Package i5.las2peer.security
Class Mediator
java.lang.Object
i5.las2peer.security.Mediator
- All Implemented Interfaces:
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 TypeMethodDescriptiongetAgent()
Gets the mediated agentprotected Node
Grants access to the node this Mediator is registered to.Gets (and removes) the next pending message.int
Gets the number of waiting messages.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
(Class<?> cls) Has this mediator a registered message handler of the given class?boolean
Does this mediator have pending messages?invoke
(ServiceNameVersion serviceNameVersion, String method, Serializable[] parameters, boolean localOnly) Invokes a service method (in the network) for the mediated agent.invoke
(String service, String method, Serializable[] parameters, boolean localOnly) Deprecated.boolean
void
notifyRegistrationTo
(Node node) Called by aNode
on registering a MessageReceiver to the network.void
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
(Class<?> cls) Unregisters all handlers of the given class.int
unregisterMessageHandlerClass
(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
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 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 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 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 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
Unregisters all handlers of the given class.- Parameters:
cls
-- Returns:
- number of successfully removed message handlers
-
unregisterMessageHandlerClass
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
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
-