org.objectweb.joram.mom.proxies
Class ClientSubscription

java.lang.Object
  extended by org.objectweb.joram.mom.proxies.ClientSubscription
All Implemented Interfaces:
java.io.Serializable, ClientSubscriptionMBean

 class ClientSubscription
extends java.lang.Object
implements ClientSubscriptionMBean, java.io.Serializable

The ClientSubscription class holds the data of a client subscription, and the methods managing the delivery and acknowledgement of the messages.


Field Summary
private  boolean active
          true if the subscription is active.
private  int contextId
          Identifier of the subscription context.
private  java.util.Map deliveredIds
          Table of delivered messages identifiers.
private  java.util.Map deniedMsgs
          Table keeping the denied messages identifiers.
private  AgentId dmqId
          Identifier of the subscriber's dead message queue, null for DMQ not set.
private  boolean durable
          true if the subscription is durable.
static org.objectweb.util.monolog.api.Logger logger
           
private  java.util.List messageIds
          Vector of identifiers of the messages to deliver.
private  java.util.Map messagesTable
          Proxy messages table.
private  java.lang.String name
          The subscription name.
protected  int nbMaxMsg
          Max number of Message stored in the queue (-1 no limit).
protected  long nbMsgsDeliveredSinceCreation
          the number of delivered messages
protected  long nbMsgsSentToDMQSinceCreation
          the number of erroneous messages forwarded to the DMQ
private  boolean noFiltering
          true if the subscription does not filter messages in any way.
private  boolean noLocal
          true if the subscriber does not wish to consume messages published in the same context.
private  ProxyAgentItf proxy
           
private  AgentId proxyId
          The proxy's agent identifier.
private  long requestExpTime
          Expiration time of the "receive" request, if any.
private  int requestId
          Identifier of the request requesting messages, either the listener's request, or a "receive" request.
private  java.lang.String selector
          The selector for filtering messages.
private static long serialVersionUID
          define serialVersionUID for interoperability
private  int subRequestId
          Identifier of the subscription request.
private  int threshold
          Threshold above which messages are considered as undeliverable because constantly denied. 0 stands for no threshold, -1 for value not set (use servers' default value).
private  boolean toListener
          true if the messages are destinated to a listener.
private  AgentId topicId
          The topic identifier.
 
Constructor Summary
ClientSubscription(AgentId proxyId, int contextId, int reqId, boolean durable, AgentId topicId, java.lang.String name, java.lang.String selector, boolean noLocal, AgentId dmqId, int threshold, int nbMaxMsg, java.util.Map messagesTable)
          Constructs a ClientSubscription instance.
 
Method Summary
(package private)  void acknowledge(java.util.Iterator acks)
          Acknowledges messages.
(package private)  void acknowledge(java.lang.String id)
           
(package private)  void browseNewMessages(java.util.List newMessages)
          Browses messages and keeps those which will have to be delivered to the subscriber.
(package private)  void cleanMessageIds()
           
 void clear()
          Deletes all messages
(package private)  void deactivate()
          De-activates the subscription, denies the non acknowledged messages.
private  void decrAckCounters(java.lang.String msgId, Message message)
           
(package private)  void delete()
          Decreases the subscription's messages acknowledgement expectations, deletes those not to be consumed anymore.
 void deleteMessage(java.lang.String msgId)
          Deletes a particular pending message in the subscription.
(package private)  ConsumerMessages deliver()
          Launches a delivery sequence, either for a listener, or for a receiver.
(package private)  void deny(java.util.Iterator denies)
          Denies messages.
private  void deny(java.util.Iterator denies, boolean remove)
          Denies the messages.
 boolean getActive()
          Returns true if the subscription is active.
 int getContextId()
          Returns the subscription's context identifier.
 boolean getDurable()
          Returns true if the subscription is durable.
 javax.management.openmbean.CompositeData getMessage(java.lang.String msgId)
          Returns the description of a particular pending message.
 java.lang.String[] getMessageIds()
          Returns the list of message's identifiers for the subscription.
 javax.management.openmbean.TabularData getMessages()
          Returns the description of all pending messages.
 java.util.List getMessagesView()
          Returns the description of all pending messages.
 java.lang.String getName()
          Returns the name of the subscription.
 int getNbMaxMsg()
          Returns the maximum number of message for the subscription.
 long getNbMsgsDeliveredSinceCreation()
          Returns the number of messages delivered to the client since creation time of this subscription.
 long getNbMsgsSentToDMQSinceCreation()
          Returns the number of erroneous messages forwarded to the DMQ since creation time of this subscription.
 int getPendingMessageCount()
          Returns the number of pending messages for the subscription.
 java.lang.String getSelector()
          Returns the selector.
 int getSubRequestId()
          Returns the identifier of the subscribing request.
(package private)  Message getSubscriptionMessage(java.lang.String msgId)
           
 AgentId getTopicId()
          Returns the identifier of the subscription topic.
 java.lang.String getTopicIdAsString()
          Returns the identifier of the subscription topic.
private  boolean isUndeliverable(int deliveryAttempts)
          Returns true if a given message is considered as undeliverable, because its delivery count matches the subscription's threshold, if any, or the server's default threshold value (if any).
(package private)  void reactivate(int contextId, int reqId, AgentId topicId, java.lang.String selector, boolean noLocal)
          Reactivates the subscription.
 void readBag(java.io.ObjectInputStream in)
           
(package private)  void reinitialize(java.util.Map messagesTable, java.util.List persistedMessages, boolean denyDeliveredMessages)
          Re-initializes the client subscription.
(package private)  Message removeMessage(java.lang.String msgId)
          Removes a particular pending message in the subscription.
private  void save()
           
(package private)  void setActive(boolean active)
           
(package private)  void setDMQId(AgentId dmqId)
          Sets the subscription's dead message queue identifier.
(package private)  void setListener(int requestId)
          Sets a listener.
 void setNbMaxMsg(int nbMaxMsg)
          Sets the maximum number of message for the subscription.
(package private)  void setProxyAgent(ProxyAgentItf px)
           
(package private)  void setReceiver(int requestId, long timeToLive)
          Sets a receiver request.
(package private)  void setThreshold(int threshold)
          Sets the subscription's threshold value.
 java.lang.String toString()
           
(package private)  void unsetListener()
          Unsets the listener.
(package private)  void unsetReceiver()
          Unsets a receiver request.
 void writeBag(java.io.ObjectOutputStream out)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
define serialVersionUID for interoperability

See Also:
Constant Field Values

logger

public static org.objectweb.util.monolog.api.Logger logger

proxyId

private AgentId proxyId
The proxy's agent identifier.


durable

private boolean durable
true if the subscription is durable.


topicId

private AgentId topicId
The topic identifier.


name

private java.lang.String name
The subscription name.


selector

private java.lang.String selector
The selector for filtering messages.


dmqId

private AgentId dmqId
Identifier of the subscriber's dead message queue, null for DMQ not set.


threshold

private int threshold
Threshold above which messages are considered as undeliverable because constantly denied. 0 stands for no threshold, -1 for value not set (use servers' default value).


nbMaxMsg

protected int nbMaxMsg
Max number of Message stored in the queue (-1 no limit).


messageIds

private java.util.List messageIds
Vector of identifiers of the messages to deliver.


deliveredIds

private java.util.Map deliveredIds
Table of delivered messages identifiers.


deniedMsgs

private java.util.Map deniedMsgs
Table keeping the denied messages identifiers.


contextId

private transient int contextId
Identifier of the subscription context.


subRequestId

private transient int subRequestId
Identifier of the subscription request.


noLocal

private transient boolean noLocal
true if the subscriber does not wish to consume messages published in the same context.


noFiltering

private transient boolean noFiltering
true if the subscription does not filter messages in any way.


active

private transient boolean active
true if the subscription is active.


requestId

private transient int requestId
Identifier of the request requesting messages, either the listener's request, or a "receive" request.


toListener

private transient boolean toListener
true if the messages are destinated to a listener.


requestExpTime

private transient long requestExpTime
Expiration time of the "receive" request, if any.


messagesTable

private transient java.util.Map messagesTable
Proxy messages table. Be careful: currently this table is shared between all subscription.


proxy

private transient ProxyAgentItf proxy

nbMsgsSentToDMQSinceCreation

protected long nbMsgsSentToDMQSinceCreation
the number of erroneous messages forwarded to the DMQ


nbMsgsDeliveredSinceCreation

protected long nbMsgsDeliveredSinceCreation
the number of delivered messages

Constructor Detail

ClientSubscription

ClientSubscription(AgentId proxyId,
                   int contextId,
                   int reqId,
                   boolean durable,
                   AgentId topicId,
                   java.lang.String name,
                   java.lang.String selector,
                   boolean noLocal,
                   AgentId dmqId,
                   int threshold,
                   int nbMaxMsg,
                   java.util.Map messagesTable)
Constructs a ClientSubscription instance.

Parameters:
proxyId - Proxy's identifier.
contextId - Context identifier.
reqId - Request identifier.
durable - true for a durable subscription.
topicId - Topic identifier.
name - Subscription's name.
selector - Selector for filtering messages.
noLocal - true for not consuming messages published within the same proxy's context.
dmqId - Identifier of the proxy's dead message queue, if any.
threshold - Proxy's threshold value, if any.
messagesTable - Proxy's messages table.
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getContextId

public int getContextId()
Returns the subscription's context identifier.

Specified by:
getContextId in interface ClientSubscriptionMBean

getSubRequestId

public int getSubRequestId()
Returns the identifier of the subscribing request.

Specified by:
getSubRequestId in interface ClientSubscriptionMBean

getName

public java.lang.String getName()
Returns the name of the subscription.

Specified by:
getName in interface ClientSubscriptionMBean

getTopicId

public AgentId getTopicId()
Returns the identifier of the subscription topic.


getTopicIdAsString

public java.lang.String getTopicIdAsString()
Returns the identifier of the subscription topic.

Specified by:
getTopicIdAsString in interface ClientSubscriptionMBean

getSelector

public java.lang.String getSelector()
Returns the selector.

Specified by:
getSelector in interface ClientSubscriptionMBean

getDurable

public boolean getDurable()
Returns true if the subscription is durable.

Specified by:
getDurable in interface ClientSubscriptionMBean

getActive

public boolean getActive()
Returns true if the subscription is active.

Specified by:
getActive in interface ClientSubscriptionMBean

getNbMaxMsg

public int getNbMaxMsg()
Returns the maximum number of message for the subscription. If the limit is unset the method returns -1.

Specified by:
getNbMaxMsg in interface ClientSubscriptionMBean
Returns:
the maximum number of message for subscription if set; -1 otherwise.

setNbMaxMsg

public void setNbMaxMsg(int nbMaxMsg)
Sets the maximum number of message for the subscription.

Specified by:
setNbMaxMsg in interface ClientSubscriptionMBean
Parameters:
nbMaxMsg - the maximum number of message for subscription (-1 set no limit).

getPendingMessageCount

public int getPendingMessageCount()
Returns the number of pending messages for the subscription.

Specified by:
getPendingMessageCount in interface ClientSubscriptionMBean
Returns:
The number of pending message for the subscription.

getMessageIds

public java.lang.String[] getMessageIds()
Returns the list of message's identifiers for the subscription.

Specified by:
getMessageIds in interface ClientSubscriptionMBean
Returns:
the list of message's identifiers for the subscription.

setProxyAgent

void setProxyAgent(ProxyAgentItf px)

reinitialize

void reinitialize(java.util.Map messagesTable,
                  java.util.List persistedMessages,
                  boolean denyDeliveredMessages)
Re-initializes the client subscription.

Parameters:
messagesTable - Proxy's table where storing the messages.
persistedMessages - Proxy's persisted messages.
denyDeliveredMessages - Denies already delivered messages.

reactivate

void reactivate(int contextId,
                int reqId,
                AgentId topicId,
                java.lang.String selector,
                boolean noLocal)
Reactivates the subscription.

Parameters:
context - Re-activation context.
reqId - Re-activation request identifier.
topicId - Topic identifier.
selector - Selector for filtering messages.
noLocal - true for not consuming messages published within the same proxy's context.

deactivate

void deactivate()
De-activates the subscription, denies the non acknowledged messages.


setActive

void setActive(boolean active)

setListener

void setListener(int requestId)
Sets a listener.

Parameters:
requestId - Identifier of the listener request.

unsetListener

void unsetListener()
Unsets the listener.


setReceiver

void setReceiver(int requestId,
                 long timeToLive)
Sets a receiver request.

Parameters:
requestId - Identifier of the "receive" request.
timeToLive - Request's time to live value.

unsetReceiver

void unsetReceiver()
Unsets a receiver request.


setDMQId

void setDMQId(AgentId dmqId)
Sets the subscription's dead message queue identifier.


setThreshold

void setThreshold(int threshold)
Sets the subscription's threshold value.


browseNewMessages

void browseNewMessages(java.util.List newMessages)
Browses messages and keeps those which will have to be delivered to the subscriber.


deliver

ConsumerMessages deliver()
Launches a delivery sequence, either for a listener, or for a receiver.


acknowledge

void acknowledge(java.util.Iterator acks)
Acknowledges messages.


acknowledge

void acknowledge(java.lang.String id)

deny

void deny(java.util.Iterator denies)
Denies messages.


deny

private void deny(java.util.Iterator denies,
                  boolean remove)
Denies the messages.

Parameters:
denies - all ids of the messages to deny
remove - true to remove messages from deliveredIds map. Must be false when denies iterates over deliveredIds map keys, to avoid a ConcurrentModificationException.

delete

void delete()
Decreases the subscription's messages acknowledgement expectations, deletes those not to be consumed anymore.


isUndeliverable

private boolean isUndeliverable(int deliveryAttempts)
Returns true if a given message is considered as undeliverable, because its delivery count matches the subscription's threshold, if any, or the server's default threshold value (if any).


getNbMsgsSentToDMQSinceCreation

public long getNbMsgsSentToDMQSinceCreation()
Description copied from interface: ClientSubscriptionMBean
Returns the number of erroneous messages forwarded to the DMQ since creation time of this subscription.

Specified by:
getNbMsgsSentToDMQSinceCreation in interface ClientSubscriptionMBean
Returns:
the number of erroneous messages forwarded to the DMQ.

getNbMsgsDeliveredSinceCreation

public long getNbMsgsDeliveredSinceCreation()
Description copied from interface: ClientSubscriptionMBean
Returns the number of messages delivered to the client since creation time of this subscription.

Specified by:
getNbMsgsDeliveredSinceCreation in interface ClientSubscriptionMBean
Returns:
the number of delivered messages.

getSubscriptionMessage

Message getSubscriptionMessage(java.lang.String msgId)

getMessage

public javax.management.openmbean.CompositeData getMessage(java.lang.String msgId)
                                                    throws java.lang.Exception
Returns the description of a particular pending message. The message is pointed out through its unique identifier.

Specified by:
getMessage in interface ClientSubscriptionMBean
Parameters:
msgId - The unique message's identifier.
Returns:
the description of the message.
Throws:
java.lang.Exception
See Also:
MessageJMXWrapper

getMessages

public javax.management.openmbean.TabularData getMessages()
                                                   throws java.lang.Exception
Returns the description of all pending messages.

Specified by:
getMessages in interface ClientSubscriptionMBean
Returns:
the description of the message.
Throws:
java.lang.Exception
See Also:
MessageJMXWrapper

getMessagesView

public java.util.List getMessagesView()
Description copied from interface: ClientSubscriptionMBean
Returns the description of all pending messages.

Specified by:
getMessagesView in interface ClientSubscriptionMBean
Returns:
the description of the message.

deleteMessage

public void deleteMessage(java.lang.String msgId)
Description copied from interface: ClientSubscriptionMBean
Deletes a particular pending message in the subscription. The message is pointed out through its unique identifier.

Specified by:
deleteMessage in interface ClientSubscriptionMBean
Parameters:
msgId - The unique message's identifier.

clear

public void clear()
Description copied from interface: ClientSubscriptionMBean
Deletes all messages

Specified by:
clear in interface ClientSubscriptionMBean

removeMessage

Message removeMessage(java.lang.String msgId)
Removes a particular pending message in the subscription. The message is pointed out through its unique identifier.

Parameters:
msgId - The unique message's identifier.

decrAckCounters

private void decrAckCounters(java.lang.String msgId,
                             Message message)

save

private void save()

readBag

public void readBag(java.io.ObjectInputStream in)
             throws java.io.IOException,
                    java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException

writeBag

public void writeBag(java.io.ObjectOutputStream out)
              throws java.io.IOException
Throws:
java.io.IOException

cleanMessageIds

void cleanMessageIds()


Copyright © 2010 ScalAgent D.T.. All Rights Reserved.