|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.ws4d.java.client.DefaultClient
public class DefaultClient
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 |
---|
public DefaultClient()
DPWSFramework.isRunning()
. Throws a
java.lang.RuntimeException
if this is not the case.
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
constructorMethod Detail |
---|
public DataStructure getAllDiscoveryBindings()
public EventSink getEventSink(DataStructure bindings)
EventListener
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.
getEventSink
in interface EventListener
bindings
- a data structure of CommunicationBinding
instances to expose the created event sink over
public EventSink generateEventSink(int configurationId)
CommunicationBinding
instance. This
CommunicationBinding
instance defines a local transport address,
to which incoming notifications will be delivered.
configurationId
- Configuration id of the properties of the event
sink to generate
public void deviceBye(DeviceReference deviceRef)
DeviceListener
deviceBye
in interface DeviceListener
deviceRef
- a reference to the device that caused the notificationpublic void deviceCompletelyDiscovered(DeviceReference deviceRef)
DeviceListener
deviceCompletelyDiscovered
in interface DeviceListener
deviceRef
- a reference to the device that caused the notificationpublic void deviceChanged(DeviceReference deviceRef)
DeviceListener
deviceChanged
in interface DeviceListener
deviceRef
- a reference to the device that caused the notificationpublic void deviceRunning(DeviceReference deviceRef)
DeviceListener
deviceRunning
in interface DeviceListener
deviceRef
- a reference to the device that caused the notificationpublic void deviceBuiltUp(DeviceReference deviceRef, Device device)
DeviceListener
DeviceReference
was
created.
deviceBuiltUp
in interface DeviceListener
deviceRef
- a reference to the device that caused the notificationdevice
- the proxy device just built uppublic void deviceCommunicationErrorOrReset(DeviceReference deviceRef)
DeviceListener
DeviceReference
has failed or the reference was reset.
deviceCommunicationErrorOrReset
in interface DeviceListener
deviceRef
- a reference to the device that caused the notificationpublic void serviceChanged(ServiceReference serviceRef, Service service)
ServiceListener
ServiceReference
has been
changed.
serviceChanged
in interface ServiceListener
serviceRef
- a reference to the service that caused the notificationpublic void serviceCreated(ServiceReference serviceRef, Service service)
ServiceListener
ServiceReference
was
created.
serviceCreated
in interface ServiceListener
serviceRef
- a reference to the service that caused the notification
qpram service the service that just have changedpublic void serviceDisposed(ServiceReference serviceRef)
ServiceListener
ServiceReference
was
disposed of.
serviceDisposed
in interface ServiceListener
serviceRef
- a reference to the service that caused the notificationpublic void registerServiceListening()
ServiceListener
public void unregisterServiceListening()
ServiceListener
public DeviceReference getDeviceReference(EndpointReference deviceEpr, DiscoveryBinding binding)
Client
instance will be used as callback for device changes
of the corresponding device.
deviceEpr
- endpoint reference of device to get device reference for
SearchManager#getDeviceReference(EndpointReference, DeviceListener)
public DeviceReference getDeviceReference(EndpointReference deviceEpr)
public DeviceReference getDeviceReference(HelloData helloData)
Client
instance will be used as callback for device changes
of the corresponding device.
helloData
- Hello data received from
helloReceived(HelloData)
callback method.
SearchManager.getDeviceReference(HelloData, DeviceListener)
public ServiceReference getServiceReference(EndpointReference serviceEpr, java.lang.String comManId)
serviceEpr
- endpoint reference of service to get service reference
forcomManId
- ID of the communication manager to use when interacting
with supplied endpoint reference
SearchManager#getServiceReference(EndpointReference)
public void searchDevice(SearchParameter search)
deviceFound(DeviceReference, SearchParameter)
method.
search
- search criteriaSearchManager.searchDevice(SearchParameter, SearchCallback,
DeviceListener)
public void searchService(SearchParameter search)
serviceFound(ServiceReference, SearchParameter)
method.
search
- search parameter to specify the search for device and
serviceSearchManager.searchService(SearchParameter, SearchCallback)
public void registerHelloListening()
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.
public void registerHelloListening(SearchParameter search)
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.
search
- containing the types and scopes.public void registerHelloListening(DiscoveryBinding binding)
helloReceived(HelloData)
is called to deliver the hello data.
The client will be used as receiver for the incoming Hello messages.
binding
- the binding for the listener.public void registerHelloListening(SearchParameter search, DiscoveryBinding binding)
SearchParameter
).
helloReceived(HelloData)
is called to deliver the hello data.
The client will be used as receiver for the incoming Hello messages.
search
- containing the types and scopes.binding
- the binding for the listener.public void registerHelloListening(SearchParameter search, DiscoveryBinding binding, HelloListener helloListener)
SearchParameter
).
helloReceived(HelloData)
is called to deliver the hello data.
search
- containing the types and scopes.binding
- the binding for the listener.helloListener
- the listener to receive the hello data from matching
hello messages.public void unregisterHelloListening(DiscoveryBinding binding)
DiscoveryBinding
.
binding
- the binding for the listener.public void unregisterHelloListening(SearchParameter search)
SearchParameter
and ALL DiscoveryBinding
found.
search
- containing the types and scopes.public void unregisterHelloListening(SearchParameter search, DiscoveryBinding binding)
SearchParameter
and DiscoveryBinding
.
search
- containing the types and scopes.binding
- the binding for the listener.public void helloReceived(HelloData helloData)
HelloListener
helloReceived
in interface HelloListener
helloData
- public void deviceFound(DeviceReference devRef, SearchParameter search)
SearchCallback
search
) has been
found.
deviceFound
in interface SearchCallback
devRef
- a reference to the matching devicesearch
- the collection of criteria the search was initiated withpublic void serviceFound(ServiceReference servRef, SearchParameter search)
SearchCallback
search
) has been
found.
serviceFound
in interface SearchCallback
servRef
- a reference to the matching servicesearch
- the list of criteria the search was initiated withpublic ParameterValue eventReceived(ClientSubscription subscription, URI actionURI, ParameterValue parameterValue)
EventListener
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.
eventReceived
in interface EventListener
subscription
- this is the subscription because of which the event
was receivedactionURI
- URI of the subscribed actionparameterValue
- parameter value of notification message containing
the user data
public void subscriptionEndReceived(ClientSubscription subscription, URI reason)
EventListener
subscriptionEndReceived
in interface EventListener
subscription
- subscription ended.reason
- Reason why the subscription ends unexpectedlypublic void subscriptionTimeoutReceived(ClientSubscription subscription)
EventListener
subscriptionTimeoutReceived
in interface EventListener
subscription
- Ending subscription.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |