com.inspirel.yami
Class ValuePublisher

java.lang.Object
  extended by com.inspirel.yami.ValuePublisher

public class ValuePublisher
extends java.lang.Object

Simple subscription publisher. The subscription publisher that notifies remote listeners with published value updates. Remote listeners can subscribe and unsubscribe at any time.


Nested Class Summary
static class ValuePublisher.SubscriberInfo
          Helper class for holding destination target and object for any given subscriber.
 
Constructor Summary
ValuePublisher()
          Constructor.
ValuePublisher(IncomingMessageCallback callback)
          Constructor.
ValuePublisher(IncomingMessageCallback callback, int maxQueueLength, ValuePublisherOverflowCallback overflowCallback)
          Constructor.
 
Method Summary
 void close()
          Unregisters from the controlling agent and cleans up resources.
 int getNumberOfSubscribers()
          Returns the number of current subscribes.
 java.util.List<ValuePublisher.SubscriberInfo> getSubscribers()
          Returns the list of current subscribers.
 void publish(Parameters value)
          Publishe the new value with default priority.
 void publish(YAMISerializable value, int priority)
          Publishe the new value.
 void subscribe(java.lang.String destinationTarget, java.lang.String destinationObject)
          Subscribe new listener.
 void unsubscribe(java.lang.String destinationTarget)
          Unsubscribe the given listener.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ValuePublisher

public ValuePublisher()
Constructor. Creates the subscription publisher that is not registered at any agent. The new publisher will use queues of length 1 for each subscriber.


ValuePublisher

public ValuePublisher(IncomingMessageCallback callback)
Constructor.

Creates the subscription publisher that is not registered at any agent and that delegates arbitrary remote commands to the given callback. The new publisher will use queues of length 1 for each subscriber.

Note: The "subscribe" and "unsubscribe" messages are also forwarded to the user-provided callback, but these two messages are already processed by the published value's implementation.

Parameters:
callback - the callback implementation for unknown commands

ValuePublisher

public ValuePublisher(IncomingMessageCallback callback,
                      int maxQueueLength,
                      ValuePublisherOverflowCallback overflowCallback)
Constructor.

Creates the subscription publisher that is not registered at any agent and that delegates arbitrary remote commands to the given callback as well as reports queue overflow conditions.

Note: The "subscribe" and "unsubscribe" messages are also forwarded to the user-provided callback, but these two messages are already "replied-to" by the published value's implementation.

Parameters:
callback - the callback implementation for unknown commands
maxQueueLength - length of message queue for each subscriber
overflowCallback - the callback implementation for overflow condition
Method Detail

subscribe

public void subscribe(java.lang.String destinationTarget,
                      java.lang.String destinationObject)
               throws YAMIIOException
Subscribe new listener. This function is usually called internally as a result of processing the remote "subscribe" message, but can be also used locally if the listener's location is obtained via other means.

Parameters:
destinationTarget - target of the remote listener
destinationObject - name of the remote listener's object
Throws:
YAMIIOException - if the connection to the destination cannot be established

unsubscribe

public void unsubscribe(java.lang.String destinationTarget)
Unsubscribe the given listener.

Parameters:
destinationTarget - target of the remote listener

publish

public void publish(Parameters value)
Publishe the new value with default priority.

Parameters:
value - new value that is to be sent as update to all listeners

publish

public void publish(YAMISerializable value,
                    int priority)
Publishe the new value. Sends the update message to all active listeners with the given value. In case of any errors or communication problems, the problematic listener is automatically unsubscribed.

Parameters:
value - new value that is to be sent as update to all listeners
priority - priority of the update message

getNumberOfSubscribers

public int getNumberOfSubscribers()
Returns the number of current subscribes.

Returns:
number of current subscribers

getSubscribers

public java.util.List<ValuePublisher.SubscriberInfo> getSubscribers()
Returns the list of current subscribers.

Returns:
list of subscriber info objects, one for each subscriber

close

public void close()
Unregisters from the controlling agent and cleans up resources.