Refine search
/** * Attempts to start the timer immediately prior to the service being started via {@link * Service#startAsync()}. */ void tryStartTiming(Service service) { monitor.enter(); try { Stopwatch stopwatch = startupTimers.get(service); if (stopwatch == null) { startupTimers.put(service, Stopwatch.createStarted()); } } finally { monitor.leave(); } }
void awaitStopped(long timeout, TimeUnit unit) throws TimeoutException { monitor.enter(); try { if (!monitor.waitForUninterruptibly(stoppedGuard, timeout, unit)) { throw new TimeoutException( "Timeout waiting for the services to stop. The following " + "services have not stopped: " + Multimaps.filterKeys(servicesByState, not(in(EnumSet.of(TERMINATED, FAILED))))); } } finally { monitor.leave(); } }
/** * Attempts to start the timer immediately prior to the service being started via {@link * Service#startAsync()}. */ void tryStartTiming(Service service) { monitor.enter(); try { Stopwatch stopwatch = startupTimers.get(service); if (stopwatch == null) { startupTimers.put(service, Stopwatch.createStarted()); } } finally { monitor.leave(); } }
public void requestStarted() { int previousCount = activeRequests.getAndIncrement(); totalRequests.incrementAndGet(); if (previousCount == 0) { // previously there were no active requests, but now there are -- signal to any waitForQuiescence threads that they need to // begin waiting again monitor.enter(); monitor.leave(); } }
void awaitHealthy(long timeout, TimeUnit unit) throws TimeoutException { monitor.enter(); try { if (!monitor.waitForUninterruptibly(awaitHealthGuard, timeout, unit)) { throw new TimeoutException( "Timeout waiting for the services to become healthy. The " + "following services have not started: " + Multimaps.filterKeys(servicesByState, in(ImmutableSet.of(NEW, STARTING)))); } checkHealthy(); } finally { monitor.leave(); } }
public void requestFinished() { int newCount = activeRequests.decrementAndGet(); lastRequestFinishedNanos.set(System.nanoTime()); if (newCount == 0) { // there are no active requests, so signal to any waitForQuiescence threads that they can begin waiting for their quietPeriod monitor.enter(); monitor.leave(); } }
/** * Attempts to start the timer immediately prior to the service being started via {@link * Service#startAsync()}. */ void tryStartTiming(Service service) { monitor.enter(); try { Stopwatch stopwatch = startupTimers.get(service); if (stopwatch == null) { startupTimers.put(service, Stopwatch.createStarted()); } } finally { monitor.leave(); } }
ImmutableMap<Service, Long> startupTimes() { List<Entry<Service, Long>> loadTimes; monitor.enter(); try { loadTimes = Lists.newArrayListWithCapacity(startupTimers.size()); // N.B. There will only be an entry in the map if the service has started for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) { Service service = entry.getKey(); Stopwatch stopWatch = entry.getValue(); if (!stopWatch.isRunning() && !(service instanceof NoOpService)) { loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS))); } } } finally { monitor.leave(); } Collections.sort( loadTimes, Ordering.natural() .onResultOf( new Function<Entry<Service, Long>, Long>() { @Override public Long apply(Entry<Service, Long> input) { return input.getValue(); } })); return ImmutableMap.copyOf(loadTimes); }
void awaitStopped(long timeout, TimeUnit unit) throws TimeoutException { monitor.enter(); try { if (!monitor.waitForUninterruptibly(stoppedGuard, timeout, unit)) { throw new TimeoutException( "Timeout waiting for the services to stop. The following " + "services have not stopped: " + Multimaps.filterKeys(servicesByState, not(in(EnumSet.of(TERMINATED, FAILED))))); } } finally { monitor.leave(); } }
/** * Marks the {@link State} as ready to receive transitions. Returns true if no transitions have * been observed yet. */ void markReady() { monitor.enter(); try { if (!transitioned) { // nothing has transitioned since construction, good. ready = true; } else { // This should be an extremely rare race condition. List<Service> servicesInBadStates = Lists.newArrayList(); for (Service service : servicesByState().values()) { if (service.state() != NEW) { servicesInBadStates.add(service); } } throw new IllegalArgumentException( "Services started transitioning asynchronously before " + "the ServiceManager was constructed: " + servicesInBadStates); } } finally { monitor.leave(); } }
ImmutableMultimap<State, Service> servicesByState() { ImmutableSetMultimap.Builder<State, Service> builder = ImmutableSetMultimap.builder(); monitor.enter(); try { for (Entry<State, Service> entry : servicesByState.entries()) { if (!(entry.getValue() instanceof NoOpService)) { builder.put(entry); } } } finally { monitor.leave(); } return builder.build(); }
void awaitStopped(long timeout, TimeUnit unit) throws TimeoutException { monitor.enter(); try { if (!monitor.waitForUninterruptibly(stoppedGuard, timeout, unit)) { throw new TimeoutException( "Timeout waiting for the services to stop. The following " + "services have not stopped: " + Multimaps.filterKeys(servicesByState, not(in(EnumSet.of(TERMINATED, FAILED))))); } } finally { monitor.leave(); } }
void awaitHealthy(long timeout, TimeUnit unit) throws TimeoutException { monitor.enter(); try { if (!monitor.waitForUninterruptibly(awaitHealthGuard, timeout, unit)) { throw new TimeoutException( "Timeout waiting for the services to become healthy. The " + "following services have not started: " + Multimaps.filterKeys(servicesByState, in(ImmutableSet.of(NEW, STARTING)))); } checkHealthy(); } finally { monitor.leave(); } }
ImmutableMap<Service, Long> startupTimes() { List<Entry<Service, Long>> loadTimes; monitor.enter(); try { loadTimes = Lists.newArrayListWithCapacity(startupTimers.size()); // N.B. There will only be an entry in the map if the service has started for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) { Service service = entry.getKey(); Stopwatch stopWatch = entry.getValue(); if (!stopWatch.isRunning() && !(service instanceof NoOpService)) { loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS))); } } } finally { monitor.leave(); } Collections.sort( loadTimes, Ordering.natural() .onResultOf( new Function<Entry<Service, Long>, Long>() { @Override public Long apply(Entry<Service, Long> input) { return input.getValue(); } })); return ImmutableMap.copyOf(loadTimes); }
/** * Invoke this method to transition the service to the {@link State#FAILED}. The service will * <b>not be stopped</b> if it is running. Invoke this method when a service has failed critically * or otherwise cannot be started nor stopped. */ protected final void notifyFailed(Throwable cause) { checkNotNull(cause); monitor.enter(); try { State previous = state(); switch (previous) { case NEW: case TERMINATED: throw new IllegalStateException("Failed while in state:" + previous, cause); case RUNNING: case STARTING: case STOPPING: snapshot = new StateSnapshot(FAILED, false, cause); enqueueFailedEvent(previous, cause); break; case FAILED: // Do nothing break; } } finally { monitor.leave(); dispatchListenerEvents(); } }
void awaitHealthy(long timeout, TimeUnit unit) throws TimeoutException { monitor.enter(); try { if (!monitor.waitForUninterruptibly(awaitHealthGuard, timeout, unit)) { throw new TimeoutException( "Timeout waiting for the services to become healthy. The " + "following services have not started: " + Multimaps.filterKeys(servicesByState, in(ImmutableSet.of(NEW, STARTING)))); } checkHealthy(); } finally { monitor.leave(); } }
/** * Implementing classes should invoke this method once their service has stopped. It will cause * the service to transition from {@link State#STARTING} or {@link State#STOPPING} to {@link * State#TERMINATED}. * * @throws IllegalStateException if the service is not one of {@link State#STOPPING}, {@link * State#STARTING}, or {@link State#RUNNING}. */ protected final void notifyStopped() { monitor.enter(); try { State previous = state(); switch (previous) { case NEW: case TERMINATED: case FAILED: throw new IllegalStateException("Cannot notifyStopped() when the service is " + previous); case RUNNING: case STARTING: case STOPPING: snapshot = new StateSnapshot(TERMINATED); enqueueTerminatedEvent(previous); break; } } finally { monitor.leave(); dispatchListenerEvents(); } }
ImmutableMap<Service, Long> startupTimes() { List<Entry<Service, Long>> loadTimes; monitor.enter(); try { loadTimes = Lists.newArrayListWithCapacity(startupTimers.size()); // N.B. There will only be an entry in the map if the service has started for (Entry<Service, Stopwatch> entry : startupTimers.entrySet()) { Service service = entry.getKey(); Stopwatch stopWatch = entry.getValue(); if (!stopWatch.isRunning() && !(service instanceof NoOpService)) { loadTimes.add(Maps.immutableEntry(service, stopWatch.elapsed(MILLISECONDS))); } } } finally { monitor.leave(); } Collections.sort( loadTimes, Ordering.natural() .onResultOf( new Function<Entry<Service, Long>, Long>() { @Override public Long apply(Entry<Service, Long> input) { return input.getValue(); } })); return ImmutableMap.copyOf(loadTimes); }