CountDownServiceServerListener.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2011 Google Inc.
00003  * 
00004  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
00005  * use this file except in compliance with the License. You may obtain a copy of
00006  * the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  * 
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00012  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
00013  * License for the specific language governing permissions and limitations under
00014  * the License.
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 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49