@Override public String toString() { String result = "Furnace: " + runnable.furnace.hashCode() + "\nStatus: " + runnable.furnace.getStatus() + "\n\n"; for (AddonRepository repository : runnable.furnace.getRepositories()) { result += repository + "\n"; } result += "\n" + runnable.furnace; return result; } }
private void waitUntilStable(Furnace forge) throws InterruptedException { while (forge.getStatus().isStarting()) { Thread.sleep(10); } } }
@Override public Set<String> getAllCommandNames() { if (!furnace.getStatus().isStarted()) return Collections.emptySet(); Set<String> allCommands = new TreeSet<>(); allCommands.addAll(getForgeCommandNames()); allCommands.addAll(aeshCommandRegistry.getAllCommandNames()); return allCommands; }
@SuppressWarnings("unused") private void stop() { if (furnace != null && !furnace.getStatus().isStopped()) furnace.stop(); }
private void waitUntilStarted() { while (furnace.getStatus().isStarting()) { try { Thread.sleep(10); } catch (InterruptedException e) { throw new ContainerException("Interrputed while waiting for STARTED state.", e); } } }
private void stop() { if (furnace != null && !furnace.getStatus().isStopped()) furnace.stop(); while (!containerStatusListener.getContainerStatus().isStopped()) { try { Thread.sleep(10); } catch (InterruptedException e) { System.err.println("Failure waiting for Furnace to shutdown: " + e.getMessage()); e.printStackTrace(); } } }
@SuppressWarnings("unused") private void stop() { if (furnace != null && !furnace.getStatus().isStopped()) furnace.stop(); }
private void stop() { if (furnace != null && !furnace.getStatus().isStopped()) furnace.stop(); while (!containerStatusListener.getContainerStatus().isStopped()) { try { Thread.sleep(10); } catch (InterruptedException e) { System.err.println("Failure waiting for Furnace to shutdown: " + e.getMessage()); e.printStackTrace(); } } }
@Override public <T> Collection<Class<T>> locate(final Class<T> type) { List<Class<T>> result = new ArrayList<>(); Furnace furnace = FurnaceHolder.getFurnace(); // Furnace may be not available if the ServiceLoader is called before FurnaceHolder // has received the Furnace PostConstruct event, so check for null and if it isStarted if (furnace != null && furnace.getStatus().isStarted()) { Set<Class<T>> types = furnace.getAddonRegistry().getExportedTypes(type); result.addAll(types); } return result; } }
@Override public <T> Collection<Class<T>> locate(final Class<T> type) { List<Class<T>> result = new ArrayList<>(); Furnace furnace = FurnaceHolder.getFurnace(); // Furnace may be not available if the ServiceLoader is called before FurnaceHolder // has received the Furnace PostConstruct event, so check for null and if it isStarted if (furnace != null && furnace.getStatus().isStarted()) { Set<Class<T>> types = furnace.getAddonRegistry().getExportedTypes(type); result.addAll(types); } return result; } }
@Override public <T> Collection<T> produce(final Class<T> type) { final Collection<T> result = new HashSet<>(); final Furnace furnace = FurnaceHolder.getFurnace(); // Furnace may be not available if the ServiceLoader is called before FurnaceHolder // has received the Furnace PostConstruct event, so check for null and if it isStarted if (furnace != null && furnace.getStatus().isStarted()) { final Imported<T> services = furnace.getAddonRegistry().getServices(type); for (final T service : services) { result.add(service); } } return result; }
@Override public <T> Collection<T> produce(final Class<T> type) { final Collection<T> result = new HashSet<>(); final Furnace furnace = FurnaceHolder.getFurnace(); // Furnace may be not available if the ServiceLoader is called before FurnaceHolder // has received the Furnace PostConstruct event, so check for null and if it isStarted if (furnace != null && furnace.getStatus().isStarted()) { final Imported<T> services = furnace.getAddonRegistry().getServices(type); for (final T service : services) { result.add(service); } } return result; }
@Override public final void perform() { ConfigurationScanListener listener = new ConfigurationScanListener(); ListenerRegistration<ContainerLifecycleListener> reg = furnace.addContainerLifecycleListener(listener); try { execute(); if (!furnace.getStatus().isStopped()) { while (furnace.getStatus().isStarting() || !listener.isConfigurationScanned()) { try { Thread.sleep(100); } catch (InterruptedException e) { throw new RuntimeException(e); } } } } finally { reg.removeListener(); } }
private <T> T waitForConfigurationRescan(Callable<T> action) { ConfigurationScanListener listener = new ConfigurationScanListener(); ListenerRegistration<ContainerLifecycleListener> registration = runnable.furnace .addContainerLifecycleListener(listener); T result = Callables.call(action); while (runnable.furnace.getStatus().isStarting() || !listener.isConfigurationScanned()) { try { Thread.sleep(100); } catch (InterruptedException e) { throw new RuntimeException("Sleep interrupted while waiting for configuration rescan.", e); } } registration.removeListener(); return result; }
@Override public Set<ClassLoader> call() throws Exception { if (furnace.getStatus().isStarted()) { long registryVersion = furnace.getAddonRegistry().getVersion(); if (registryVersion != lastRegistryVersion) { result.clear(); lastRegistryVersion = registryVersion; for (Addon addon : furnace.getAddonRegistry().getAddons()) { ClassLoader classLoader = addon.getClassLoader(); if (classLoader != null) result.add(classLoader); } } } return result; } };
@Override public Set<ClassLoader> call() throws Exception { if (furnace.getStatus().isStarted()) { long registryVersion = furnace.getAddonRegistry().getVersion(); if (registryVersion != lastRegistryVersion) { result.clear(); lastRegistryVersion = registryVersion; for (Addon addon : furnace.getAddonRegistry().getAddons()) { ClassLoader classLoader = addon.getClassLoader(); if (classLoader != null) result.add(classLoader); } } } return result; } };