public final class ServiceDirectory
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
protected class |
ServiceDirectory.BonjourServiceListenerInfo
service listener information for Bonjour
|
Modifier and Type | Field and Description |
---|---|
protected java.util.Map<ServiceListener,ServiceDirectory.BonjourServiceListenerInfo> |
_listenerMap
Table mapping ServiceListener to the corresponding bonjour service listener
|
Constructor and Description |
---|
ServiceDirectory()
ServiceDirectory constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addServiceListener(java.lang.Class<?> protocol,
ServiceListener listener)
Add a listener for addition and removal of service providers.
|
void |
addServiceListener(java.lang.String type,
ServiceListener listener)
Add a listener for addition and removal of service providers.
|
static ServiceDirectory |
defaultDirectory()
Get the default ServiceDirectory instance.
|
void |
dispose()
Shutdown bonjour and the RPC server and dispose of all resources.
|
ServiceRef[] |
findServicesWithType(java.lang.Class<?> protocol,
long timeout)
Convenience method for making a request to find service providers of a specific service type and waiting
a specified amount of time to find those services.
|
ServiceRef[] |
findServicesWithType(java.lang.String serviceType,
long timeout)
Convenience method for making a request to find service providers of a specific service type and waiting a specified amount of time to find those services.
|
protected static xal.extension.service.ClientHandler<?> |
getClientHandler(java.lang.Object proxy)
Convenience method for getting the ClientHandler for the given proxy
|
protected static java.lang.String |
getDefaultType(java.lang.Class<?> protocol)
Form a valid type based on the specified protocol by replacing the protocol's name with
a valid name in which "." is replaced by "_".
|
static java.lang.String |
getHost(java.lang.Object proxy)
Get the remote host for the service
|
static int |
getPort(java.lang.Object proxy)
Get the remote port at which the service is available.
|
static java.lang.Class<?> |
getProtocol(java.lang.Object proxy)
Get the protocol of the remote proxy
|
<T> T |
getProxy(java.lang.Class<T> protocol,
ServiceRef serviceRef)
Get a proxy to the service with the given service reference and protocol.
|
static java.lang.String |
getServiceName(java.lang.Object proxy)
Get the service name for the remote service
|
java.util.List<java.lang.String> |
getStandardCodingTypes()
Get a list of standard data types which are supported for coding and decoding
|
java.util.List<java.lang.String> |
getSupportedCodingTypes()
Get a list of all data types which are supported for coding and decoding
|
boolean |
isActive()
Check if service support is active.
|
boolean |
isLoopback()
Determine if bonjour is running in loopback mode which would indicate that the computer is isolated from the network.
|
ServiceRef |
lookupService(java.lang.String type,
java.lang.String name)
Lookup the service given the fully qualified service type and the fully qualified service name
|
ServiceRef |
lookupService(java.lang.String type,
java.lang.String name,
int timeout)
Lookup the service given the fully qualified service type and the fully qualified service name and block until a match is found or the specified timeout has expired.
|
<CustomType,RepresentationType> |
registerCodingType(java.lang.Class<CustomType> type,
ConversionAdaptor<CustomType,RepresentationType> adaptor)
Register the custom type and its associated adaptor to use for encoding and decoding objects of the custom type
|
<ProtocolType> |
registerService(java.lang.Class<ProtocolType> protocol,
java.lang.String name,
ProtocolType provider)
Register a local service provider.
|
<ProtocolType> |
registerService(java.lang.Class<ProtocolType> protocol,
java.lang.String serviceName,
ProtocolType provider,
java.util.Map<java.lang.String,java.lang.Object> properties)
Register a local service provider.
|
void |
removeServiceListener(ServiceListener listener)
Remove a listener of service availability events.
|
boolean |
unregisterService(ServiceRef serviceRef)
Unregister a local service.
|
protected java.util.Map<ServiceListener,ServiceDirectory.BonjourServiceListenerInfo> _listenerMap
public ServiceDirectory() throws ServiceException
ServiceException
public static ServiceDirectory defaultDirectory()
public void dispose()
public boolean isActive()
public boolean isLoopback()
public java.util.List<java.lang.String> getStandardCodingTypes()
public java.util.List<java.lang.String> getSupportedCodingTypes()
public <CustomType,RepresentationType> void registerCodingType(java.lang.Class<CustomType> type, ConversionAdaptor<CustomType,RepresentationType> adaptor)
type
- type to identify and process for encoding and decodingadaptor
- translator between the custom type and representation constructspublic <ProtocolType> ServiceRef registerService(java.lang.Class<ProtocolType> protocol, java.lang.String name, ProtocolType provider) throws ServiceException
protocol
- The protocol identifying the service type.name
- The unique name of the service provider.provider
- The provider which handles the service requests.ServiceException
public <ProtocolType> ServiceRef registerService(java.lang.Class<ProtocolType> protocol, java.lang.String serviceName, ProtocolType provider, java.util.Map<java.lang.String,java.lang.Object> properties)
protocol
- The protocol identifying the service type.serviceName
- The unique name of the service provider.provider
- The provider which handles the service requests.properties
- Properties.public boolean unregisterService(ServiceRef serviceRef) throws ServiceException
serviceRef
- The service reference whose service should be shutdown.ServiceException
public <T> T getProxy(java.lang.Class<T> protocol, ServiceRef serviceRef)
protocol
- The protocol implemented by the service.serviceRef
- The service reference.public ServiceRef lookupService(java.lang.String type, java.lang.String name)
type
- The fully qualified service typename
- The fully qualified service namepublic ServiceRef lookupService(java.lang.String type, java.lang.String name, int timeout) throws ServiceException
type
- The fully qualified service typename
- The fully qualified service nametimeout
- The timeout in milliseconds to block until a match is foundServiceException
public ServiceRef[] findServicesWithType(java.lang.Class<?> protocol, long timeout) throws ServiceException
protocol
- The protocol identifying the service type for which to find providers.timeout
- Time to block in milliseconds while waiting for services to be discovered.ServiceException
addServiceListener(java.lang.Class<?>, xal.extension.service.ServiceListener)
public ServiceRef[] findServicesWithType(java.lang.String serviceType, long timeout) throws ServiceException
serviceType
- The type of service to find.timeout
- Time to block in milliseconds while waiting for services to be discovered.ServiceException
addServiceListener(java.lang.Class<?>, xal.extension.service.ServiceListener)
public void addServiceListener(java.lang.Class<?> protocol, ServiceListener listener) throws ServiceException
protocol
- The protocol identifying the service type.listener
- The receiver of service availability events.ServiceException
public void addServiceListener(java.lang.String type, ServiceListener listener) throws ServiceException
type
- The type of service provided.listener
- The receiver of service availability events.ServiceException
public void removeServiceListener(ServiceListener listener)
listener
- The listener of service availability events.protected static java.lang.String getDefaultType(java.lang.Class<?> protocol)
protocol
- The protocol for which to get a valid typepublic static java.lang.String getHost(java.lang.Object proxy)
proxy
- the proxy to the service at the remote hostpublic static int getPort(java.lang.Object proxy)
proxy
- the proxy to the service at the remote hostpublic static java.lang.String getServiceName(java.lang.Object proxy)
proxy
- the proxy to the remote servicepublic static java.lang.Class<?> getProtocol(java.lang.Object proxy)
proxy
- the proxy to the remote serviceprotected static xal.extension.service.ClientHandler<?> getClientHandler(java.lang.Object proxy)
proxy
- the proxy for which we seek its client handler