|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjaxcent.JaxcentTopic
JaxcentTopic provides a simple publish-and-subscribe model for a single server, using Java synchronization primitives. The items are not persistent, and do not survive application server or host restart. See ChatSample2.java for an example of using this model.
To extend this model for clusters, add a special listener that sends messages over a socket (or other mechanism) to other machines in the cluster, where they get posted to another JaxcentTopic object.
To extend this model to have persistent items, add a special listener that saves all items in a database. At system startup, retrieve messages from database and post them.
For complex requirements, a full fledged publish-and-subscribe model should be used instead of this simple one.
Constructor Summary | |
JaxcentTopic(int maxItems,
long maxAge)
Create a new topic. |
Method Summary | |
JaxcentTopicItem |
getItem(JaxcentTopicItem lastItem)
Get the next item from the topic, waiting until an item becomes available. |
JaxcentTopicItem |
getItem(JaxcentTopicItem lastItem,
long timeout)
Get the next item from the topic. |
void |
postItem(java.lang.Object newItem)
Post an item to the topic. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public JaxcentTopic(int maxItems, long maxAge)
maxItems specifies the maximum number of items to keep in topic. If 0 or negative, items are not removed by count.
maxAge specifies the maximum age of items in milliseconds. If 0 or negative, items are not removed by age.
Both maxItems and maxAge must not be zero, otherwise the topic will grow without bounds!
Method Detail |
public void postItem(java.lang.Object newItem)
public JaxcentTopicItem getItem(JaxcentTopicItem lastItem, long timeout) throws java.lang.InterruptedException
The first time through, lastItem should be null. After that, it must be the last item returned.
If using this form, you cannot use the syntax "item = getItem( item, timeout );", because that will set the item to null upon timeouts. The last non-null item returned, needs to be preserved!
java.lang.InterruptedException
public JaxcentTopicItem getItem(JaxcentTopicItem lastItem) throws java.lang.InterruptedException
The first time through, lastItem should be null. After that, it must be the last item returned.
java.lang.InterruptedException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |