Java Code Examples for org.jboss.msc.service.ServiceContainer#shutdown()

The following examples show how to use org.jboss.msc.service.ServiceContainer#shutdown() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EmbeddedHostControllerBootstrap.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void run() {
    final ServiceContainer sc;
    final ControlledProcessState ps;
    synchronized (this) {
        down = true;
        sc = container;
        ps = processState;
    }
    try {
        if (ps != null) {
            ps.setStopping();
        }
    } finally {
        if (sc != null) {
            final CountDownLatch latch = new CountDownLatch(1);
            sc.addTerminateListener(new ServiceContainer.TerminateListener() {
                @Override
                public void handleTermination(Info info) {
                    latch.countDown();
                }
            });
            sc.shutdown();
            // wait for all services to finish.
            for (;;) {
                try {
                    latch.await();
                    break;
                } catch (InterruptedException e) {
                }
            }
        }
    }
}
 
Example 2
Source File: HostControllerBootstrap.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void run() {
    final ServiceContainer sc;
    final ControlledProcessState ps;
    synchronized (this) {
        down = true;
        sc = container;
        ps = processState;
    }
    try {
        if (ps != null) {
            ps.setStopping();
        }
    } finally {
        if (sc != null) {
            SystemExiter.logBeforeExit(HostControllerLogger.ROOT_LOGGER::shutdownHookInvoked);
            final CountDownLatch latch = new CountDownLatch(1);
            sc.addTerminateListener(new ServiceContainer.TerminateListener() {
                @Override
                public void handleTermination(Info info) {
                    latch.countDown();
                }
            });
            sc.shutdown();
            // wait for all services to finish.
            for (;;) {
                try {
                    latch.await();
                    break;
                } catch (InterruptedException e) {
                }
            }
        }
    }
}
 
Example 3
Source File: BootstrapImpl.java    From wildfly-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void shutdown(boolean failed) {
    final ServiceContainer sc;
    final ControlledProcessState ps;
    synchronized (this) {
        down = true;
        sc = container;
        ps = processState;
    }
    try {
        if (ps != null) {
            if (!failed && ps.getState() == ControlledProcessState.State.RUNNING) {
                suspend(sc);
            }
            ps.setStopping();
        }
    } finally {
        if (sc != null && !sc.isShutdownComplete()) {
            if (!failed) {
                // TODO this is probably better before the 'suspend' logging but the
                // shutdown mgmt op has this order of logging
                SystemExiter.logBeforeExit(ServerLogger.ROOT_LOGGER::shutdownHookInvoked);
            }
            final CountDownLatch terminateLatch = new CountDownLatch(1);
            sc.addTerminateListener(new ServiceContainer.TerminateListener() {
                @Override
                public void handleTermination(Info info) {
                    terminateLatch.countDown();
                }
            });
            sc.shutdown();
            // wait for all services to finish.
            for (;;) {
                try {
                    terminateLatch.await();
                    break;
                } catch (InterruptedException e) {
                    // ignored
                }
            }
        }
    }
}