Esempio n. 1
0
 /**
  * @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;
   }
 }
Esempio n. 2
0
 /**
  * @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;
 }
Esempio n. 3
0
 /**
  * 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);
   }
 }
Esempio n. 4
0
 /**
  * @return <code>true</code> if the container was not shut down yet, <code>false</code> otherwise
  */
 public boolean isRunning() {
   return SINGLETON.isSet(id);
 }