0 Replies Latest reply on Feb 28, 2012 8:24 AM by David Robison

    AS7.1 Stopping stopping domain server instance does not stop deployed SARs

    David Robison Novice

      I have a AS7.1 domain. On one of my host controllers I have a server instance that runs a SAR. When I stop the server instance from the domain console the instance does not seem to completly shut down. It appears that the stop on the SAR is never called. My SAR main service is as follows:

       

      public class AwamDataSingletonSvc implements AwamDataSingletonSvcMBean {

          private static final Logger LOG = Logger.getLogger(AwamDataSingletonSvc.class.getName());

       

          private AwamDataSvc service;

          private ServiceController<String> controller;

       

          /**

           * {@inheritDoc}

           */

          @Override

          public void start() throws Exception {

              LOG.info("Starting service...");

              ThreadTransaction.init();

              String preferedNode = System.getProperty("AwamDataSvc.PreferedNode", "tte-processor-01");

              service = new AwamDataSvc();

              SingletonService<String> singleton = new SingletonService<String>(service, AwamDataSvc.SERVICE_NAME);

              singleton.setElectionPolicy(new PreferredSingletonElectionPolicy(new NamePreference(preferedNode + "/" + SingletonService.DEFAULT_CONTAINER), new SimpleSingletonElectionPolicy()));

              controller = singleton.build(CurrentServiceContainer.getServiceContainer())

                      .addDependency(ServerEnvironmentService.SERVICE_NAME, ServerEnvironment.class, service.getEnvInjector())

                      .install()

                      ;

              controller.setMode(ServiceController.Mode.ACTIVE);

              wait(controller, EnumSet.of(ServiceController.State.DOWN, ServiceController.State.STARTING), ServiceController.State.UP);

              LOG.info("Start done");

          }

       

          /**

           * {@inheritDoc}

           */

          @Override

          public void stop() {

              LOG.info("Stopping service...");

              service.stop(null);

              controller.setMode(ServiceController.Mode.REMOVE);

              wait(controller, EnumSet.of(ServiceController.State.UP, ServiceController.State.STOPPING, ServiceController.State.DOWN), ServiceController.State.REMOVED);

              LOG.info("Stop done");

          }

       

          /**

           * Wait for the controller state.

           * @param controller the controller

           * @param expectedStates the expected sates

           * @param targetState the target state

           * @param <T> the type

           */

          private static <T> void wait(ServiceController<T> controller, Collection<ServiceController.State> expectedStates, ServiceController.State targetState) {

              if (controller.getState() != targetState) {

                  ServiceListener<T> listener = new NotifyingServiceListener<T>();

                  controller.addListener(listener);

                  try {

                      synchronized (controller) {

                          while (expectedStates.contains(controller.getState())) {

                              LOG.info(String.format("Service controller state is %s, waiting for transition to %s", controller.getState(), targetState));

                              controller.wait();

                          }

                      }

                  } catch (InterruptedException e) {

                      Thread.currentThread().interrupt();

                  }

                  controller.removeListener(listener);

                  ServiceController.State state = controller.getState();

                  if (state != targetState) {

                      throw new IllegalStateException(String.format("Failed to wait for state to transition to %s.  Current state is %s", targetState, state), controller.getStartException());

                  }

              }

          }

       

          private static class NotifyingServiceListener<T> extends AbstractServiceListener<T> {

              @Override

              public void transition(ServiceController<? extends T> controller, Transition transition) {

                  synchronized (controller) {

                      controller.notify();

                  }

              }

          }

      }

      and from the server instance log:

       

      [Host Controller] 08:03:41,196 INFO  [org.jboss.as.host.controller] (domain-connection-threads - 33) JBAS010923: Stopping server tte-processor-01

      08:03:41,196 INFO  [org.jboss.as.process.Server:tte-processor-01.status] (ProcessController-threads - 6) JBAS012018: Stopping process 'Server:tte-processor-01'

      [Server:tte-processor-01] 08:03:41,243 INFO  [org.jboss.as.osgi] (MSC service thread 1-2) JBAS011942: Stopping OSGi Framework

      [Host Controller] 08:03:41,243 INFO  [org.jboss.as.host.controller] (Remoting "tvdint01:MANAGEMENT" read-1) JBAS010926: Unregistering server tte-processor-01

      [Server:tte-processor-01] 08:03:41,259 INFO  [org.jboss.as.jpa] (MSC service thread 1-1) JBAS011403: Stopping Persistence Unit Service 'TravelTimeEngine-AwamDataProvidor-1.0.sar#TravelTimeEngine-DS'

      [Server:tte-processor-01] 08:03:41,259 INFO  [org.apache.coyote.http11.Http11AprProtocol] (MSC service thread 1-1) Pausing Coyote HTTP/1.1 on http--192.168.117.34-8380

      [Server:tte-processor-01] 08:03:41,259 INFO  [org.apache.coyote.http11.Http11AprProtocol] (MSC service thread 1-1) Stopping Coyote HTTP/1.1 on http--192.168.117.34-8380

      It seems the "stop" method is never called. Am I doing something wrong? David