CountDownRegistrantListener.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.internal.node;
00018 
00019 import org.ros.node.topic.CountDownPublisherListener;
00020 
00021 import java.util.concurrent.CountDownLatch;
00022 import java.util.concurrent.TimeUnit;
00023 
00027 public class CountDownRegistrantListener<T> implements RegistrantListener<T> {
00028 
00029   private final CountDownLatch masterRegistrationSuccessLatch;
00030   private final CountDownLatch masterRegistrationFailureLatch;
00031   private final CountDownLatch masterUnregistrationSuccessLatch;
00032   private final CountDownLatch masterUnregistrationFailureLatch;
00033 
00037   public CountDownRegistrantListener() {
00038     this(1, 1, 1, 1);
00039   }
00040 
00051   public CountDownRegistrantListener(int masterRegistrationSuccessCount,
00052       int masterRegistrationFailureCount, int masterUnregistrationSuccessCount,
00053       int masterUnregistrationFailureCount) {
00054     this(new CountDownLatch(masterRegistrationSuccessCount), new CountDownLatch(
00055         masterRegistrationFailureCount), new CountDownLatch(masterUnregistrationSuccessCount),
00056         new CountDownLatch(masterUnregistrationFailureCount));
00057   }
00058 
00059   public CountDownRegistrantListener(CountDownLatch masterRegistrationSuccessLatch,
00060       CountDownLatch masterRegistrationFailureLatch,
00061       CountDownLatch masterUnregistrationSuccessLatch,
00062       CountDownLatch masterUnregistrationFailureLatch) {
00063     this.masterRegistrationSuccessLatch = masterRegistrationSuccessLatch;
00064     this.masterRegistrationFailureLatch = masterRegistrationFailureLatch;
00065     this.masterUnregistrationSuccessLatch = masterUnregistrationSuccessLatch;
00066     this.masterUnregistrationFailureLatch = masterUnregistrationFailureLatch;
00067   }
00068 
00069   @Override
00070   public void onMasterRegistrationSuccess(T registrant) {
00071     masterRegistrationSuccessLatch.countDown();
00072   }
00073 
00074   @Override
00075   public void onMasterRegistrationFailure(T registrant) {
00076     masterRegistrationFailureLatch.countDown();
00077   }
00078 
00079   @Override
00080   public void onMasterUnregistrationSuccess(T registrant) {
00081     masterUnregistrationSuccessLatch.countDown();
00082   }
00083 
00084   @Override
00085   public void onMasterUnregistrationFailure(T registrant) {
00086     masterUnregistrationFailureLatch.countDown();
00087   }
00088 
00094   public void awaitMasterRegistrationSuccess() throws InterruptedException {
00095     masterRegistrationSuccessLatch.await();
00096   }
00097 
00110   public boolean awaitMasterRegistrationSuccess(long timeout, TimeUnit unit)
00111       throws InterruptedException {
00112     return masterRegistrationSuccessLatch.await(timeout, unit);
00113   }
00114 
00120   public void awaitMasterUnregistrationSuccess() throws InterruptedException {
00121     masterUnregistrationSuccessLatch.await();
00122   }
00123 
00136   public boolean awaitMasterUnregistrationSuccess(long timeout, TimeUnit unit)
00137       throws InterruptedException {
00138     return masterUnregistrationSuccessLatch.await(timeout, unit);
00139   }
00140 
00146   public void awaitMasterRegistrationFailure() throws InterruptedException {
00147     masterRegistrationFailureLatch.await();
00148   }
00149 
00162   public boolean awaitMasterRegistrationFailure(long timeout, TimeUnit unit)
00163       throws InterruptedException {
00164     return masterRegistrationFailureLatch.await(timeout, unit);
00165   }
00166 
00172   public void awaitMasterUnregistrationFailure() throws InterruptedException {
00173     masterUnregistrationFailureLatch.await();
00174   }
00175 
00188   public boolean awaitMasterUnregistrationFailure(long timeout, TimeUnit unit)
00189       throws InterruptedException {
00190     return masterUnregistrationFailureLatch.await(timeout, unit);
00191   }
00192 }


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