org.ros.master.uri
Class SwitchableMasterUriProvider

java.lang.Object
  extended by org.ros.master.uri.SwitchableMasterUriProvider
All Implemented Interfaces:
MasterUriProvider

public class SwitchableMasterUriProvider
extends java.lang.Object
implements MasterUriProvider

A proxying MasterUriProvider which can be switched between providers.

This class is thread-safe.


Nested Class Summary
static interface SwitchableMasterUriProvider.MasterUriProviderSwitcher
          Perform a switch between MasterUriProvider instances for the SwitchableMasterUriProvider.
 
Constructor Summary
SwitchableMasterUriProvider(MasterUriProvider provider)
           
 
Method Summary
 java.net.URI getMasterUri()
          Get a master URI.
 java.net.URI getMasterUri(long timeout, java.util.concurrent.TimeUnit unit)
          Get a master URI within a given amount of time.
 void switchProvider(SwitchableMasterUriProvider.MasterUriProviderSwitcher switcher)
          Switch between providers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwitchableMasterUriProvider

public SwitchableMasterUriProvider(MasterUriProvider provider)
Parameters:
provider - the initial provider to use
Method Detail

getMasterUri

public java.net.URI getMasterUri()
                          throws RosRuntimeException
Description copied from interface: MasterUriProvider
Get a master URI.

There is no guarantee that calling this class twice will provide the same URI.

This call may or may not block until a URI is available.

Specified by:
getMasterUri in interface MasterUriProvider
Returns:
a master URI
Throws:
RosRuntimeException - this exception may or may not be thrown if there is no master URI available

getMasterUri

public java.net.URI getMasterUri(long timeout,
                                 java.util.concurrent.TimeUnit unit)
Description copied from interface: MasterUriProvider
Get a master URI within a given amount of time.

There is no guarantee that calling this class twice will provide the same URI.

This call may or may not block until a URI is available.

Specified by:
getMasterUri in interface MasterUriProvider
Parameters:
timeout - the amount of time to wait for a URI
unit - the time unit for the wait time
Returns:
a master URI or null if none could be obtained within the timeout

switchProvider

public void switchProvider(SwitchableMasterUriProvider.MasterUriProviderSwitcher switcher)
Switch between providers.

Parameters:
switcher - the new provider