Class SimpleMessageSystem

java.lang.Object
pygar.communication.SimpleMessageSystem
All Implemented Interfaces:
PmessageSystem, PmessageSystemEE

@ThreadSafe
public class SimpleMessageSystem
extends java.lang.Object
implements PmessageSystemEE
The SimpleMessageSystem implements message passing between threads that share memory and file space. It implements message queues that the threads use to communicate. Message bodies are stored in files which never actually move because the file space is shared.

Warning - only demo0P uses this package. It is suitable for testing simple software on a single machine but inadequate for testing JMS software even on a single machine.

In an operational system, the sender and recipient would be separate process initialized with separate identities. In this simple, one process implementation, senders and receivers are separate threads in the same process. Consequently, this implementation requires a different SimpleMessageSystem object for each thread. The first object that is instantiated prepares class members shared by the objects.

Warning: this simple implementation does not protect data from loss if the software is shutdown while there are still messages in the queue. Furthermore, it saves all messages and never cleans up. Consequently, it is only suitable for short-term tests or demonstrations.

Warning: this simple implementation does not sign a message so that the recipient may verify it. The interface is agnostic about the message body which will be encrypted and/or signed as the case may require. However, a message without a body is also used as a protocol even and those should be signed and verified to protect the integrity of the system. Be sure to select a more complete implementation of PmessageSystem for production software.

  • Field Summary

    Fields 
    Modifier and Type Field Description
    java.lang.String id  
    static boolean isInitialized  
    static java.util.Map<java.lang.String,​java.util.Queue<Pmessage>> messages  
    static java.util.logging.Logger theLogger  
  • Constructor Summary

    Constructors 
    Modifier Constructor Description
    protected SimpleMessageSystem()
    This constructor sets up the shared area and returns an instance that is only suitable for using the factory method.
      SimpleMessageSystem​(java.lang.String senderId)
    The constructor sets up one sender.
  • Method Summary

    Modifier and Type Method Description
    boolean canSend​(Pmessage message)
    Test whether the system is ready to send to a given recipient.
    PmessageSystem getPmessageSystem​(java.lang.String senderId)
    Factory method returns a working instance for the specified senderId.
    PmessageSystem getPmessageSystem​(Profile p)
    Factory method returns a working instance for the specified configuration Profile.
    boolean hasNext()
    Return true if there is a Pmessage waiting to be received.
    static void main​(java.lang.String[] args)  
    Pmessage next()
    Return the next waiting Pmessage or void if there is none.
    void printAgents()
    Return all the agent names associated with this instance.
    void send​(java.lang.String sender, java.lang.String receiver, java.lang.String event)
    Send a simple event from one message agent to another.
    void send​(Pmessage message)
    Send a Pmessage to the destination specified in the Pmessage object.
    boolean shutdownNow()
    The SimpleMessageSystem has no mechanism to determine when it can shutdown so the condition shutdownNow() is always false.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • isInitialized

      public static boolean isInitialized
    • messages

      public static java.util.Map<java.lang.String,​java.util.Queue<Pmessage>> messages
    • id

      public java.lang.String id
    • theLogger

      public static java.util.logging.Logger theLogger
  • Constructor Details

    • SimpleMessageSystem

      protected SimpleMessageSystem()
      This constructor sets up the shared area and returns an instance that is only suitable for using the factory method.
    • SimpleMessageSystem

      public SimpleMessageSystem​(java.lang.String senderId)
      The constructor sets up one sender. If this is the first object to be constructed, it will also set up the logfile and other shared resources. Note that the filepath is used for the first object but it is ignored for all the rest because the shared resources were previously established. This constructor is not compatible with the convention for program configuration. Instead, one should use one exemplar of the class to provide additional instances via the factory method.
      Parameters:
      senderId - The identification of the thread that will send/get from this service
      Throws:
      MessageSystemException
  • Method Details