|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgnu.cajo.utils.extra.Queue
public class Queue
This class is a cajo-based implementation of the message communication paradigm. One or more producer objects can invoke methods on this object, and the invocations will be asynchronously performed on one (point to point), or more (publish/subscribe), consumer objects. A producer, by virtue of having its method invocation return immediately and successfully, can be certain its invocation has been enqueued, and will be invoked on the member consumers (if any). The consumers can be either local or remote objects.
A producer enqueues its invocations for the member consumers, by invoking the corresponding method on its reference to an instance of this object. Its argument(s), if any, will be invoked on the matching method of each of the consumer objects, in a separate thread. This creates a dynamic buffer of invocations.
Due to the asynchronous disconnection between the producer and consumer(s), no results can be returned from the method invocations. If a producer wishes to receive data from each of the consumers, it could provide a callback reference as one of the arguments, for example.
Interactions between producers and consumers can be as simple as a single method taking no arguments - notification, to a method taking a single argument - messaging, to multiple methods taking multiple arguments - remote procedure calls.
Finally, this class is serialisable, to allow passing of Queue objects between machines, and replication of Queue objects, the possibilities this creates require a bit of thought indeed...
Field Summary | |
---|---|
protected java.util.LinkedList |
consumers
The list of consumers, remote and local, to receive producer invocations. |
protected java.util.LinkedList |
invocations
The list of all pending producer method invocations. |
protected java.lang.Thread |
thread
This is the thread performing the asynchronous invocation operation, invoking the corresponding method on consumer objects. |
protected java.lang.Object |
topic
Some manner of commonly agreed upon descriptor for the subject matter about which the producers and consumers are interested. |
Constructor Summary | |
---|---|
Queue(java.lang.Object topic)
The constructor simply assigns the topic for the object and returns, as the object is entirely event driven. |
Method Summary | |
---|---|
void |
dequeue(java.lang.Object consumer)
This method is used to remove a consumer from the list. |
void |
enqueue(java.lang.Object consumer)
This method is used to add an object to list of consumers awaiting producer invocation. |
java.lang.Object |
invoke(java.lang.String method,
java.lang.Object args)
This is the method a producer, local or remote, would invoke, to be performed in a message-based fashion, asynchronously, on all registered consumers. |
static void |
main(java.lang.String[] args)
This method will start up a remotely accessible Queue object, in its own JVM. |
void |
pause()
This method is called to suspend method invocation dispatching. |
void |
resume()
This method is called to resume method invocation dispatching. |
java.lang.Object |
topic()
This method is used to request the topic of the producer/consumer community. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected final java.lang.Object topic
protected java.util.LinkedList invocations
protected java.util.LinkedList consumers
protected transient java.lang.Thread thread
Constructor Detail |
---|
public Queue(java.lang.Object topic)
topic
- A descriptor object, mutually agreed upon by all participantsMethod Detail |
---|
public java.lang.Object topic()
public void enqueue(java.lang.Object consumer)
consumer
- The object wishing to subscribepublic void dequeue(java.lang.Object consumer)
consumer
- The object wishing to unsubscribepublic void pause()
public void resume()
public java.lang.Object invoke(java.lang.String method, java.lang.Object args)
Note: normally invocation of the methods topic, enque, and deque will not be passed along to consumers, as they are performed on the Queue instance. However, invoking topic with any arguments, and enqueue or dequeue with no arguments, these will be passed on to consumers, as they do not apply to the Queue instance.
invoke
in interface Invoke
method
- The public method name on the consumer objects to be
invokedargs
- The argument(s) to invoke on the consumer object's method,
there can be none, to simply perform notification, there can be a single
argument to provide data, or there can be a collection to engage a
behaviour, presumably, the subscribed object has a matching public method
signature.
java.rmi.RemoteException
- If the invocation failed to enqueue,
due to a network related errorpublic static void main(java.lang.String[] args) throws java.lang.Exception
args
- The first string, if defined, will be the topic string,
undefined it will be "void", the second, if defined, will be the TCP port
number on which the queue will accept invocations, undefined it will be
1198, it can be zero, to use an anonymous port
java.lang.Exception
- For startup or machine/network configuration issues
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |