### Question:
LifecycleSupervisor implements LifecycleAware { public synchronized void supervise(LifecycleAware lifecycleAware, SupervisorPolicy policy, LifecycleState desiredState) { if(this.monitorService.isShutdown() || this.monitorService.isTerminated() || this.monitorService.isTerminating()){ throw new FlumeException("Supervise called on " + lifecycleAware + " " + "after shutdown has been initiated. " + lifecycleAware + " will not" + " be started"); } Preconditions.checkState(!supervisedProcesses.containsKey(lifecycleAware), "Refusing to supervise " + lifecycleAware + " more than once"); if (logger.isDebugEnabled()) { logger.debug("Supervising service:{} policy:{} desiredState:{}", new Object[] { lifecycleAware, policy, desiredState }); } Supervisoree process = new Supervisoree(); process.status = new Status(); process.policy = policy; process.status.desiredState = desiredState; process.status.error = false; MonitorRunnable monitorRunnable = new MonitorRunnable(); monitorRunnable.lifecycleAware = lifecycleAware; monitorRunnable.supervisoree = process; monitorRunnable.monitorService = monitorService; supervisedProcesses.put(lifecycleAware, process); ScheduledFuture<?> future = monitorService.scheduleWithFixedDelay( monitorRunnable, 0, 3, TimeUnit.SECONDS); monitorFutures.put(lifecycleAware, future); } LifecycleSupervisor(); @Override synchronized void start(); @Override synchronized void stop(); synchronized void fail(); synchronized void supervise(LifecycleAware lifecycleAware,
      SupervisorPolicy policy, LifecycleState desiredState); synchronized void unsupervise(LifecycleAware lifecycleAware); synchronized void setDesiredState(LifecycleAware lifecycleAware,
      LifecycleState desiredState); @Override synchronized LifecycleState getLifecycleState(); synchronized boolean isComponentInErrorState(LifecycleAware component);  }### Answer:
@Test public void testSupervise() throws LifecycleException, InterruptedException { supervisor.start(); CountingLifecycleAware node = new CountingLifecycleAware(); SupervisorPolicy policy = new SupervisorPolicy.OnceOnlyPolicy(); supervisor.supervise(node, policy, LifecycleState.START); Thread.sleep(10000); node = new CountingLifecycleAware(); policy = new SupervisorPolicy.OnceOnlyPolicy(); supervisor.supervise(node, policy, LifecycleState.START); Thread.sleep(5000); supervisor.stop(); }