org.ws4d.java.eventing
Class DefaultEventSink

java.lang.Object
  extended by org.ws4d.java.eventing.DefaultEventSink
All Implemented Interfaces:
Bindable, EventSink

public class DefaultEventSink
extends java.lang.Object
implements EventSink

Class represents an endpoint to receive notifications.


Constructor Summary
DefaultEventSink(EventListener eventListener, DataStructure bindings)
          Constructor.
DefaultEventSink(EventListener eventListener, int configurationId)
           
 
Method Summary
 void addBinding(CommunicationBinding binding)
          Adds the given binding to this Bindable.
 void addSubscription(java.lang.String clientSubId, ClientSubscription subscription)
          Internal method used within the subscription process.
 void clearBindings()
          Removes all bindings from this Bindable instance.
 void close()
          Closes event receiving for this event endpoint.
 Iterator getBindings()
          Returns an iterator over all bindings assigned to this Bindable instance.
 EventListener getEventListener()
          Get associated event listener of this event sink.
 ClientSubscription getSubscription(java.lang.String clientSubId)
           
 boolean hasBindings()
          Returns true only if this Bindable instance has at least one binding assigned.
 boolean isOpen()
          Returns if event sink is open to receive notifications/ solicit responses.
 void open()
          Opens event receiving for this event endpoint.
 ParameterValue receiveLocalEvent(java.lang.String clientSubscriptionId, URI actionUri, ParameterValue outputParameter)
          Callback method for receiving local notifications/ solicit responses.
 boolean removeBinding(CommunicationBinding binding)
          Removes the specified binding from this Bindable instance.
 ClientSubscription removeSubscription(java.lang.String clientSubId)
           
 boolean supportsBindingChanges()
          Returns true, if it is safe to call one of the mutator methods ((Bindable.addBinding(CommunicationBinding), Bindable.removeBinding(CommunicationBinding), (Bindable.clearBindings(), etc.) at this time without getting an IllegalStateException.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultEventSink

public DefaultEventSink(EventListener eventListener,
                        DataStructure bindings)
Constructor.

Parameters:
eventListener - Client with which this event sink should be associated. Received events will be transmitted to the eventListener.
bindings - a data structure of CommunicationBinding instances over which to expose this event sink

DefaultEventSink

public DefaultEventSink(EventListener eventListener,
                        int configurationId)
Parameters:
eventListener -
configurationId -
Method Detail

hasBindings

public boolean hasBindings()
Description copied from interface: Bindable
Returns true only if this Bindable instance has at least one binding assigned. Returns false, if it doesn't have any bindings.

Specified by:
hasBindings in interface Bindable
Returns:
whether there are any bindings assigned to that Bindable instance or not

getBindings

public Iterator getBindings()
Description copied from interface: Bindable
Returns an iterator over all bindings assigned to this Bindable instance. This iterator will have no next elements (rather than being ), if the Bindable doesn't have any bindings.

Specified by:
getBindings in interface Bindable
Returns:
an iterator over all available bindings

supportsBindingChanges

public boolean supportsBindingChanges()
Description copied from interface: Bindable
Returns true, if it is safe to call one of the mutator methods ((Bindable.addBinding(CommunicationBinding), Bindable.removeBinding(CommunicationBinding), (Bindable.clearBindings(), etc.) at this time without getting an IllegalStateException. Returns false otherwise.

Some implementations of this interface may not allow for bindings to be added or removed all the time, but rather only when the actual implementation is in a certain set of states (note that this set could be empty or contain solely a single set). By calling this method and observing its return value it is possible for a client to determine whether this Bindable supports changes within its current state.

Specified by:
supportsBindingChanges in interface Bindable
Returns:
true if this Bindable instance may be modified at the moment without throwing IllegalStateExceptions, false otherwise
See Also:
Bindable.addBinding(CommunicationBinding), Bindable.removeBinding(CommunicationBinding), Bindable.clearBindings()

addBinding

public void addBinding(CommunicationBinding binding)
                throws WS4DIllegalStateException
Description copied from interface: Bindable
Adds the given binding to this Bindable. Does nothing if the Bindable already contains the binding.

Specified by:
addBinding in interface Bindable
Parameters:
binding - the binding to add
Throws:
WS4DIllegalStateException - in case this Bindable doesn't currently support modifications (see Bindable.supportsBindingChanges())

removeBinding

public boolean removeBinding(CommunicationBinding binding)
                      throws WS4DIllegalStateException
Description copied from interface: Bindable
Removes the specified binding from this Bindable instance. Does nothing, if the Bindable doesn't contain the given binding. Returns true if the binding was removed and false if it didn't exist.

Specified by:
removeBinding in interface Bindable
Parameters:
binding - the binding to remove
Returns:
true if this Bindable instance had the given binding assigned and it was removed successfully, false otherwise
Throws:
WS4DIllegalStateException - in case this Bindable doesn't currently support modifications (see Bindable.supportsBindingChanges())

clearBindings

public void clearBindings()
                   throws WS4DIllegalStateException
Description copied from interface: Bindable
Removes all bindings from this Bindable instance. Does nothing if there are no bindings assigned.

Specified by:
clearBindings in interface Bindable
Throws:
WS4DIllegalStateException - in case this Bindable doesn't support modifications at the current time (see Bindable.supportsBindingChanges())

open

public void open()
          throws EventingException
Opens event receiving for this event endpoint.

Specified by:
open in interface EventSink
Throws:
EventingException - in case opening this event sink fails for any reason (e.g. binding to a specified local address fails)

close

public void close()
Closes event receiving for this event endpoint.

Specified by:
close in interface EventSink

getEventListener

public EventListener getEventListener()
Description copied from interface: EventSink
Get associated event listener of this event sink.

Specified by:
getEventListener in interface EventSink
Returns:
EventListener associated with this event sink.

isOpen

public boolean isOpen()
Description copied from interface: EventSink
Returns if event sink is open to receive notifications/ solicit responses.

Specified by:
isOpen in interface EventSink
Returns:
true - if event sink is open to receive events/ solicit responses, else false.

getSubscription

public ClientSubscription getSubscription(java.lang.String clientSubId)
Specified by:
getSubscription in interface EventSink
Returns:
the client subscription with the given ID

removeSubscription

public ClientSubscription removeSubscription(java.lang.String clientSubId)
Parameters:
clientSubId -
Returns:
the removed client subscription

addSubscription

public void addSubscription(java.lang.String clientSubId,
                            ClientSubscription subscription)
Description copied from interface: EventSink
Internal method used within the subscription process.
Subscribing to an event is done by Service.subscribe(EventSink, String, org.ws4d.java.types.URISet, long) .

Specified by:
addSubscription in interface EventSink
Parameters:
clientSubId - client subscription id
subscription - client subscription

receiveLocalEvent

public ParameterValue receiveLocalEvent(java.lang.String clientSubscriptionId,
                                        URI actionUri,
                                        ParameterValue outputParameter)
Description copied from interface: EventSink
Callback method for receiving local notifications/ solicit responses.

Specified by:
receiveLocalEvent in interface EventSink
Parameters:
clientSubscriptionId -
actionUri -
outputParameter -
Returns:
a possible result to a solicit-response event