/** * @param id * @return the running container with the specified identifier or <code>null</code> if no such * container exists */ public static WeldContainer instance(String id) { try { return SINGLETON.get(id); } catch (IllegalStateException e) { return null; } }
/** * @param id * @param manager * @param bootstrap * @return the initialized Weld container */ static WeldContainer initialize(String id, WeldManager manager, Bootstrap bootstrap) { if (SINGLETON.isSet(id)) { throw WeldSELogger.LOG.weldContainerAlreadyRunning(id); } WeldContainer weldContainer = new WeldContainer(id, manager, bootstrap); SINGLETON.set(id, weldContainer); RUNNING_CONTAINER_IDS.add(id); WeldSELogger.LOG.weldContainerInitialized(id); manager.fireEvent(new ContainerInitialized(id), InitializedLiteral.APPLICATION); // If needed, register one shutdown hook for all containers if (isShutdownHookNeeded() && shutdownHook == null) { synchronized (LOCK) { if (shutdownHook == null) { shutdownHook = new ShutdownHook(); Runtime.getRuntime().addShutdownHook(shutdownHook); } } } return weldContainer; }
/** * Shutdown the container. * * @see Weld#initialize() */ public synchronized void shutdown() { if (isRunning()) { try { manager.fireEvent(new ContainerShutdown(id), DestroyedLiteral.APPLICATION); } finally { SINGLETON.clear(id); RUNNING_CONTAINER_IDS.remove(id); // Destroy all the dependent beans correctly creationalContext.release(); bootstrap.shutdown(); WeldSELogger.LOG.weldContainerShutdown(id); } } else { if (WeldSELogger.LOG.isTraceEnabled()) { WeldSELogger.LOG.tracev( "Spurious call to shutdown from: {0}", (Object[]) Thread.currentThread().getStackTrace()); } throw WeldSELogger.LOG.weldContainerAlreadyShutDown(id); } }
/** * @return <code>true</code> if the container was not shut down yet, <code>false</code> otherwise */ public boolean isRunning() { return SINGLETON.isSet(id); }