org.jlab.coda.cMsg
Class cMsgSubscription

java.lang.Object
  extended by org.jlab.coda.cMsg.cMsgSubscription

public class cMsgSubscription
extends java.lang.Object

Class to store a client's subscription to a particular message subject and type. Used by both the cMsg domain API and cMsg subdomain handler objects. Once the domain server object is created, the only set method called is setNamespace. Thus, this object is for all intents and purposes immutable during its lifetime.

Version:
1.0
Author:
Carl Timmer

Constructor Summary
cMsgSubscription(java.lang.String subject, java.lang.String type, int id, cMsgCallbackThread cbThread)
          Constructor used by cMsg domain API.
cMsgSubscription(java.lang.String subject, java.lang.String type, java.lang.String namespace)
          Constructor used by cMsg subdomain handler.
 
Method Summary
 void addCallback(cMsgCallbackThread cbThread)
          Method to add a callback thread.
 boolean addClientSubscriber(cMsgClientInfo client)
          Adds a client to the set containing only regular clients subscribed to this subject, type, and namespace.
 void addNotifier(cMsgNotifier notifier)
          Add a notifier object to the set of objects used to notify servers that their subscribeAndGet is complete.
 void addSubAndGetter(cMsgClientInfo client)
          Adds a client to the hashmap containing all regular clients who have called cMsg.subscribeAndGet(java.lang.String, java.lang.String, int).
 boolean addSubscriber(cMsgClientInfo client)
          Adds a client to the set containing all clients (regular and bridge) subscribed to this subject, type, and namespace.
 boolean areWildCardsInSub()
          Returns true if there are * or ? characters in subject.
 boolean areWildCardsInType()
          Returns true if there are * or ? characters in type.
 void clearNotifiers()
          Clear all notifier objects from the set of objects used to notify servers that their subscribeAndGet is complete.
 void clearSubAndGetters()
          Clears the hashmap containing all regular clients who have called cMsg.subscribeAndGet(java.lang.String, java.lang.String, int).
 boolean containsSubscriber(cMsgClientInfo client)
          Is this a subscription of the given client (regular or bridge)? Used only on the server side.
 java.util.HashSet<cMsgClientInfo> getAllSubscribers()
          Gets the set containing all clients (regular and bridge) subscribed to this subject, type, and namespace.
 java.util.HashSet<cMsgCallbackThread> getCallbacks()
          Gets the hashset storing callback threads.
 java.util.HashSet<cMsgClientInfo> getClientSubscribers()
          Gets the set containing only regular clients subscribed to this subject, type, and namespace.
 int getId()
          Gets the id which client generates (receiverSubscribeId).
 java.lang.String getNamespace()
          Gets the namespace in the cMsg subdomain in which this subscription resides.
 java.util.Set<cMsgNotifier> getNotifiers()
          Gets the set of objects used to notify servers that their subscribeAndGet is complete.
 java.util.HashMap<cMsgClientInfo,java.lang.Integer> getSubAndGetters()
          Gets the hashmap containing all regular clients who have called cMsg.subscribeAndGet(java.lang.String, java.lang.String, int) with this subject, type, and namespace.
 java.lang.String getSubject()
          Gets subject subscribed to.
 java.util.regex.Pattern getSubjectPattern()
          Gets subject turned into compiled regular expression pattern.
 java.lang.String getSubjectRegexp()
          Gets subject turned into regular expression that understands * and ?.
 java.lang.String getType()
          Gets type subscribed to.
 java.util.regex.Pattern getTypePattern()
          Gets type turned into compiled regular expression pattern.
 java.lang.String getTypeRegexp()
          Gets type turned into regular expression that understands * and ?.
 int numberOfCallbacks()
          Method to return the number of callback threads registered.
 int numberOfSubscribers()
          Returns the total number of subscribers and subscribeAndGet callers subscribed to this subject, type, and namespace.
 void printSizes()
          This method prints the sizes of all sets and maps.
 void removeCallback(cMsgCallbackThread cbThread)
          Method to remove a callback thread.
 boolean removeClientSubscriber(cMsgClientInfo client)
          Removes a client from the set containing only regular clients subscribed to this subject, type, and namespace.
 void removeNotifier(cMsgNotifier notifier)
          Remove a notifier object from the set of objects used to notify servers that their subscribeAndGet is complete.
 void removeSubAndGetter(cMsgClientInfo client)
          Removes a client from the hashmap containing all regular clients who have called cMsg.subscribeAndGet(java.lang.String, java.lang.String, int).
 boolean removeSubscriber(cMsgClientInfo client)
          Removes a client from the set containing all clients (regular and bridge) subscribed to this subject, type, and namespace.
 void setId(int id)
          Sets the id which client generates (receiverSubscribeId).
 void setNamespace(java.lang.String namespace)
          Sets the namespace in the cMsg subdomain in which this subscription resides.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

cMsgSubscription

public cMsgSubscription(java.lang.String subject,
                        java.lang.String type,
                        java.lang.String namespace)
Constructor used by cMsg subdomain handler.

Parameters:
subject - subscription subject
type - subscription type
namespace - namespace subscription exists in

cMsgSubscription

public cMsgSubscription(java.lang.String subject,
                        java.lang.String type,
                        int id,
                        cMsgCallbackThread cbThread)
Constructor used by cMsg domain API.

Parameters:
subject - subscription subject
type - subscription type
id - unique id referring to subject and type combination
cbThread - object containing callback, its argument, and the thread to run it
Method Detail

printSizes

public void printSizes()
This method prints the sizes of all sets and maps.


areWildCardsInSub

public boolean areWildCardsInSub()
Returns true if there are * or ? characters in subject.

Returns:
true if there are * or ? characters in subject.

areWildCardsInType

public boolean areWildCardsInType()
Returns true if there are * or ? characters in type.

Returns:
true if there are * or ? characters in type.

getSubject

public java.lang.String getSubject()
Gets subject subscribed to.

Returns:
subject subscribed to

getSubjectRegexp

public java.lang.String getSubjectRegexp()
Gets subject turned into regular expression that understands * and ?.

Returns:
subject subscribed to in regexp form

getSubjectPattern

public java.util.regex.Pattern getSubjectPattern()
Gets subject turned into compiled regular expression pattern.

Returns:
subject subscribed to in compiled regexp form

getType

public java.lang.String getType()
Gets type subscribed to.

Returns:
type subscribed to

getTypeRegexp

public java.lang.String getTypeRegexp()
Gets type turned into regular expression that understands * and ?.

Returns:
type subscribed to in regexp form

getTypePattern

public java.util.regex.Pattern getTypePattern()
Gets type turned into compiled regular expression pattern.

Returns:
type subscribed to in compiled regexp form

getId

public int getId()
Gets the id which client generates (receiverSubscribeId).

Returns:
receiverSubscribeId

setId

public void setId(int id)
Sets the id which client generates (receiverSubscribeId).

Parameters:
id - id which client generates (receiverSubscribeId)

getNamespace

public java.lang.String getNamespace()
Gets the namespace in the cMsg subdomain in which this subscription resides.

Returns:
namespace subscription resides in

setNamespace

public void setNamespace(java.lang.String namespace)
Sets the namespace in the cMsg subdomain in which this subscription resides.

Parameters:
namespace - namespace subscription resides in

getCallbacks

public java.util.HashSet<cMsgCallbackThread> getCallbacks()
Gets the hashset storing callback threads.

Returns:
hashset storing callback threads

addCallback

public void addCallback(cMsgCallbackThread cbThread)
Method to add a callback thread.

Parameters:
cbThread - object containing callback thread, its argument, and the thread to run it

removeCallback

public void removeCallback(cMsgCallbackThread cbThread)
Method to remove a callback thread.

Parameters:
cbThread - object containing callback thread to be removed

numberOfCallbacks

public int numberOfCallbacks()
Method to return the number of callback threads registered.

Returns:
number of callback registered

getClientSubscribers

public java.util.HashSet<cMsgClientInfo> getClientSubscribers()
Gets the set containing only regular clients subscribed to this subject, type, and namespace. Used only on the server side.

Returns:
set containing only regular clients subscribed to this subject, type, and namespace

addClientSubscriber

public boolean addClientSubscriber(cMsgClientInfo client)
Adds a client to the set containing only regular clients subscribed to this subject, type, and namespace. Used only on the server side.

Parameters:
client - regular client to be added to subscription
Returns:
true if set did not already contain client, else false

removeClientSubscriber

public boolean removeClientSubscriber(cMsgClientInfo client)
Removes a client from the set containing only regular clients subscribed to this subject, type, and namespace. Used only on the server side.

Parameters:
client - regular client to be removed from subscription
Returns:
true if set contained client, else false

getAllSubscribers

public java.util.HashSet<cMsgClientInfo> getAllSubscribers()
Gets the set containing all clients (regular and bridge) subscribed to this subject, type, and namespace. Used only on the server side.

Returns:
set containing all clients (regular and bridge) subscribed to this subject, type, and namespace

containsSubscriber

public boolean containsSubscriber(cMsgClientInfo client)
Is this a subscription of the given client (regular or bridge)? Used only on the server side.

Parameters:
client - client
Returns:
true if this is a subscription of the given client, else false

addSubscriber

public boolean addSubscriber(cMsgClientInfo client)
Adds a client to the set containing all clients (regular and bridge) subscribed to this subject, type, and namespace. Used only on the server side.

Parameters:
client - client to be added to subscription
Returns:
true if set did not already contain client, else false

removeSubscriber

public boolean removeSubscriber(cMsgClientInfo client)
Removes a client from the set containing all clients (regular and bridge) subscribed to this subject, type, and namespace. Used only on the server side.

Parameters:
client - client to be removed from subscription
Returns:
true if set contained client, else false

getSubAndGetters

public java.util.HashMap<cMsgClientInfo,java.lang.Integer> getSubAndGetters()
Gets the hashmap containing all regular clients who have called cMsg.subscribeAndGet(java.lang.String, java.lang.String, int) with this subject, type, and namespace. A count is keep of how many times subscribeAndGet for a particular client has been called. The client info object is the key and count is the value. This is used on the server side.

Returns:
hashmap containing all regular clients who have called cMsg.subscribeAndGet(java.lang.String, java.lang.String, int)

addSubAndGetter

public void addSubAndGetter(cMsgClientInfo client)
Adds a client to the hashmap containing all regular clients who have called cMsg.subscribeAndGet(java.lang.String, java.lang.String, int). This is used on the server side.

Parameters:
client - client who called subscribeAndGet

clearSubAndGetters

public void clearSubAndGetters()
Clears the hashmap containing all regular clients who have called cMsg.subscribeAndGet(java.lang.String, java.lang.String, int). This is used on the server side.


removeSubAndGetter

public void removeSubAndGetter(cMsgClientInfo client)
Removes a client from the hashmap containing all regular clients who have called cMsg.subscribeAndGet(java.lang.String, java.lang.String, int). If the client has called subscribeAndGet more than once, it's entry in the table stays but it's count of active subscribeAndGet calls is decremented. This is used on the server side.

Parameters:
client - client who called subscribeAndGet

numberOfSubscribers

public int numberOfSubscribers()
Returns the total number of subscribers and subscribeAndGet callers subscribed to this subject, type, and namespace.

Returns:
the total number of subscribers and subscribeAndGet callers subscribed to this subject, type, and namespace

getNotifiers

public java.util.Set<cMsgNotifier> getNotifiers()
Gets the set of objects used to notify servers that their subscribeAndGet is complete.

Returns:
set of objects used to notify servers that their subscribeAndGet is complete

addNotifier

public void addNotifier(cMsgNotifier notifier)
Add a notifier object to the set of objects used to notify servers that their subscribeAndGet is complete.

Parameters:
notifier - notifier object

removeNotifier

public void removeNotifier(cMsgNotifier notifier)
Remove a notifier object from the set of objects used to notify servers that their subscribeAndGet is complete.

Parameters:
notifier - notifier object

clearNotifiers

public void clearNotifiers()
Clear all notifier objects from the set of objects used to notify servers that their subscribeAndGet is complete.