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 AgentImpl
getAgent()
Gets the mediated agentprotected Node
getMyNode()
Grants access to the node this Mediator is registered to.Message
getNextMessage()
Gets (and removes) the next pending message.int
getNumberOfWaiting()
Gets the number of waiting messages.java.lang.String
getResponsibleForAgentSafeId()
In case aMediator
implements this interface, this method will return the id of the agent, this mediator is responsible for.boolean
hasMessageHandler(MessageHandler handler)
Is the given message handler registered at this mediator?boolean
hasMessageHandlerClass(java.lang.Class<?> cls)
Has this mediator a registered message handler of the given class?boolean
hasMessages()
Does this mediator have pending messages?java.io.Serializable
invoke(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.Serializable
invoke(java.lang.String service, java.lang.String method, java.io.Serializable[] parameters, boolean localOnly)
Deprecated.boolean
isRegistered()
void
notifyRegistrationTo(Node node)
Called by aNode
on registering a MessageReceiver to the network.void
notifyUnregister()
Called by aNode
on unregistering a MessageReceiver from the network.void
receiveMessage(Message message, AgentContext c)
Receives a message.void
registerMessageHandler(MessageHandler handler)
Registers a MessageHandler for message processing.void
unregisterMessageHandler(MessageHandler handler)
Unregisters a handler from this mediator.int
unregisterMessageHandlerClass(java.lang.Class<?> cls)
Unregisters all handlers of the given class.int
unregisterMessageHandlerClass(java.lang.String classname)
Unregisters all handlers of the given class.boolean
workOnMessage(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:MessageReceiver
Receives a message. Will be called by aNode
implementation on reception of messages that this receiver is responsible for.- Specified by:
receiveMessage
in interfaceMessageReceiver
- Throws:
MessageException
-
workOnMessage
Method for message reception treatment. Will call all registeredMessageHandler
s 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:MessageReceiver
In case aMediator
implements this interface, this method will return the id of the agent, this mediator is responsible for. Otherwise it will just return theAgentImpl
s id.- Specified by:
getResponsibleForAgentSafeId
in 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:MessageReceiver
Called by aNode
on registering a MessageReceiver to the network.- Specified by:
notifyRegistrationTo
in interfaceMessageReceiver
- Parameters:
node
- the node this receiver has been registered to
-
notifyUnregister
public void notifyUnregister()Description copied from interface:MessageReceiver
Called by aNode
on unregistering a MessageReceiver from the network.- Specified by:
notifyUnregister
in 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:
InternalSecurityException
ServiceInvocationException
AgentException
-
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:
InternalSecurityException
ServiceInvocationException
AgentException
-
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
-