Duration duration = this.duration; if (duration == null) { monitor.awaitStability(); } else if (!monitor.awaitStability(duration.toMillis(), TimeUnit.MILLISECONDS)) { throw new IllegalStateException(new TimeoutException());
private void transition(State targetState) { // Short-circuit if the service is already at the target state if (this.controller.getState() == targetState) return; StabilityMonitor monitor = new StabilityMonitor(); monitor.addController(this.controller); try { // Force service to transition to desired state Mode targetMode = modeToggle.get(targetState).get(this.controller.getMode()); if (targetMode != null) { this.controller.setMode(targetMode); } monitor.awaitStability(); if (this.controller.getState() == ServiceController.State.START_FAILED) { throw new IllegalStateException(this.controller.getStartException()); } } catch (InterruptedException e) { Thread.currentThread().interrupt(); } finally { monitor.removeController(this.controller); } } }
monitor.addController(controller); try { monitor.awaitStability(); } catch (InterruptedException e) { throw NamingLogger.ROOT_LOGGER.threadInterrupt(serviceName);
monitor.awaitStability(); } catch (InterruptedException ex) { context.failed(new StartException(ex));
/** * Wait for the required service to start up and fail otherwise. This method is necessary when a runtime operation * uses a service that might have been created within a composite operation. * * This method will wait at most 100 millis. * * @param controller the service to wait for * @throws OperationFailedException if the service is not available, or the thread was interrupted. */ private static void waitForService(final ServiceController<?> controller) throws OperationFailedException { if (controller.getState() == ServiceController.State.UP) return; final StabilityMonitor monitor = new StabilityMonitor(); monitor.addController(controller); try { monitor.awaitStability(100, MILLISECONDS); } catch (final InterruptedException e) { Thread.currentThread().interrupt(); throw SecurityLogger.ROOT_LOGGER.interruptedWaitingForSecurityDomain(controller.getName().getSimpleName()); } finally { monitor.removeController(controller); } if (controller.getState() != ServiceController.State.UP) { throw SecurityLogger.ROOT_LOGGER.requiredSecurityDomainServiceNotAvailable(controller.getName().getSimpleName()); } }
monitor.addController(binderServiceController); try { monitor.awaitStability(); } finally { monitor.removeController(binderServiceController);
public void unbind(final Name name) throws NamingException { requireOwner(); final ServiceName bindName = buildServiceName(name); final ServiceController<?> controller = getServiceRegistry().getService(bindName); if (controller == null) { throw NamingLogger.ROOT_LOGGER.cannotResolveService(bindName); } controller.setMode(ServiceController.Mode.REMOVE); final StabilityMonitor monitor = new StabilityMonitor(); monitor.addController(controller); try { monitor.awaitStability(); } catch (Exception e) { throw namingException("Failed to unbind [" + bindName + "]", e); } finally { monitor.removeController(controller); } }
/** * Causes the current thread to wait until the monitor is stable. * * @throws InterruptedException if the current thread is interrupted * while waiting */ public void awaitStability() throws InterruptedException { awaitStability(null, null, null); }
/** * Causes the current thread to wait until the monitor is stable. * * @param statistics stability statistics report to fill in * @throws InterruptedException if the current thread is interrupted * while waiting */ public void awaitStability(final StabilityStatistics statistics) throws InterruptedException { awaitStability(null, null, statistics); }
/** * Causes the current thread to wait until the monitor is stable. * * @param failed a set into which failed services should be copied * @param problems a set into which problem services should be copied * @throws InterruptedException if the current thread is interrupted * while waiting */ public void awaitStability(final Set<? super ServiceController<?>> failed, final Set<? super ServiceController<?>> problems) throws InterruptedException { this.awaitStability(failed, problems, null); }
/** * Causes the current thread to wait until the monitor is stable. * * @param failed a set into which failed services should be copied * @param problems a set into which problem services should be copied * @throws InterruptedException if the current thread is interrupted * while waiting */ public void awaitStability(final Set<? super ServiceController<?>> failed, final Set<? super ServiceController<?>> problems) throws InterruptedException { this.awaitStability(failed, problems, null); }
/** * Causes the current thread to wait until the monitor is stable. * * @param timeout the maximum time to wait * @param unit the time unit of the {@code timeout} argument * @return <tt>true</tt> if this monitor achieved stability, * <tt>false</tt> if the timeout elapsed before stability * @throws InterruptedException if the current thread is interrupted * while waiting */ public boolean awaitStability(final long timeout, final TimeUnit unit) throws InterruptedException { return awaitStability(timeout, unit, null, null, null); }
/** * Causes the current thread to wait until the monitor is stable. * * @throws InterruptedException if the current thread is interrupted * while waiting */ public void awaitStability() throws InterruptedException { awaitStability(null, null, null); }
/** * Causes the current thread to wait until the monitor is stable. * * @param statistics stability statistics report to fill in * @throws InterruptedException if the current thread is interrupted * while waiting */ public void awaitStability(final StabilityStatistics statistics) throws InterruptedException { awaitStability(null, null, statistics); }
/** * Causes the current thread to wait until the monitor is stable. * * @param timeout the maximum time to wait * @param unit the time unit of the {@code timeout} argument * @param statistics stability statistics report to fill in * @return <tt>true</tt> if this monitor achieved stability, * <tt>false</tt> if the timeout elapsed before stability * @throws InterruptedException if the current thread is interrupted * while waiting */ public boolean awaitStability(final long timeout, final TimeUnit unit, final StabilityStatistics statistics) throws InterruptedException { return awaitStability(timeout, unit, null, null, statistics); }
public DeploymentStatus getStatus() { final Set<ServiceController<?>> problems = new HashSet<ServiceController<?>>(); try { monitor.awaitStability(problems, problems); } catch (final InterruptedException e) { // ignore } return problems.isEmpty() ? DeploymentStatus.OK : DeploymentStatus.FAILED; }
public DeploymentStatus getStatus() { StabilityMonitor monitor = this.monitor; if (monitor == null) { return DeploymentStatus.STOPPED; } final Set<ServiceController<?>> problems = new HashSet<ServiceController<?>>(); try { monitor.awaitStability(problems, problems); } catch (final InterruptedException e) { // ignore } return problems.isEmpty() ? DeploymentStatus.OK : DeploymentStatus.FAILED; }
public DeploymentStatus getStatus() { StabilityMonitor monitor = this.monitor; if (monitor == null) { return DeploymentStatus.STOPPED; } final Set<ServiceController<?>> problems = new HashSet<ServiceController<?>>(); try { monitor.awaitStability(problems, problems); } catch (final InterruptedException e) { // ignore } return problems.isEmpty() ? DeploymentStatus.OK : DeploymentStatus.FAILED; }
ContainerStateChangeReport awaitContainerStateChangeReport() throws InterruptedException { monitor.awaitStability(failed, problems); return createContainerStateChangeReport(false); }
public void printBootStatistics() { final StabilityStatistics statistics = new StabilityStatistics(); try { monitor.awaitStability(statistics); } catch (final InterruptedException e) { Thread.currentThread().interrupt(); return; } finally { serviceTarget.removeMonitor(monitor); final long bootstrapTime = System.currentTimeMillis() - startTime; done(bootstrapTime, statistics); monitor.clear(); } }