private boolean next() { if (myRes != null) return true; long started = startTiming(); try { Loader loader; if (myLoaders != null) { while (myIndex < myLoaders.size()) { loader = myLoaders.get(myIndex++); if (!myCache.loaderHasName(myName, loader)) { myRes = null; continue; } myRes = loader.getResource(myName, myCheck); if (myRes != null) return true; } } else { while ((loader = getLoader(myIndex++)) != null) { if (!myCache.loaderHasName(myName, loader)) continue; myRes = loader.getResource(myName, myCheck); if (myRes != null) return true; } } } finally { logTiming(ClassPath.this, started, myName); } return false; }
private boolean next() { if (myRes != null) return true; long started = myDebugTime ? System.nanoTime() : 0; Loader loader; try { if (myLoaders != null) { while (myIndex < myLoaders.size()) { loader = myLoaders.get(myIndex++); if (!myCache.loaderHasName(myName, loader)) { myRes = null; continue; } myRes = loader.getResource(myName, myCheck); if (myRes != null) return true; } } else { while ((loader = getLoader(myIndex++)) != null) { if (!myCache.loaderHasName(myName, loader)) continue; myRes = loader.getResource(myName, myCheck); if (myRes != null) return true; } } } finally { if (myDebugTime) reportTime(started, myName); } return false; }
@Nullable public Resource getResource(String s, boolean flag) { final long started = startTiming(); try { int i; if (myCanUseCache) { Resource prevResource = myCache.iterateLoaders(s, flag ? ourCheckedIterator : ourUncheckedIterator, s, this); if (prevResource != null) return prevResource; synchronized (myUrls) { if (myUrls.isEmpty()) return null; } i = myLoaders.size(); } else { i = 0; } Loader loader; while ((loader = getLoader(i++)) != null) { if (myCanUseCache) { if (!myCache.loaderHasName(s, loader)) continue; } Resource resource = loader.getResource(s, flag); if (resource != null) { return resource; } } } finally { logTiming(this, started, s); } return null; }
String getContent(String identifier) throws Exception { logger.trace("Searching for '{}' in cache.", identifier); ResourceWrapper wrapper = resources.get(identifier); // If not in cache yet, load it if (wrapper == null) { long start = System.currentTimeMillis(); logger.debug("'{}' not in cache. Loading and processing...", identifier); String extension = FilenameUtils.getExtension(identifier); Type type = TypeFactory.getType(extension); if (type == null) { logger.warn("No type available for the specified resource: {}", extension); throw new UnknownTypeException( "No type available for the specified resource: " + extension); } String content = processContent(loader.loadResource(identifier), type); wrapper = new ResourceWrapper(identifier, type, content); resources.put(identifier, wrapper); logger.debug("Resource loaded and processed in {} ms.", System.currentTimeMillis() - start); } else { // If in cache, check last modified if (wrapper.getLastLoaded() < loader.lastModified(identifier)) { // If last loaded was before last modified, load it again wrapper.setContent(loader.loadResource(identifier)); } } return wrapper.getContent(); }
@Override public Void doInBackground() { setProgress(0); MetaData metaData; final Loader loader = new Loader(); final File file = loader.load(); final Collection<File> files = FileUtils.listFiles( file, new RegexFileFilter("^(.*.mp3)"), DirectoryFileFilter.DIRECTORY); final List<Song> songList = new ArrayList<Song>(); int onePercent = files.size() / 100; if (onePercent == 0) { onePercent = 1; } int progressSoFar = 0; for (final File singleFile : files) { metaData = new MetaData(singleFile); songList.add(new Song(metaData, singleFile)); progress++; if (progress % onePercent == 0) { setProgress(Math.min(++progressSoFar, 99)); } } songLibrary = new SongLibrary(songList); setProgress(100); pcs.firePropertyChange("libraryLoaded", 0, songLibrary); return null; }
/** * Create an <code>ObjectName</code> for this <code>Loader</code> object. * * @param domain Domain in which this name is to be created * @param loader The Loader to be named * @exception MalformedObjectNameException if a name cannot be created */ static ObjectName createObjectName(String domain, Loader loader) throws MalformedObjectNameException { ObjectName name = null; Container container = loader.getContainer(); if (container instanceof Engine) { name = new ObjectName(domain + ":type=Loader"); } else if (container instanceof Host) { name = new ObjectName(domain + ":type=Loader,host=" + container.getName()); } else if (container instanceof Context) { String path = ((Context) container).getPath(); if (path.length() < 1) { path = "/"; } Host host = (Host) container.getParent(); name = new ObjectName(domain + ":type=Loader,path=" + path + ",host=" + host.getName()); } else if (container == null) { // What is that ??? DefaultContext defaultContext = loader.getDefaultContext(); if (defaultContext != null) { Container parent = defaultContext.getParent(); if (parent instanceof Engine) { name = new ObjectName(domain + ":type=DefaultLoader"); } else if (parent instanceof Host) { name = new ObjectName(domain + ":type=DefaultLoader,host=" + parent.getName()); } } } return (name); }
@Subscribe public void buildModList(FMLLoadEvent event) { this.modList = loader.getIndexedModList(); Builder<String, EventBus> eventBus = ImmutableMap.builder(); for (ModContainer mod : loader.getModList()) { EventBus bus = new EventBus(mod.getModId()); boolean isActive = mod.registerBus(bus, this); if (isActive) { Level level = Logger.getLogger(mod.getModId()).getLevel(); FMLLog.log( mod.getModId(), Level.FINE, "Mod Logging channel %s configured at %s level.", level == null ? "default" : level); FMLLog.log(mod.getModId(), Level.INFO, "Activating mod %s", mod.getModId()); activeModList.add(mod); modStates.put(mod.getModId(), ModState.UNLOADED); eventBus.put(mod.getModId(), bus); } else { FMLLog.log( mod.getModId(), Level.WARNING, "Mod %s has been disabled through configuration", mod.getModId()); modStates.put(mod.getModId(), ModState.UNLOADED); modStates.put(mod.getModId(), ModState.DISABLED); } } eventChannels = eventBus.build(); }
/** * the Main way to add plugin to the PluginLoader * * @author RoboRave * @param plugin the class of the plugin * @throws IllegalAccessException * @throws InstantiationException */ @SuppressWarnings("static-access") public static void addPlugin(Class<? extends Plugin> plugin) throws InstantiationException, IllegalAccessException { // if(plugin.getClass().getAnnotation(PreInit.class) != null) // { plugin.newInstance().preInit(); if (MainCore.instance.dev == true && CommonUtils.isObfuscatedEnv() == false) CoreLogger.info("Loaded Preinit for " + plugin.newInstance().meta().name); // } // if(plugin.getAnnotation(Info.Init.class)) // { plugin.newInstance().init(); if (MainCore.instance.dev == true && CommonUtils.isObfuscatedEnv() == false) CoreLogger.info("Loaded Init for " + plugin.newInstance().meta().name); // } // if(plugin.getClass().isAnnotationPresent(PostInit.class)) // { plugin.newInstance().postInit(); if (MainCore.instance.dev == true && CommonUtils.isObfuscatedEnv() == false) CoreLogger.info("Loaded Postinit for " + plugin.newInstance().meta().name); // } Loader.instance().mods.add(plugin); Loader.instance().plugins.add(plugin.newInstance().meta().name); }
public void testLoader() { Logger.getLogger("uk.ac.starlink.util").setLevel(Level.SEVERE); assertNull(Loader.getClassInstance("no.class.here.mate", TestCase.class)); assertNull(Loader.getClassInstance(getClass().getName(), Comparable.class)); assertEquals( LoaderTest.class, Loader.getClassInstance(getClass().getName(), TestCase.class).getClass()); }
private void parseSimpleFieldAnnotation( SetMultimap<String, ASMData> annotations, String annotationClassName, Function<ModContainer, Object> retreiver) throws IllegalAccessException { String[] annName = annotationClassName.split("\\."); String annotationName = annName[annName.length - 1]; for (ASMData targets : annotations.get(annotationClassName)) { String targetMod = (String) targets.getAnnotationInfo().get("value"); Field f = null; Object injectedMod = null; ModContainer mc = this; boolean isStatic = false; Class<?> clz = modInstance.getClass(); if (!Strings.isNullOrEmpty(targetMod)) { if (Loader.isModLoaded(targetMod)) { mc = Loader.instance().getIndexedModList().get(targetMod); } else { mc = null; } } if (mc != null) { try { clz = Class.forName(targets.getClassName(), true, Loader.instance().getModClassLoader()); f = clz.getDeclaredField(targets.getObjectName()); f.setAccessible(true); isStatic = Modifier.isStatic(f.getModifiers()); injectedMod = retreiver.apply(mc); } catch (Exception e) { Throwables.propagateIfPossible(e); FMLLog.log( getModId(), Level.WARNING, e, "Attempting to load @%s in class %s for %s and failing", annotationName, targets.getClassName(), mc.getModId()); } } if (f != null) { Object target = null; if (!isStatic) { target = modInstance; if (!modInstance.getClass().equals(clz)) { FMLLog.log( getModId(), Level.WARNING, "Unable to inject @%s in non-static field %s.%s for %s as it is NOT the primary mod instance", annotationName, targets.getClassName(), targets.getObjectName(), mc.getModId()); continue; } } f.set(target, injectedMod); } } }
@Override public List load(EntityInfo... entityInfos) { // no need to timeouManage here, the underlying loader is the real time consumer List results = new ArrayList(entityInfos.length); if (entityInfos.length == 0) { return results; } if (projectionEnabledOnThis(entityInfos[0])) { Loader objectLoader = getObjectLoader(); objectLoader.load(entityInfos); // load by batch for (EntityInfo entityInfo : entityInfos) { final Object entityInstance = objectLoader.loadWithoutTiming(entityInfo); entityInfo.populateWithEntityInstance(entityInstance); } } for (EntityInfo entityInfo : entityInfos) { if (transformer != null) { results.add(transformer.transformTuple(entityInfo.getProjection(), aliases)); } else { results.add(entityInfo.getProjection()); } } return results; }
/** * Loads the cache result, computing it if needed by executing the query phase and otherwise * deserializing the cached value into the {@link SearchContext#queryResult() context's query * result}. The combination of load + compute allows to have a single load operation that will * cause other requests with the same key to wait till its loaded an reuse the same cache. */ public void loadIntoContext( final ShardSearchRequest request, final SearchContext context, final QueryPhase queryPhase) throws Exception { assert canCache(request, context); Key key = buildKey(request, context); Loader loader = new Loader(queryPhase, context, key); Value value = cache.get(key, loader); if (loader.isLoaded()) { key.shard.requestCache().onMiss(); // see if its the first time we see this reader, and make sure to register a cleanup key CleanupKey cleanupKey = new CleanupKey( context.indexShard(), ((DirectoryReader) context.searcher().getIndexReader()).getVersion()); if (!registeredClosedListeners.containsKey(cleanupKey)) { Boolean previous = registeredClosedListeners.putIfAbsent(cleanupKey, Boolean.TRUE); if (previous == null) { context.searcher().getIndexReader().addReaderClosedListener(cleanupKey); } } } else { key.shard.requestCache().onHit(); // restore the cached query result into the context final QuerySearchResult result = context.queryResult(); result.readFromWithId(context.id(), value.reference.streamInput()); result.shardTarget(context.shardTarget()); } }
public void computeBranding() { if (brandings == null) { Builder brd = ImmutableList.<String>builder(); brd.add(Loader.instance().getMCVersionString()); brd.add(Loader.instance().getMCPVersionString()); brd.add("FML v" + Loader.instance().getFMLVersionString()); String forgeBranding = (String) callForgeMethod("getBrandingVersion"); if (!Strings.isNullOrEmpty(forgeBranding)) { brd.add(forgeBranding); } if (sidedDelegate != null) { brd.addAll(sidedDelegate.getAdditionalBrandingInformation()); } try { Properties props = new Properties(); props.load(getClass().getClassLoader().getResourceAsStream("fmlbranding.properties")); brd.add(props.getProperty("fmlbranding")); } catch (Exception ex) { // Ignore - no branding file found } int tModCount = Loader.instance().getModList().size(); int aModCount = Loader.instance().getActiveModList().size(); brd.add( String.format( "%d mod%s loaded, %d mod%s active", tModCount, tModCount != 1 ? "s" : "", aModCount, aModCount != 1 ? "s" : "")); brandings = brd.build(); } }
public BranchGroup createSceneGraph(URL url) { try { Loader loader = new com.sun.j3d.loaders.objectfile.ObjectFile(); Scene scene = loader.load(url); BranchGroup bg = scene.getSceneGroup(); System.out.println(bg); TransformGroup[] views = scene.getViewGroups(); if (views != null) { for (int i = 0; i < views.length; i++) { System.out.print(views[i]); } if (views.length > 0) viewStart = views[0]; } return bg; } catch (Exception ex) { // in case there was a problem, print the stack out ex.printStackTrace(); // System.out.println(ex); add("South", new Label(ex.toString())); System.out.println("URL: " + url); BranchGroup bg = new BranchGroup(); bg.addChild(new ColorCube()); System.out.println(bg); return bg; } }
@Nullable public Resource getResource(String s, boolean flag) { final long started = myDebugTime ? System.nanoTime() : 0; try { int i; if (myCanUseCache) { Resource prevResource = myCache.iterateLoaders(s, flag ? checkedIterator : uncheckedIterator, s, this); if (prevResource != null) return prevResource; synchronized (myUrls) { if (myUrls.isEmpty()) return null; } i = myLoaders.size(); } else { i = 0; } for (Loader loader; (loader = getLoader(i)) != null; i++) { if (myCanUseCache) { if (!myCache.loaderHasName(s, loader)) continue; } Resource resource = loader.getResource(s, flag); if (resource != null) { return resource; } } return null; } finally { if (myDebugTime) reportTime(started, s); } }
@Override public void bindMetadata(MetadataCollection mc) { modMetadata = mc.getMetadataForId(getModId(), descriptor); if (descriptor.containsKey("useMetadata")) { overridesMetadata = !((Boolean) descriptor.get("useMetadata")).booleanValue(); } if (overridesMetadata || !modMetadata.useDependencyInformation) { Set<ArtifactVersion> requirements = Sets.newHashSet(); List<ArtifactVersion> dependencies = Lists.newArrayList(); List<ArtifactVersion> dependants = Lists.newArrayList(); annotationDependencies = (String) descriptor.get("dependencies"); Loader.instance() .computeDependencies(annotationDependencies, requirements, dependencies, dependants); modMetadata.requiredMods = requirements; modMetadata.dependencies = dependencies; modMetadata.dependants = dependants; FMLLog.finest("Parsed dependency info : %s %s %s", requirements, dependencies, dependants); } else { FMLLog.finest( "Using mcmod dependency info : %s %s %s", modMetadata.requiredMods, modMetadata.dependencies, modMetadata.dependants); } if (Strings.isNullOrEmpty(modMetadata.name)) { FMLLog.info( "Mod %s is missing the required element 'name'. Substituting %s", getModId(), getModId()); modMetadata.name = getModId(); } internalVersion = (String) descriptor.get("version"); if (Strings.isNullOrEmpty(internalVersion)) { Properties versionProps = searchForVersionProperties(); if (versionProps != null) { internalVersion = versionProps.getProperty(getModId() + ".version"); FMLLog.fine( "Found version %s for mod %s in version.properties, using", internalVersion, getModId()); } } if (Strings.isNullOrEmpty(internalVersion) && !Strings.isNullOrEmpty(modMetadata.version)) { FMLLog.warning( "Mod %s is missing the required element 'version' and a version.properties file could not be found. Falling back to metadata version %s", getModId(), modMetadata.version); internalVersion = modMetadata.version; } if (Strings.isNullOrEmpty(internalVersion)) { FMLLog.warning( "Mod %s is missing the required element 'version' and no fallback can be found. Substituting '1.0'.", getModId()); modMetadata.version = internalVersion = "1.0"; } String mcVersionString = (String) descriptor.get("acceptedMinecraftVersions"); if (!Strings.isNullOrEmpty(mcVersionString)) { minecraftAccepted = VersionParser.parseRange(mcVersionString); } else { minecraftAccepted = Loader.instance().getMinecraftModContainer().getStaticVersionRange(); } }
private void ensureHeavy() { if (!created) { loader.ensureHeavy(record); if (before != null) { loader.ensureHeavy(before); } } }
private Loader obtainInstance(String documentId) throws FileNotFoundException { Loader loader; synchronized (mArchives) { loader = getInstanceUncheckedLocked(documentId); loader.getReadLock().lock(); } return loader; }
public void AddJob() // method to add a process and execute { load.loader(); // load.quickSort(load.arlist,0,load.arlist.size()-1); System.out.println(load.getJobs()); for (int i = 0; i < load.getJobs(); i++) { queue.add(load.arlist.get(i)); } }
/** * Returns a MIME type of a document within an archive. * * @see DocumentsProvider.getDocumentType(String) */ public String getDocumentType(String documentId) throws FileNotFoundException { Loader loader = null; try { loader = obtainInstance(documentId); return loader.get().getDocumentType(documentId); } finally { releaseInstance(loader); } }
/** * Finds the resource with the specified name on the URL search path or null if not found or * security check fails. * * @param name the name of the resource * @param check whether to perform a security check * @return a <code>URL</code> for the resource, or <code>null</code> if the resource could not be * found. */ public URL findResource(String name, boolean check) { Loader loader; for (int i = 0; (loader = getLoader(i)) != null; i++) { URL url = loader.findResource(name, check); if (url != null) { return url; } } return null; }
/** * Returns metadata of a document within an archive. * * @see DocumentsProvider.queryDocument(String, String[]) */ public Cursor queryDocument(String documentId, @Nullable String[] projection) throws FileNotFoundException { Loader loader = null; try { loader = obtainInstance(documentId); return loader.get().queryDocument(documentId, projection); } finally { releaseInstance(loader); } }
/** * Finds the first Resource on the URL search path which has the specified name. Returns null if * no Resource could be found. * * @param name the name of the Resource * @param check whether to perform a security check * @return the Resource, or null if not found */ public Resource getResource(String name, boolean check) { Loader loader; for (int i = 0; (loader = getLoader(i)) != null; i++) { Resource res = loader.getResource(name, check); if (res != null) { return res; } } return null; }
/* */ public void startElement(UnmarshallingContext.State state, TagName ea) throws SAXException { /* 59 */ JaxBeanInfo beanInfo = parseXsiType(state, ea, this.defaultBeanInfo); /* 60 */ if (beanInfo == null) { /* 61 */ beanInfo = this.defaultBeanInfo; /* */ } /* 63 */ Loader loader = beanInfo.getLoader(null, false); /* 64 */ state.setLoader(loader); /* 65 */ loader.startElement(state, ea); /* */ }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (ListView) findViewById(R.id.list); prefs = getSharedPreferences("com.uclastudentmedia.test_bank", 0); Loader loader = new Loader(); loader.execute(); }
/** * Opens a file within an archive. * * @see DocumentsProvider.openDocument(String, String, CancellationSignal)) */ public ParcelFileDescriptor openDocument( String documentId, String mode, final CancellationSignal signal) throws FileNotFoundException { Loader loader = null; try { loader = obtainInstance(documentId); return loader.get().openDocument(documentId, mode, signal); } finally { releaseInstance(loader); } }
/** * Opens a thumbnail of a file within an archive. * * @see DocumentsProvider.openDocumentThumbnail(String, Point, CancellationSignal)) */ public AssetFileDescriptor openDocumentThumbnail( String documentId, Point sizeHint, final CancellationSignal signal) throws FileNotFoundException { Loader loader = null; try { loader = obtainInstance(documentId); return loader.get().openDocumentThumbnail(documentId, sizeHint, signal); } finally { releaseInstance(loader); } }
@Override public void entryRemoved(boolean evicted, String key, Loader oldValue, Loader newValue) { oldValue.getWriteLock().lock(); try { oldValue.get().close(); } catch (FileNotFoundException e) { Log.e(TAG, "Failed to close an archive as it no longer exists."); } finally { oldValue.getWriteLock().unlock(); } }
/** * Returns true if a document within an archive is a child or any descendant of the archive * document or another document within the archive. * * @see DocumentsProvider.isChildDocument(String, String) */ public boolean isChildDocument(String parentDocumentId, String documentId) { Loader loader = null; try { loader = obtainInstance(documentId); return loader.get().isChildDocument(parentDocumentId, documentId); } catch (FileNotFoundException e) { throw new IllegalStateException(e); } finally { releaseInstance(loader); } }
public void loadEvents() throws Exception { ReplicatorRuntime runtime = null; Pipeline pipeline = null; Class<?> headExtractorClass = null; Class<?> storeClass = null; try { runtime = new ReplicatorRuntime( this.buildLoaderConfig(), new MockOpenReplicatorContext(), ReplicatorMonitor.getInstance()); runtime.configure(); pipeline = runtime.getPipeline(); ExtractorWrapper ew = (ExtractorWrapper) pipeline.getHeadExtractor(); headExtractorClass = ew.getExtractor().getClass(); if (Loader.class.isAssignableFrom(headExtractorClass) != true) { throw new Exception( "Unable to start the loader because " + headExtractorClass + " does not extend " + Loader.class); } Loader extractor = (Loader) ew.getExtractor(); if (extractor.getLockTables() == true) { for (String storeName : pipeline.getStoreNames()) { Store store = pipeline.getStore(storeName); storeClass = store.getClass(); if (THL.class.isAssignableFrom(storeClass) == true) { THL thlStore = (THL) store; thlStore.setUrl(null); } } } runtime.prepare(); pipeline.start(new MockEventDispatcher()); pipeline.shutdownAfterHeartbeat("LOAD_COMPLETE"); while (pipeline.isShutdown() != true) { // Wait for the pipeline to complete Thread.sleep(100); } logger.info("Tables imported"); } finally { runtime.release(); } }