org.ws4d.java.client
Class DefaultClient

java.lang.Object
  extended by org.ws4d.java.client.DefaultClient
All Implemented Interfaces:
HelloListener, SearchCallback, EventListener, DeviceListener, ServiceListener

public class DefaultClient
extends java.lang.Object
implements DeviceListener, ServiceListener, SearchCallback, EventListener, HelloListener

Default DPWS Client implementation. This class provides easy access to several points of interaction within the DPWS framework, such as searching for devices/services, tracking a device's or service's state changes and receiving events from subscribed services.

The basic idea behind this class is: it extends several callback interfaces and provides empty implementations for all of their methods, so that an implementing client can easily overwrite those in which it is really interested in.

A simple use case of this class could be a client searching for a particular device. This can be accomplished by a call to searchDevice(SearchParameter) providing the desired search criteria within the expected SearchParameter argument. The framework will then start looking asynchronously for devices matching those criteria and will invoke deviceFound(DeviceReference, SearchParameter) each time a corresponding device is discovered.
Searching for services can be done in a similar manner, this time using the method searchService(SearchParameter) to initiate the search and receiving results by means of serviceFound(ServiceReference, SearchParameter).

When a client starts a device search, it is automatically registered as DeviceListener to any device matching the search criteria. This is especially useful for getting notifications about state changes of the device, such as a device shut-down, an update of a device's metadata, etc.

Listening to service state changes differs from the aforementioned approach. In order to start receiving service update notifications, a client must register itself for that purpose. It will then be notified about any state change regarding every service the DPWS framework knows about. This also includes any services not explicitly searched for by this client.

A simple client implementation interested in devices providing the ex:Printer port type (where ex is a XML namespace prefix referring to the http://www.example.org/printing namespace) could look like:

 // create a new client
 Client client = new DefaultClient() {
 
     // overwrite deviceFound method in order to receive callbacks
     public void deviceFound(DeviceReference devRef, SearchParameter search) {
         // start interacting with matching device
         ...
     }
 
 };
 // describe device port type to look for
 QName printerType = new QName("Printer", "http://www.example.org/printlng");
 QNameSet types = new QNameSet(printerType);
 
 // create a search parameter object and store desired type(s) into it
 SearchParameter criteria = new SearchParameter();
 criteria.setDeviceTypes(types);
 
 // start the asynchronous search
 client.searchDevice(criteria);
 


Constructor Summary
DefaultClient()
          Default constructor.
 
Method Summary
 void deviceBuiltUp(DeviceReference deviceRef, Device device)
          Callback method, if device within the DeviceReference was created.
 void deviceBye(DeviceReference deviceRef)
          Callback method, if device bye was received or the local device was stopped.
 void deviceChanged(DeviceReference deviceRef)
          Callback method, if device was changed and the device data is no longer accurate.
 void deviceCommunicationErrorOrReset(DeviceReference deviceRef)
          Callback method, if communication with the remote device of the DeviceReference has failed or the reference was reset.
 void deviceCompletelyDiscovered(DeviceReference deviceRef)
          Callback method, if discovery metadata was completely received from device (via directed probe).
 void deviceFound(DeviceReference devRef, SearchParameter search)
          This method is called each time a device matching the initial search criteria (as contained within argument search) has been found.
 void deviceRunning(DeviceReference deviceRef)
          Callback method, if device is usable.
 ParameterValue eventReceived(ClientSubscription subscription, URI actionURI, ParameterValue parameterValue)
          Callback method to receive events.
 EventSink generateEventSink(int configurationId)
          Generates an event sink which can be used when registering for event notifications from a service.
 DataStructure getAllDiscoveryBindings()
           
 DeviceReference getDeviceReference(EndpointReference deviceEpr)
           
 DeviceReference getDeviceReference(EndpointReference deviceEpr, DiscoveryBinding binding)
          Gets device reference of device with specified endpoint reference.
 DeviceReference getDeviceReference(HelloData helloData)
          Gets device reference of device which sent the specified hello data.
 EventSink getEventSink(DataStructure bindings)
          Gets an event sink, which can be used when registering for event notifications from a service.
 ServiceReference getServiceReference(EndpointReference serviceEpr, java.lang.String comManId)
          Gets service reference of service with specified endpoint reference.
 void helloReceived(HelloData helloData)
          This method is called, if matching hello was received.
 void registerHelloListening()
          Registers for incoming HelloMessages for all possible domains.
 void registerHelloListening(DiscoveryBinding binding)
          Registers for incoming Hello messages.
 void registerHelloListening(SearchParameter search)
          Registers for incoming HelloMessages for all possible domains, with specified types and scopes (SearchParameter).
 void registerHelloListening(SearchParameter search, DiscoveryBinding binding)
          Registers for incoming Hello messages, which matches to the specified types and scopes (SearchParameter).
 void registerHelloListening(SearchParameter search, DiscoveryBinding binding, HelloListener helloListener)
          Registers for incoming HelloMessages, which matches to the specified types and scopes (SearchParameter).
 void registerServiceListening()
          Registers client for service reference changes.
 void searchDevice(SearchParameter search)
          Shorthand method for searching devices.
 void searchService(SearchParameter search)
          Searches for services.
 void serviceChanged(ServiceReference serviceRef, Service service)
          Callback method, if service within the ServiceReference has been changed.
 void serviceCreated(ServiceReference serviceRef, Service service)
          Callback method, if the service within the ServiceReference was created.
 void serviceDisposed(ServiceReference serviceRef)
          Callback method, if the service within the ServiceReference was disposed of.
 void serviceFound(ServiceReference servRef, SearchParameter search)
          This method is called each time a service matching the initial search criteria (as contained within argument search) has been found.
 void subscriptionEndReceived(ClientSubscription subscription, URI reason)
          Callback method to receive unexpected subscription ends from event sources.
 void subscriptionTimeoutReceived(ClientSubscription subscription)
          Callback method to receive timeouts of subscriptions.
 void unregisterHelloListening(DiscoveryBinding binding)
          Unregisters the listeners for incoming hello messages according to the given DiscoveryBinding.
 void unregisterHelloListening(SearchParameter search)
          Unregisters the listeners for incoming hello messages according to the given SearchParameter and ALL DiscoveryBinding found.
 void unregisterHelloListening(SearchParameter search, DiscoveryBinding binding)
          Unregisters the listeners for incoming hello messages according to the given SearchParameter and DiscoveryBinding.
 void unregisterServiceListening()
          Unregisters service listening for this service client.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultClient

public DefaultClient()
Default constructor. Ensures the DPWS framework is running (see DPWSFramework.isRunning(). Throws a java.lang.RuntimeException if this is not the case.

Throws:
java.lang.RuntimeException - if the DPWS framework is not running; i.e. it was either not started by means of DPWSFramework.start(String[]) or has already been stopped via DPWSFramework.stop() before calling this constructor
Method Detail

getAllDiscoveryBindings

public DataStructure getAllDiscoveryBindings()

getEventSink

public EventSink getEventSink(DataStructure bindings)
Description copied from interface: EventListener
Gets an event sink, which can be used when registering for event notifications from a service. The supplied data structure bindings is supposed to contain at least one CommunicationBinding instance denoting a local transport address, at which incoming notifications shall be delivered to. The EventSink is associated with the EventListener.

Specified by:
getEventSink in interface EventListener
Parameters:
bindings - a data structure of CommunicationBinding instances to expose the created event sink over
Returns:
the event sink

generateEventSink

public EventSink generateEventSink(int configurationId)
Generates an event sink which can be used when registering for event notifications from a service. The supplied configuration id is supposed to refer to an EventSink property which contains at least one binding property to create a CommunicationBinding instance. This CommunicationBinding instance defines a local transport address, to which incoming notifications will be delivered.

Parameters:
configurationId - Configuration id of the properties of the event sink to generate
Returns:
a new event sink

deviceBye

public void deviceBye(DeviceReference deviceRef)
Description copied from interface: DeviceListener
Callback method, if device bye was received or the local device was stopped.

Specified by:
deviceBye in interface DeviceListener
Parameters:
deviceRef - a reference to the device that caused the notification

deviceCompletelyDiscovered

public void deviceCompletelyDiscovered(DeviceReference deviceRef)
Description copied from interface: DeviceListener
Callback method, if discovery metadata was completely received from device (via directed probe).

Specified by:
deviceCompletelyDiscovered in interface DeviceListener
Parameters:
deviceRef - a reference to the device that caused the notification

deviceChanged

public void deviceChanged(DeviceReference deviceRef)
Description copied from interface: DeviceListener
Callback method, if device was changed and the device data is no longer accurate.

Specified by:
deviceChanged in interface DeviceListener
Parameters:
deviceRef - a reference to the device that caused the notification

deviceRunning

public void deviceRunning(DeviceReference deviceRef)
Description copied from interface: DeviceListener
Callback method, if device is usable.

Specified by:
deviceRunning in interface DeviceListener
Parameters:
deviceRef - a reference to the device that caused the notification

deviceBuiltUp

public void deviceBuiltUp(DeviceReference deviceRef,
                          Device device)
Description copied from interface: DeviceListener
Callback method, if device within the DeviceReference was created.

Specified by:
deviceBuiltUp in interface DeviceListener
Parameters:
deviceRef - a reference to the device that caused the notification
device - the proxy device just built up

deviceCommunicationErrorOrReset

public void deviceCommunicationErrorOrReset(DeviceReference deviceRef)
Description copied from interface: DeviceListener
Callback method, if communication with the remote device of the DeviceReference has failed or the reference was reset.

Specified by:
deviceCommunicationErrorOrReset in interface DeviceListener
Parameters:
deviceRef - a reference to the device that caused the notification

serviceChanged

public void serviceChanged(ServiceReference serviceRef,
                           Service service)
Description copied from interface: ServiceListener
Callback method, if service within the ServiceReference has been changed.

Specified by:
serviceChanged in interface ServiceListener
Parameters:
serviceRef - a reference to the service that caused the notification

serviceCreated

public void serviceCreated(ServiceReference serviceRef,
                           Service service)
Description copied from interface: ServiceListener
Callback method, if the service within the ServiceReference was created.

Specified by:
serviceCreated in interface ServiceListener
Parameters:
serviceRef - a reference to the service that caused the notification qpram service the service that just have changed

serviceDisposed

public void serviceDisposed(ServiceReference serviceRef)
Description copied from interface: ServiceListener
Callback method, if the service within the ServiceReference was disposed of.

Specified by:
serviceDisposed in interface ServiceListener
Parameters:
serviceRef - a reference to the service that caused the notification

registerServiceListening

public void registerServiceListening()
Registers client for service reference changes. Client gets information about service changes.

See Also:
ServiceListener

unregisterServiceListening

public void unregisterServiceListening()
Unregisters service listening for this service client. This method should be called, if holder of reference is no longer interested in this reference.

See Also:
ServiceListener

getDeviceReference

public DeviceReference getDeviceReference(EndpointReference deviceEpr,
                                          DiscoveryBinding binding)
Gets device reference of device with specified endpoint reference. This Client instance will be used as callback for device changes of the corresponding device.

Parameters:
deviceEpr - endpoint reference of device to get device reference for
Returns:
device reference
See Also:
SearchManager#getDeviceReference(EndpointReference, DeviceListener)

getDeviceReference

public DeviceReference getDeviceReference(EndpointReference deviceEpr)

getDeviceReference

public DeviceReference getDeviceReference(HelloData helloData)
Gets device reference of device which sent the specified hello data. This Client instance will be used as callback for device changes of the corresponding device.

Parameters:
helloData - Hello data received from helloReceived(HelloData) callback method.
Returns:
device reference
See Also:
SearchManager.getDeviceReference(HelloData, DeviceListener)

getServiceReference

public ServiceReference getServiceReference(EndpointReference serviceEpr,
                                            java.lang.String comManId)
Gets service reference of service with specified endpoint reference.

Parameters:
serviceEpr - endpoint reference of service to get service reference for
comManId - ID of the communication manager to use when interacting with supplied endpoint reference
Returns:
service reference
See Also:
SearchManager#getServiceReference(EndpointReference)

searchDevice

public void searchDevice(SearchParameter search)
Shorthand method for searching devices. Expect search results asynchronously within this client instance's deviceFound(DeviceReference, SearchParameter) method.

Parameters:
search - search criteria
See Also:
SearchManager.searchDevice(SearchParameter, SearchCallback, DeviceListener)

searchService

public void searchService(SearchParameter search)
Searches for services. Uses search parameter to specify the search. Obtained results will be delivered asynchronously to this client instance's serviceFound(ServiceReference, SearchParameter) method.

Parameters:
search - search parameter to specify the search for device and service
See Also:
SearchManager.searchService(SearchParameter, SearchCallback)

registerHelloListening

public void registerHelloListening()
Registers for incoming HelloMessages for all possible domains.

This method will check every CommunicationManager registered inside the framework and registers all discovery domains found with #registerHelloListening(CommunicationBinding).

The client will be used as receiver for the incoming Hello messages.


registerHelloListening

public void registerHelloListening(SearchParameter search)
Registers for incoming HelloMessages for all possible domains, with specified types and scopes (SearchParameter).

helloReceived(HelloData) is called to deliver the hello data.

This method will check every CommunicationManager registered inside the framework and registers all discovery domains found with #registerHelloListening(CommunicationBinding).

The client will be used as receiver for the incoming Hello messages.

Parameters:
search - containing the types and scopes.

registerHelloListening

public void registerHelloListening(DiscoveryBinding binding)
Registers for incoming Hello messages.

helloReceived(HelloData) is called to deliver the hello data.

*

The client will be used as receiver for the incoming Hello messages.

Parameters:
binding - the binding for the listener.

registerHelloListening

public void registerHelloListening(SearchParameter search,
                                   DiscoveryBinding binding)
Registers for incoming Hello messages, which matches to the specified types and scopes (SearchParameter).

helloReceived(HelloData) is called to deliver the hello data.

The client will be used as receiver for the incoming Hello messages.

Parameters:
search - containing the types and scopes.
binding - the binding for the listener.

registerHelloListening

public void registerHelloListening(SearchParameter search,
                                   DiscoveryBinding binding,
                                   HelloListener helloListener)
Registers for incoming HelloMessages, which matches to the specified types and scopes (SearchParameter).

helloReceived(HelloData) is called to deliver the hello data.

Parameters:
search - containing the types and scopes.
binding - the binding for the listener.
helloListener - the listener to receive the hello data from matching hello messages.

unregisterHelloListening

public void unregisterHelloListening(DiscoveryBinding binding)
Unregisters the listeners for incoming hello messages according to the given DiscoveryBinding.

Parameters:
binding - the binding for the listener.

unregisterHelloListening

public void unregisterHelloListening(SearchParameter search)
Unregisters the listeners for incoming hello messages according to the given SearchParameter and ALL DiscoveryBinding found.

Parameters:
search - containing the types and scopes.

unregisterHelloListening

public void unregisterHelloListening(SearchParameter search,
                                     DiscoveryBinding binding)
Unregisters the listeners for incoming hello messages according to the given SearchParameter and DiscoveryBinding.

Parameters:
search - containing the types and scopes.
binding - the binding for the listener.

helloReceived

public void helloReceived(HelloData helloData)
Description copied from interface: HelloListener
This method is called, if matching hello was received.

Specified by:
helloReceived in interface HelloListener
Parameters:
helloData -

deviceFound

public void deviceFound(DeviceReference devRef,
                        SearchParameter search)
Description copied from interface: SearchCallback
This method is called each time a device matching the initial search criteria (as contained within argument search) has been found.

Specified by:
deviceFound in interface SearchCallback
Parameters:
devRef - a reference to the matching device
search - the collection of criteria the search was initiated with

serviceFound

public void serviceFound(ServiceReference servRef,
                         SearchParameter search)
Description copied from interface: SearchCallback
This method is called each time a service matching the initial search criteria (as contained within argument search) has been found.

Specified by:
serviceFound in interface SearchCallback
Parameters:
servRef - a reference to the matching service
search - the list of criteria the search was initiated with

eventReceived

public ParameterValue eventReceived(ClientSubscription subscription,
                                    URI actionURI,
                                    ParameterValue parameterValue)
Description copied from interface: EventListener
Callback method to receive events. Override this to receive and handle events.

In case the received event corresponds to a WSDLOperation.TYPE_SOLICIT_RESPONSE operation, the response to send back to the event source is taken from the return value of this method.

Specified by:
eventReceived in interface EventListener
Parameters:
subscription - this is the subscription because of which the event was received
actionURI - URI of the subscribed action
parameterValue - parameter value of notification message containing the user data
Returns:
if not null, solicit response message: parameter values will be sent as response to notification sender

subscriptionEndReceived

public void subscriptionEndReceived(ClientSubscription subscription,
                                    URI reason)
Description copied from interface: EventListener
Callback method to receive unexpected subscription ends from event sources. If this method is called, the subscription has been removed from the event sink. Override this to receive and handle subscription ends.

Specified by:
subscriptionEndReceived in interface EventListener
Parameters:
subscription - subscription ended.
reason - Reason why the subscription ends unexpectedly

subscriptionTimeoutReceived

public void subscriptionTimeoutReceived(ClientSubscription subscription)
Description copied from interface: EventListener
Callback method to receive timeouts of subscriptions. Override this to receive and handle timeouts of subscriptions.

Specified by:
subscriptionTimeoutReceived in interface EventListener
Parameters:
subscription - Ending subscription.