コード例 #1
0
  /**
   * Stops the EJB3 server.
   *
   * @throws EmbeddedException if container cannot be stopped.
   */
  public synchronized void stop() throws EmbeddedException {
    // ensure started
    if (!this.started) {
      throw new EmbeddedException("Cannot stop the server as it is not started.");
    }
    this.stopping = true;

    if (this.dispatcher != null) {
      this.dispatcher.dispatch(new EventLifeCycleStopping(this.j2eeManagedObjectId));
    }

    // Stop the containers
    // Use a ListIterator to allow us to safely remove EZBContainers
    // from the List being processed.
    List<EZBContainer> containersList = new ArrayList<EZBContainer>(this.containers.values());
    ListIterator<EZBContainer> li = containersList.listIterator();
    while (li.hasNext()) {
      EZBContainer container = li.next();
      container.stop();
      removeContainer(container);
    }

    // Unregister MBeans
    if (this.serverConfig.isUsingMBeans()) {

      if (this.serverConfig.isStartJMXConnector()) {
        // Stop the JMX Connector
        try {
          JMXRemoteHelper.stopConnector();
        } catch (JMXRemoteException e) {
          // Only log the Exception

          // and continue ...
        }
      }

      // Unregister the Deployer
      if (this.serverConfig.isRegisterDeployerMBean()) {
        try {
          MBeansHelper.getInstance().unregisterMBean(this.deployer);
        } catch (MBeansException e) {
          // Only log the Exception

        }
      }

      // Unregister the Server
      if (this.serverConfig.isRegisterJ2EEServerMBean()) {
        try {
          MBeansHelper.getInstance().unregisterMBean(this);
        } catch (MBeansException e) {
          // Only log the Exception
        }
      }
    }

    // Unbind the RPCInvoker Remote Object
    try {
      new InitialContext().unbind(RMIServerRPC.RPC_JNDI_NAME);
    } catch (NamingException e) {
      // Only log the Exception
    }

    // Unexport
    try {
      PortableRemoteObject.unexportObject(this.invoker);
    } catch (NoSuchObjectException e) {
      // Only log the Exception
    }

    // Dispatch lifecycle event.
    this.dispatcher.dispatch(new EventLifeCycleStopped(this.j2eeManagedObjectId));

    // Unregister from statistic component.
    EZBStatisticComponent statisticComponent = getComponent(EZBStatisticComponent.class);
    if (statisticComponent != null) {
      statisticComponent.unregisterJ2EEManagedObject(this);
    }

    // Unregister from jmx component will be done by the mbean itself.

    // Unregister from event component.
    EZBEventComponent eventComponent = getComponent(EZBEventComponent.class);
    if (eventComponent != null) {
      eventComponent.unregisterJ2EEManagedObject(this);

      // Unregister the NamingExtensions (used to fill the java:comp Context)
      for (IEventListener extension : this.defaultNamingExtensions) {
        eventComponent.getEventService().unregisterListener(extension);
      }
    }

    // Destroy the event dispatcher.
    this.dispatcher.stop();
    this.dispatcher = null;

    // Stop the components
    if (this.serverConfig.isStopComponentsDuringShutdown()) {
      this.componentManager.stopComponents();
    }

    // Stop JACC
    if (this.serverConfig.initJACC()) {
      try {
        PolicyProvider.stop();
      } catch (Exception e) {
        // Only log the Exception
      }
    }

    // EasyBeans is stopped
    this.started = false;
    this.stopped = true;
    this.stopping = false;
  }