public class Queue extends Object implements Invoke
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...
| Modifier and Type | Field and Description |
|---|---|
protected LinkedList |
consumers
The list of consumers, remote and local, to receive producer invocations.
|
protected LinkedList |
invocations
The list of all pending producer method invocations.
|
protected Thread |
thread
This is the thread performing the asynchronous invocation operation,
invoking the corresponding method on consumer objects.
|
protected Object |
topic
Some manner of commonly agreed upon descriptor for the subject matter
about which the producers and consumers are interested.
|
| Constructor and Description |
|---|
Queue(Object topic)
The constructor simply assigns the topic for the object and returns, as
the object is entirely event driven.
|
| Modifier and Type | Method and Description |
|---|---|
void |
dequeue(Object consumer)
This method is used to remove a consumer from the list.
|
void |
enqueue(Object consumer)
This method is used to add an object to list of consumers awaiting
producer invocation.
|
Object |
invoke(String method,
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(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.
|
Object |
topic()
This method is used to request the topic of the producer/consumer
community.
|
protected final Object topic
protected LinkedList invocations
protected LinkedList consumers
protected transient Thread thread
public Queue(Object topic)
topic - A descriptor object, mutually agreed upon by all participantspublic Object topic()
public void enqueue(Object consumer)
consumer - The object wishing to subscribepublic void dequeue(Object consumer)
consumer - The object wishing to unsubscribepublic void pause()
public void resume()
public Object invoke(String method, 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 Invokemethod - 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.RemoteException - If the invocation failed to enqueue,
due to a network related errorpublic static void main(String[] args) throws 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 portException - For startup or machine/network configuration issuesCopyright © 2016. All Rights Reserved.