MsgQueue is very liberal with security. Senders are responsible for identifying who they are (via an ID string), and the MsgQueue just trusts this implicitly. The user of the MsgQueue might want to be more careful with authentication if sender might lie. It is not really meant to be run in an environment in which agents could be devious or insincere.
Note that clients cannot read from the queue, only the "owner" (process which started the MsgQueue object).
Note: The MsgQueueObj class is synchronized, to prevent problems with concurrent access by multiple processes.
public void tell(String sender,String message);
See Client.java for an example. The sender string is a simple ID,
like "client1". From the perspective of "servers" (programs which use
MsgQueue objects), there are several additional functions for getting
messages out. The main ones are:
public Vector pop();
public Vector peek();
public boolean isEmpty();
Clearly, pop() takes off the next message (in FIFO order), and peek tells
you what it is without removing it from the queue. These two methods return
a Vector which is a 3-tuple consisting of: 1) the message (String), 2) the
ID of the sender (String), and 3) the timestamp (Date, a Java class). Here
is a visual representation:
pop/peek -> [String message,String sender,Date timestamp]
You can also dump messages, and use 'size()' to get the count. Of course,
you have to do the usual RMI things as a server, such as set the security
manager, create the object (MsgQueueObj), bind a name to it in the registry.
See TestMQ.java for an example.
java MsgQueue.Client clientname msgqueueobjectname
Don't forget to make sure 'rmiregistry' is running.
The args you supply are: the name the client is to be known by
(messages are automatically tagged with this before being sent), and
the name of the message queue object (whatever the server object is
bound to in the RMI registry; might want prefix with machine name).
What comes up is a command-line prompt. Basically, there are two simple commands: 'say' message, which sends the message, and 'quit'. Here is an example of using the client to connect to a message queue (called 'mq1') in a TaskableAgents agent:
bradley# java MsgQueue.Client client1 mq1
client1> say (location unitA 11 9)
input: say (location unitA 11 9)
sending: (location unitA 11 9)
client1>quit
bradley#
java -Djava.security.policy=policy MsgQueue.TestMQ //$(HOST)/mq1
Don't forget to make sure 'rmiregistry' is running. The policy
file right now is all-inclusive; you can make it more restrictive if
you want. Since this command is cumbersome to type, I put it
in the Makefile, so you can try 'make runmq', for example.
After initializing a message queue object with a name (for RMI registry) as specified on the command line, TestMQ then enters a loop in which it dumps its message queue every 8 seconds.