public final class SearchManager
extends java.lang.Object
SearchParameter) and obtaining references to devices/services with
known endpoint addresses.
A typical usage of the search functionality states that the caller provides an implementation
of the SearchCallback interface which will receive asynchronous notifications about
matching services/devices found during the search. Given this SearchCallback
implementation and a SearchParameter instance describing what kind of
devices/services to look for, the actual search can be started as depicted in the following
sample code:
SearchCallback callback = ...; // provide a receiver for search matches SearchParameter search = ...; // specify what to search for SearchManager.searchDevice(parameter, callback, null);
This example starts a search for a device, as the name of the called method searchDevice(SearchParameter, SearchCallback, DeviceListener) suggests. If a device fulfilling
the given search parameter criteria is found, this will be indicated asynchronously by a call to
SearchCallback#deviceFound(DeviceReference, SearchParameter). Similarly, if a search for
services was issued (by means of #searchService(SearchParameter, SearchCallback)), then
matches would result in a call to SearchCallback#serviceFound(ServiceReference,
SearchParameter).
The second purpose of this class is to enable the obtaining of a reference to a (local or
remote) device/service when knowing its endpoint address (i.e. one of its endpoint references).
This process differs somehow from the aforementioned search as it doesn't involve probing the
network to assert the existence of the specified device or service (as its endpoint reference is
already known). Thus, it is possible that calling DeviceReference.getDevice() or ServiceReference.getService() on the returned reference object results in a CommunicationException being thrown because the specified device/service is for some reason
currently not reachable (e.g. it is not running at the moment or there is no network path
connecting it with the local machine). In contrast, using the search abilities will provide
notifications only about devices/services which are currently running and reachable.
| Modifier and Type | Method and Description |
|---|---|
static ServiceReference |
createServiceReference(EndpointReference epr,
SecurityKey key,
QNameSet portTypes,
java.lang.String comManId)
Gets service reference of service with specified endpoint reference and security key.
|
static DeviceReference |
getDeviceReference(EndpointReference epr,
SecurityKey key,
DeviceListener listener,
DiscoveryBinding binding,
java.lang.String comManId)
Gets device reference of device with specified endpoint reference and security key.
|
static DeviceReference |
getDeviceReference(EndpointReference epr,
URI address,
SecurityKey key,
DeviceListener listener,
DiscoveryBinding binding)
Gets device reference of device specified by an endpoint reference, an address and an security
key.
|
static DeviceReference |
getDeviceReference(EndpointReference epr,
URI address,
SecurityKey key,
DeviceListener listener,
java.lang.String comManId)
Gets device reference of device specified by an endpoint reference, an address and an security
key.
|
static DeviceReference |
getDeviceReference(HelloData helloData,
SecurityKey key,
DeviceListener listener,
java.lang.String comManId)
Gets device reference of device with specified endpoint reference(from helloData) and security
key.
|
static DataStructure |
getLocalDevices()
Returns a data structure containing all the local devices within the current JMEDS framework.
|
static ServiceReference |
getServiceReference(EndpointReference epr,
SecurityKey key,
java.lang.String comManId)
Gets service reference of service with specified endpoint reference and security key.
|
static void |
searchDevice(SearchParameter search,
SearchCallback callback,
DeviceListener listener)
Initiates a search for devices.
|
static void |
searchService(SearchParameter search,
SearchCallback callback,
DeviceListener listener)
Searches for services.
|
public static DeviceReference getDeviceReference(EndpointReference epr, URI address, SecurityKey key, DeviceListener listener, java.lang.String comManId)
listener is not null, it will be used as callback for device
changes of the corresponding device.
This method will NOT try to discover (resolve/probe) the device. If the address is
unreachable or wrong this method will return null .
A DeviceReference that was created by this method has not DiscoveryBinding and will therefore not receive hello or bye messages from its referenced device.
epr - endpoint reference of device for which to get device referenceaddress - the address of the devicekey - the security key for this devicelistener - optional; will be informed on changes of device' statecomManId - ID of the communication manager to use when interacting with supplied endpoint referencepublic static DeviceReference getDeviceReference(EndpointReference epr, URI address, SecurityKey key, DeviceListener listener, DiscoveryBinding binding)
listener is not null, it will be used as callback for device
changes of the corresponding device.
This method will NOT try to discover (resolve/probe) the device. If the address is
unreachable or wrong this method will return null .
epr - endpoint reference of device for which to get device referenceaddress - the address of the devicekey - the security key for this devicelistener - optional; will be informed on changes of device' statebinding - a DiscoveryBinding that specifies how to receive hello and bye messages for the DeviceReferencepublic static DeviceReference getDeviceReference(EndpointReference epr, SecurityKey key, DeviceListener listener, DiscoveryBinding binding, java.lang.String comManId)
listener is not null, it will be used as callback for device changes of the
corresponding device.epr - endpoint reference of device for which to get device referencekey - the security key for this devicelistener - optional; will be informed on changes of device' statebinding - a DiscoveryBinding that specifies how to receive hello and bye messages for the DeviceReferencepublic static DeviceReference getDeviceReference(HelloData helloData, SecurityKey key, DeviceListener listener, java.lang.String comManId)
listener is not null, it will be used as callback for device
changes of the corresponding device.helloData - hello data of device for which to get device referencekey - the security key for this devicelistener - optional; will be informed about changes of the device's statepublic static ServiceReference getServiceReference(EndpointReference epr, SecurityKey key, java.lang.String comManId)
The returned @link ServiceReference instance can be used to obtain the actual
service by calling ServiceReference.getService().
epr - endpoint reference of service to get service reference forkey - the security key for this devicecomManId - ID of the communication manager to use when interacting with supplied endpoint referencepublic static ServiceReference createServiceReference(EndpointReference epr, SecurityKey key, QNameSet portTypes, java.lang.String comManId) throws DuplicateServiceReferenceException
The returned @link ServiceReference instance can be used to obtain the actual
service by calling ServiceReference.getService().
epr - endpoint reference of service to get service reference forkey - the security key for this devicecomManId - ID of the communication manager to use when interacting with supplied endpoint referenceDuplicateServiceReferenceException - in case a service reference with the same endpoint reference is already presentpublic static void searchService(SearchParameter search, SearchCallback callback, DeviceListener listener)
callback by means of the
method SearchCallback#serviceFound(ServiceReference, SearchParameter). search - search parameter to specify the criteria that matching services must fulfillcallback - recipient of notifications about found matching serviceslistener - maybe null.public static void searchDevice(SearchParameter search, SearchCallback callback, DeviceListener listener)
search.
When a matching device is found, it is passed to the method SearchCallback#deviceFound(DeviceReference, SearchParameter) of the specified callback
argument. Should listener not be null, it will be registered
for tracking device changes on each matching device.
search - the search criteria for matching devicescallback - where search results are to be delivered to; must not be nulllistener - if not null, the listener is used for asynchronous callbacks each time the state of a device
matching the search criteria changes (i.e. when it goes online, etc.)public static DataStructure getLocalDevices()