Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 package org.ros.node.service;
00018
00019 import org.ros.internal.node.CountDownRegistrantListener;
00020
00021 import java.util.concurrent.CountDownLatch;
00022 import java.util.concurrent.TimeUnit;
00023
00030 public class CountDownServiceServerListener<T, S> extends
00031 CountDownRegistrantListener<ServiceServer<T, S>> implements ServiceServerListener<T, S> {
00032
00033 private final CountDownLatch shutdownLatch;
00034
00039 public static <T, S> CountDownServiceServerListener<T, S> newDefault() {
00040 return newFromCounts(1, 1, 1, 1);
00041 }
00042
00053 public static <T, S> CountDownServiceServerListener<T, S> newFromCounts(
00054 int masterRegistrationSuccessCount, int masterRegistrationFailureCount,
00055 int masterUnregistrationSuccessCount, int masterUnregistrationFailureCount) {
00056 return new CountDownServiceServerListener<T, S>(new CountDownLatch(
00057 masterRegistrationSuccessCount), new CountDownLatch(masterRegistrationFailureCount),
00058 new CountDownLatch(masterUnregistrationSuccessCount), new CountDownLatch(
00059 masterUnregistrationFailureCount));
00060 }
00061
00062 private CountDownServiceServerListener(CountDownLatch masterRegistrationSuccessLatch,
00063 CountDownLatch masterRegistrationFailureLatch,
00064 CountDownLatch masterUnregistrationSuccessLatch,
00065 CountDownLatch masterUnregistrationFailureLatch) {
00066 super(masterRegistrationSuccessLatch, masterRegistrationFailureLatch,
00067 masterUnregistrationSuccessLatch, masterUnregistrationFailureLatch);
00068 shutdownLatch = new CountDownLatch(1);
00069 }
00070
00071 @Override
00072 public void onShutdown(ServiceServer<T, S> server) {
00073 shutdownLatch.countDown();
00074 }
00075
00081 public void awaitShutdown() throws InterruptedException {
00082 shutdownLatch.await();
00083 }
00084
00096 public boolean awaitShutdown(long timeout, TimeUnit unit) throws InterruptedException {
00097 return shutdownLatch.await(timeout, unit);
00098 }
00099 }