Package i5.las2peer.security
Class Mediator
java.lang.Object
i5.las2peer.security.Mediator
- All Implemented Interfaces:
MessageReceiver
public class Mediator extends java.lang.Object implements MessageReceiver
A Mediator acts on behalf of an
Two ways for message handling are provided: Register a
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 Summary
-
Method Summary
Modifier and Type Method Description AgentImplgetAgent()Gets the mediated agentprotected NodegetMyNode()Grants access to the node this Mediator is registered to.MessagegetNextMessage()Gets (and removes) the next pending message.intgetNumberOfWaiting()Gets the number of waiting messages.java.lang.StringgetResponsibleForAgentSafeId()In case aMediatorimplements this interface, this method will return the id of the agent, this mediator is responsible for.booleanhasMessageHandler(MessageHandler handler)Is the given message handler registered at this mediator?booleanhasMessageHandlerClass(java.lang.Class<?> cls)Has this mediator a registered message handler of the given class?booleanhasMessages()Does this mediator have pending messages?java.io.Serializableinvoke(ServiceNameVersion serviceNameVersion, java.lang.String method, java.io.Serializable[] parameters, boolean localOnly)Invokes a service method (in the network) for the mediated agent.java.io.Serializableinvoke(java.lang.String service, java.lang.String method, java.io.Serializable[] parameters, boolean localOnly)Deprecated.booleanisRegistered()voidnotifyRegistrationTo(Node node)Called by aNodeon registering a MessageReceiver to the network.voidnotifyUnregister()Called by aNodeon unregistering a MessageReceiver from the network.voidreceiveMessage(Message message, AgentContext c)Receives a message.voidregisterMessageHandler(MessageHandler handler)Registers a MessageHandler for message processing.voidunregisterMessageHandler(MessageHandler handler)Unregisters a handler from this mediator.intunregisterMessageHandlerClass(java.lang.Class<?> cls)Unregisters all handlers of the given class.intunregisterMessageHandlerClass(java.lang.String classname)Unregisters all handlers of the given class.booleanworkOnMessage(Message message, AgentContext context)Method for message reception treatment.
-
Constructor Details
-
Mediator
Creates a new mediator.- Parameters:
n- the nodea- the agent- Throws:
AgentLockedException
-
-
Method Details
-
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
Description copied from interface:MessageReceiverReceives a message. Will be called by aNodeimplementation on reception of messages that this receiver is responsible for.- Specified by:
receiveMessagein interfaceMessageReceiver- Throws:
MessageException
-
workOnMessage
Method for message reception treatment. Will call all registeredMessageHandlers 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
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 java.lang.String getResponsibleForAgentSafeId()Description copied from interface:MessageReceiverIn case aMediatorimplements this interface, this method will return the id of the agent, this mediator is responsible for. Otherwise it will just return theAgentImpls id.- Specified by:
getResponsibleForAgentSafeIdin interfaceMessageReceiver- Returns:
- id of the agent, this receiver is responsible for
-
getAgent
Gets the mediated agent- Returns:
- Returns the mediated agent
-
notifyRegistrationTo
Description copied from interface:MessageReceiverCalled by aNodeon registering a MessageReceiver to the network.- Specified by:
notifyRegistrationToin interfaceMessageReceiver- Parameters:
node- the node this receiver has been registered to
-
notifyUnregister
public void notifyUnregister()Description copied from interface:MessageReceiverCalled by aNodeon unregistering a MessageReceiver from the network.- Specified by:
notifyUnregisterin interfaceMessageReceiver
-
invoke
@Deprecated public java.io.Serializable invoke(java.lang.String service, java.lang.String method, java.io.Serializable[] parameters, boolean localOnly) throws InternalSecurityException, ServiceInvocationException, AgentExceptionDeprecated.Invokes a service method (in the network) for the mediated agent.- Parameters:
service- the service to invokemethod- method to invokeparameters- list of method parameterslocalOnly- if true, only services on this node are invoked- Returns:
- result of the method invocation
- Throws:
InternalSecurityExceptionServiceInvocationExceptionAgentException
-
invoke
public java.io.Serializable invoke(ServiceNameVersion serviceNameVersion, java.lang.String method, java.io.Serializable[] parameters, boolean localOnly) throws InternalSecurityException, ServiceInvocationException, AgentExceptionInvokes a service method (in the network) for the mediated agent.- Parameters:
serviceNameVersion- the service and version to invokemethod- method to invokeparameters- list of method parameterslocalOnly- if true, only services on this node are invoked- Returns:
- result of the method invocation
- Throws:
InternalSecurityExceptionServiceInvocationExceptionAgentException
-
getNumberOfWaiting
public int getNumberOfWaiting()Gets the number of waiting messages.- Returns:
- number of waiting messages
-
registerMessageHandler
Registers a MessageHandler for message processing. Message handlers will be used for handling incoming messages in the order of registration.- Parameters:
handler-
-
unregisterMessageHandler
Unregisters a handler from this mediator.- Parameters:
handler-
-
unregisterMessageHandlerClass
public int unregisterMessageHandlerClass(java.lang.Class<?> cls)Unregisters all handlers of the given class.- Parameters:
cls-- Returns:
- number of successfully removed message handlers
-
unregisterMessageHandlerClass
public int unregisterMessageHandlerClass(java.lang.String classname)Unregisters all handlers of the given class.- Parameters:
classname-- Returns:
- number of successfully removed message handlers
-
hasMessageHandler
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(java.lang.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
-