Class Mediator

java.lang.Object
i5.las2peer.security.Mediator
All Implemented Interfaces:
MessageReceiver

public class Mediator extends Object implements MessageReceiver
A Mediator acts on behalf of an PassphraseAgentImpl. This necessary e.g. for remote users logged in via a Connector to collect incoming messages from the P2P network and transfer it to the connector.
Two ways for message handling are provided: Register a MessageHandler that will be called for each received message. Multiple MessageHandlers are possible (for example for different message contents). The second way to handle messages is to get pending messages from the Mediator directly via the provided methods. Handling then has to be done via the calling entity (for example a service).
  • Constructor Details

  • Method Details

    • getNextMessage

      public Message getNextMessage()
      Gets (and removes) the next pending message.
      Returns:
      the next collected message
    • hasMessages

      public boolean hasMessages()
      Does this mediator have pending messages?
      Returns:
      true, if messages have arrived
    • receiveMessage

      public void receiveMessage(Message message, AgentContext c) throws MessageException
      Description copied from interface: MessageReceiver
      Receives a message. Will be called by a Node implementation on reception of messages that this receiver is responsible for.
      Specified by:
      receiveMessage in interface MessageReceiver
      Throws:
      MessageException
    • workOnMessage

      public boolean workOnMessage(Message message, AgentContext context)
      Method for message reception treatment. Will call all registered MessageHandlers for message handling. A return value of true indicates, that the received message has been treated by a MessageHandler and does not need further storage for later use (and will not be added to pending messages).
      Parameters:
      message -
      context -
      Returns:
      true, if a message had been treated successfully
    • getMyNode

      protected Node getMyNode()
      Grants access to the node this Mediator is registered to.
      Returns:
      the node this Mediator is running at
    • isRegistered

      public boolean isRegistered()
      Returns:
      true if this mediator is registered as MessageReceiver at the node
    • getResponsibleForAgentSafeId

      public String getResponsibleForAgentSafeId()
      Description copied from interface: MessageReceiver
      In case a Mediator implements this interface, this method will return the id of the agent, this mediator is responsible for. Otherwise it will just return the AgentImpls id.
      Specified by:
      getResponsibleForAgentSafeId in interface MessageReceiver
      Returns:
      id of the agent, this receiver is responsible for
    • getAgent

      public AgentImpl getAgent()
      Gets the mediated agent
      Returns:
      Returns the mediated agent
    • notifyRegistrationTo

      public void notifyRegistrationTo(Node node)
      Description copied from interface: MessageReceiver
      Called by a Node on registering a MessageReceiver to the network.
      Specified by:
      notifyRegistrationTo in interface MessageReceiver
      Parameters:
      node - the node this receiver has been registered to
    • notifyUnregister

      public void notifyUnregister()
      Description copied from interface: MessageReceiver
      Called by a Node on unregistering a MessageReceiver from the network.
      Specified by:
      notifyUnregister in interface MessageReceiver
    • invoke

      @Deprecated public Serializable invoke(String service, String method, Serializable[] parameters, boolean localOnly) throws InternalSecurityException, ServiceInvocationException, AgentException
      Deprecated.
      Invokes a service method (in the network) for the mediated agent.
      Parameters:
      service - the service to invoke
      method - method to invoke
      parameters - list of method parameters
      localOnly - if true, only services on this node are invoked
      Returns:
      result of the method invocation
      Throws:
      InternalSecurityException
      ServiceInvocationException
      AgentException
    • invoke

      public Serializable invoke(ServiceNameVersion serviceNameVersion, String method, Serializable[] parameters, boolean localOnly) throws InternalSecurityException, ServiceInvocationException, AgentException
      Invokes a service method (in the network) for the mediated agent.
      Parameters:
      serviceNameVersion - the service and version to invoke
      method - method to invoke
      parameters - list of method parameters
      localOnly - if true, only services on this node are invoked
      Returns:
      result of the method invocation
      Throws:
      InternalSecurityException
      ServiceInvocationException
      AgentException
    • getNumberOfWaiting

      public int getNumberOfWaiting()
      Gets the number of waiting messages.
      Returns:
      number of waiting messages
    • registerMessageHandler

      public void registerMessageHandler(MessageHandler handler)
      Registers a MessageHandler for message processing. Message handlers will be used for handling incoming messages in the order of registration.
      Parameters:
      handler -
    • unregisterMessageHandler

      public void unregisterMessageHandler(MessageHandler handler)
      Unregisters a handler from this mediator.
      Parameters:
      handler -
    • unregisterMessageHandlerClass

      public int unregisterMessageHandlerClass(Class<?> cls)
      Unregisters all handlers of the given class.
      Parameters:
      cls -
      Returns:
      number of successfully removed message handlers
    • unregisterMessageHandlerClass

      public int unregisterMessageHandlerClass(String classname)
      Unregisters all handlers of the given class.
      Parameters:
      classname -
      Returns:
      number of successfully removed message handlers
    • hasMessageHandler

      public boolean hasMessageHandler(MessageHandler handler)
      Is the given message handler registered at this mediator?
      Parameters:
      handler -
      Returns:
      true, if at least one message handler is registered to this mediator
    • hasMessageHandlerClass

      public boolean hasMessageHandlerClass(Class<?> cls)
      Has this mediator a registered message handler of the given class?
      Parameters:
      cls -
      Returns:
      true, if this mediator has a message handler of the given class