Package i5.las2peer.execution
Class ExecutionContext
java.lang.Object
i5.las2peer.execution.ExecutionContext
- All Implemented Interfaces:
Context
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreateEnvelope
(String identifier) Creates a new envelope with the current main agent as signing agent and first reader.createEnvelope
(String identifier, Agent using) Creates a new envelope with the given agent as signing agent and first reader.createGroupAgent
(Agent[] members) Creates a new GroupAgent.createGroupAgent
(Agent[] members, String groupName) Creates a new GroupAgent with groupName.createUserAgent
(String passphrase) Creates a new UserAgent.fetchAgent
(String agentId) Fetches an agent from the network.static ExecutionContext
Gets the current las2peer context.Gets the executor for this service.Gets the logger for the given class.Get the main agent of this context.Get the current service.<T extends Service>
TgetService
(Class<T> serviceType) Get the current service, avoiding casting.Get the current service agent responsible for executing the service.Gets the class loader responsible for loading the current service.getUserAgentIdentifierByEmail
(String emailAddress) Gets aUserAgent
's identifier by its email address.getUserAgentIdentifierByLoginName
(String loginName) Gets aUserAgent
's identifier by its login name.boolean
Checks if the main agent is able to unlock the agent agentId.boolean
Checks if the agent specified by using is able to unlock the agent agentId.invoke
(ServiceNameVersion service, String method, Serializable... parameters) Invokes the method of any other service on behalf of the main agent, thus sending the main agent as calling agent.invoke
(String service, String method, Serializable... parameters) Invokes the method of any other service on behalf of the main agent, thus sending the main agent as calling agent.invokeInternally
(ServiceNameVersion service, String method, Serializable... parameters) Invokes a service method using the agent of this service as calling agent.invokeInternally
(String service, String method, Serializable... parameters) Invokes a service method using the agent of this service as calling agent.void
monitorEvent
(MonitoringEvent event, String message) Writes a log message to the l2p system using node observers.void
monitorEvent
(Object from, MonitoringEvent event, String message) Writes a log message to the l2p system using node observers.void
monitorEvent
(Object from, MonitoringEvent event, String message, boolean includeActingUser) Writes a log message to the l2p system using node observers.void
monitorEvent
(String message) Writes a log message to the l2p system using node observers.void
reclaimEnvelope
(String identifier) Reclaims the envelope using the current main agent agent.void
reclaimEnvelope
(String identifier, Agent using) Reclaims the envelope using the specified agent.void
registerReceiver
(MessageReceiver receiver) requestAgent
(String agentId) Requests an agent from the network using the calling (main) agent.requestAgent
(String agentId, Agent using) Fetches an agent from the network and trys to unlock it using the specified agent.requestEnvelope
(String identifier) Requests an envelope from the network.requestEnvelope
(String identifier, Agent using) Requests an envelope from the network.void
storeAgent
(Agent agent) Stores and/or updates an agent to the network.void
storeEnvelope
(Envelope env) Stores the envelope to the network and signs it with the current main agent.void
storeEnvelope
(Envelope env, EnvelopeCollisionHandler handler) Stores the envelope to the network and signs it with the current main agent.void
storeEnvelope
(Envelope env, EnvelopeCollisionHandler handler, Agent using) Stores the envelope to the network and signs it with the specified agent.void
storeEnvelope
(Envelope env, Agent using) Stores the envelope to the network and signs it with the specified agent.
-
Constructor Details
-
ExecutionContext
-
-
Method Details
-
getCurrent
Description copied from interface:Context
Gets the current las2peer context.- Returns:
- the current context
-
getCallerContext
-
getServiceClassLoader
Description copied from interface:Context
Gets the class loader responsible for loading the current service.- Specified by:
getServiceClassLoader
in interfaceContext
- Returns:
- The current service class loader.
-
getExecutor
Description copied from interface:Context
Gets the executor for this service. Async tasks should be handeld using this executor. They can access the current context.- Specified by:
getExecutor
in interfaceContext
- Returns:
- The executor responsible for the current service call.
-
getService
Description copied from interface:Context
Get the current service.- Specified by:
getService
in interfaceContext
- Returns:
- the current service
-
getService
Description copied from interface:Context
Get the current service, avoiding casting.- Specified by:
getService
in interfaceContext
- Type Parameters:
T
- type of the service- Parameters:
serviceType
- service class- Returns:
- the current service
-
getServiceAgent
Description copied from interface:Context
Get the current service agent responsible for executing the service.- Specified by:
getServiceAgent
in interfaceContext
- Returns:
- the executing service agent.
-
getMainAgent
Description copied from interface:Context
Get the main agent of this context. In most cases, this is the user.- Specified by:
getMainAgent
in interfaceContext
- Returns:
- the calling agent.
-
invoke
public Serializable invoke(String service, String method, Serializable... parameters) throws ServiceNotFoundException, ServiceNotAvailableException, InternalServiceException, ServiceMethodNotFoundException, ServiceInvocationFailedException, ServiceAccessDeniedException, ServiceNotAuthorizedException Description copied from interface:Context
Invokes the method of any other service on behalf of the main agent, thus sending the main agent as calling agent.- Specified by:
invoke
in interfaceContext
- Parameters:
service
- The service class. A version may be specified (for example package.serviceClass@1.0.0-1 or package.serviceClass@1.0). The core tries to find an appropriate version (version 1.0.5 matches 1.0). If no version is specified, the newest version is picked.method
- The service method.parameters
- The parameters list.- Returns:
- The invocation result.
- Throws:
ServiceNotFoundException
- If the service is not known to the network.ServiceNotAvailableException
- If the service is temporarily not available.InternalServiceException
- If the remote service throws an exception.ServiceMethodNotFoundException
- If the service method does not exist.ServiceInvocationFailedException
- If the service invocation failed.ServiceAccessDeniedException
- If the access to the service has been denied.ServiceNotAuthorizedException
- If access to the service method requires a logged in user.
-
invoke
public Serializable invoke(ServiceNameVersion service, String method, Serializable... parameters) throws ServiceNotFoundException, ServiceNotAvailableException, InternalServiceException, ServiceMethodNotFoundException, ServiceInvocationFailedException, ServiceAccessDeniedException, ServiceNotAuthorizedException Description copied from interface:Context
Invokes the method of any other service on behalf of the main agent, thus sending the main agent as calling agent.- Specified by:
invoke
in interfaceContext
- Parameters:
service
- The service class. A version may be specified (for example package.serviceClass@1.0.0-1 or package.serviceClass@1.0). The core tries to find an appropriate version (version 1.0.5 matches 1.0). If no version is specified, the newest version is picked.method
- The service method.parameters
- The parameters list.- Returns:
- The invocation result.
- Throws:
ServiceNotFoundException
- If the service is not known to the network.ServiceNotAvailableException
- If the service is temporarily not available.InternalServiceException
- If the remote service throws an exception.ServiceMethodNotFoundException
- If the service method does not exist.ServiceInvocationFailedException
- If the service invocation failed.ServiceAccessDeniedException
- If the access to the service has been denied.ServiceNotAuthorizedException
- If access to the service method requires a logged in user.
-
invokeInternally
public Serializable invokeInternally(String service, String method, Serializable... parameters) throws ServiceNotFoundException, ServiceNotAvailableException, InternalServiceException, ServiceMethodNotFoundException, ServiceInvocationFailedException, ServiceAccessDeniedException, ServiceNotAuthorizedException Description copied from interface:Context
Invokes a service method using the agent of this service as calling agent.- Specified by:
invokeInternally
in interfaceContext
- Parameters:
service
- The service class. A version may be specified (for example package.serviceClass@1.0.0-1 or package.serviceClass@1.0). The core tries to find an appropriate version (version 1.0.5 matches 1.0). If no version is specified, the newest version is picked.method
- The service method.parameters
- The parameters list.- Returns:
- The invocation result.
- Throws:
ServiceNotFoundException
- If the service is not known to the network.ServiceNotAvailableException
- If the service is temporarily not available.InternalServiceException
- If the remote service throws an exception.ServiceMethodNotFoundException
- If the service method does not exist.ServiceInvocationFailedException
- If the service invocation failed.ServiceAccessDeniedException
- If the access to the service has been denied.ServiceNotAuthorizedException
- If access to the service method requires a logged in user.
-
invokeInternally
public Serializable invokeInternally(ServiceNameVersion service, String method, Serializable... parameters) throws ServiceNotFoundException, ServiceNotAvailableException, InternalServiceException, ServiceMethodNotFoundException, ServiceInvocationFailedException, ServiceAccessDeniedException, ServiceNotAuthorizedException Description copied from interface:Context
Invokes a service method using the agent of this service as calling agent.- Specified by:
invokeInternally
in interfaceContext
- Parameters:
service
- The service class. A version may be specified (for example package.serviceClass@1.0.0-1 or package.serviceClass@1.0). The core tries to find an appropriate version (version 1.0.5 matches 1.0). If no version is specified, the newest version is picked.method
- The service method.parameters
- The parameters list.- Returns:
- The invocation result.
- Throws:
ServiceNotFoundException
- If the service is not known to the network.ServiceNotAvailableException
- If the service is temporarily not available.InternalServiceException
- If the remote service throws an exception.ServiceMethodNotFoundException
- If the service method does not exist.ServiceInvocationFailedException
- If the service invocation failed.ServiceAccessDeniedException
- If the access to the service has been denied.ServiceNotAuthorizedException
- If access to the service method requires a logged in user.
-
monitorEvent
Description copied from interface:Context
Writes a log message to the l2p system using node observers. Also makes data available to MobSOS. Does not include the current acting main agent. The MonitoringEvent will default to MonitoringEvent.SERVICE_MESSAGE. Use this method for trivial log messages.- Specified by:
monitorEvent
in interfaceContext
- Parameters:
message
- A message.
-
monitorEvent
Description copied from interface:Context
Writes a log message to the l2p system using node observers. Also makes data available to MobSOS. Does not include the current acting main agent.- Specified by:
monitorEvent
in interfaceContext
- Parameters:
event
- Differentiates between different log messages. Use MonitoringEvent.SERVICE_CUSTOM_MESSAGE_XXX as parameter.message
- A message.
-
monitorEvent
Description copied from interface:Context
Writes a log message to the l2p system using node observers. Also makes data available to MobSOS. Does not include the current acting main agent.- Specified by:
monitorEvent
in interfaceContext
- Parameters:
from
- Specifies from which class the message is sent from. Usually "this" is passed as parameter.event
- Differentiates between different log messages. Use MonitoringEvent.SERVICE_CUSTOM_MESSAGE_XXX as parameter.message
- A message.
-
monitorEvent
public void monitorEvent(Object from, MonitoringEvent event, String message, boolean includeActingUser) Description copied from interface:Context
Writes a log message to the l2p system using node observers. Also makes data available to MobSOS.- Specified by:
monitorEvent
in interfaceContext
- Parameters:
from
- Specifies from which class the message is sent from. Usually "this" is passed as parameter.event
- Differentiates between different log messages. Use MonitoringEvent.SERVICE_CUSTOM_MESSAGE_XXX as parameter.message
- A message.includeActingUser
- If set to true, the current main agent will be included.
-
createUserAgent
Description copied from interface:Context
Creates a new UserAgent.- Specified by:
createUserAgent
in interfaceContext
- Parameters:
passphrase
- the passphrase to protect the newly generated agent- Returns:
- A new unlocked UserAgent which is not stored to the network yet.
- Throws:
AgentOperationFailedException
- if an error occurred on the node.
-
createGroupAgent
Description copied from interface:Context
Creates a new GroupAgent.- Specified by:
createGroupAgent
in interfaceContext
- Parameters:
members
- Initial member list- Returns:
- A new unlocked GroupAgent which is not stored to the network yet.
- Throws:
AgentOperationFailedException
- If an error occurred on the node.
-
createGroupAgent
public GroupAgent createGroupAgent(Agent[] members, String groupName) throws AgentOperationFailedException Description copied from interface:Context
Creates a new GroupAgent with groupName.- Specified by:
createGroupAgent
in interfaceContext
- Parameters:
members
- Initial member list- Returns:
- A new unlocked GroupAgent which is not stored to the network yet.
- Throws:
AgentOperationFailedException
- If an error occurred on the node.
-
fetchAgent
public Agent fetchAgent(String agentId) throws AgentNotFoundException, AgentOperationFailedException Description copied from interface:Context
Fetches an agent from the network.- Specified by:
fetchAgent
in interfaceContext
- Parameters:
agentId
- The id of the agent to fetch.- Returns:
- A probably locked instance of the specified agent.
- Throws:
AgentNotFoundException
- If the specified agent cannot be found.AgentOperationFailedException
- If an error occurred on the node.
-
requestAgent
public Agent requestAgent(String agentId, Agent using) throws AgentAccessDeniedException, AgentNotFoundException, AgentOperationFailedException Description copied from interface:Context
Fetches an agent from the network and trys to unlock it using the specified agent.- Specified by:
requestAgent
in interfaceContext
- Parameters:
agentId
- The id of the agent to fetch.using
- The agent used to unlock the fetched agent.- Returns:
- An unlocked instance of the requested agent.
- Throws:
AgentAccessDeniedException
- If the given agent cannot access the fetched agent.AgentNotFoundException
- If the specified agent cannot be found.AgentOperationFailedException
- If an error occurred on the node.
-
requestAgent
public Agent requestAgent(String agentId) throws AgentAccessDeniedException, AgentNotFoundException, AgentOperationFailedException Description copied from interface:Context
Requests an agent from the network using the calling (main) agent.- Specified by:
requestAgent
in interfaceContext
- Parameters:
agentId
- The id of the agent to fetch.- Returns:
- An unlocked instance of the requested agent.
- Throws:
AgentAccessDeniedException
- If the main agent cannot access the fetched agent.AgentNotFoundException
- If the specified agent cannot be found.AgentOperationFailedException
- If an error occurred on the node.
-
storeAgent
public void storeAgent(Agent agent) throws AgentAccessDeniedException, AgentAlreadyExistsException, AgentOperationFailedException, AgentLockedException Description copied from interface:Context
Stores and/or updates an agent to the network. The given agent must be unlocked.- Specified by:
storeAgent
in interfaceContext
- Parameters:
agent
- The unlocked agent to store.- Throws:
AgentAccessDeniedException
- If the agent cannot be overridden due to access restrictions. Or it is the AnonymousAgent.AgentAlreadyExistsException
- If another agent already exists (regarding some agent specific properties).AgentOperationFailedException
- If an error occurred on the node.AgentLockedException
- If the agent is locked.
-
hasAccess
Description copied from interface:Context
Checks if the agent specified by using is able to unlock the agent agentId. This also includes recursive unlocking.- Specified by:
hasAccess
in interfaceContext
- Parameters:
agentId
- The agent to be checked.using
- The agent to unlock.- Returns:
- true If using is able to unlock agentId.
- Throws:
AgentNotFoundException
- If the agent specified by agentId does not exist.
-
hasAccess
Description copied from interface:Context
Checks if the main agent is able to unlock the agent agentId. This also includes recursive unlocking.- Specified by:
hasAccess
in interfaceContext
- Parameters:
agentId
- The agent to be checked.- Returns:
- true If the main agent is able to unlock the given agent.
- Throws:
AgentNotFoundException
- If the agent specified by agentId does not exist.
-
getUserAgentIdentifierByLoginName
public String getUserAgentIdentifierByLoginName(String loginName) throws AgentNotFoundException, AgentOperationFailedException Description copied from interface:Context
Gets aUserAgent
's identifier by its login name.- Specified by:
getUserAgentIdentifierByLoginName
in interfaceContext
- Parameters:
loginName
- The user's login name- Returns:
- The identifier of the user agents.
- Throws:
AgentNotFoundException
- If there is no agent with the given login name.AgentOperationFailedException
- On node errors.
-
getUserAgentIdentifierByEmail
public String getUserAgentIdentifierByEmail(String emailAddress) throws AgentNotFoundException, AgentOperationFailedException Description copied from interface:Context
Gets aUserAgent
's identifier by its email address.- Specified by:
getUserAgentIdentifierByEmail
in interfaceContext
- Parameters:
emailAddress
- The user's email address.- Returns:
- The identifier of the user agents.
- Throws:
AgentNotFoundException
- If there is no agent with the given email address.AgentOperationFailedException
- On node errors.
-
registerReceiver
public void registerReceiver(MessageReceiver receiver) throws AgentAlreadyRegisteredException, AgentException - Specified by:
registerReceiver
in interfaceContext
- Throws:
AgentAlreadyRegisteredException
AgentException
-
getLogger
Description copied from interface:Context
Gets the logger for the given class. -
requestEnvelope
public Envelope requestEnvelope(String identifier, Agent using) throws EnvelopeAccessDeniedException, EnvelopeNotFoundException, EnvelopeOperationFailedException Description copied from interface:Context
Requests an envelope from the network. This means fetching and decrypting it using the specified agent.- Specified by:
requestEnvelope
in interfaceContext
- Parameters:
identifier
- Identifier of the envelope.using
- Agentu sing to open the envelope.- Returns:
- An opened envelope.
- Throws:
EnvelopeAccessDeniedException
- If the given agent is not able to access the envelope.EnvelopeNotFoundException
- If the envelope doesn not exist.EnvelopeOperationFailedException
- If an error occurred in the node or network.
-
requestEnvelope
public Envelope requestEnvelope(String identifier) throws EnvelopeAccessDeniedException, EnvelopeNotFoundException, EnvelopeOperationFailedException Description copied from interface:Context
Requests an envelope from the network. This means fetching and decrypting it using the current main agent.- Specified by:
requestEnvelope
in interfaceContext
- Parameters:
identifier
- Identifier of the envelope.- Returns:
- An opened envelope.
- Throws:
EnvelopeAccessDeniedException
- If the given agent is not able to access the envelope.EnvelopeNotFoundException
- If the envelope doesn not exist.EnvelopeOperationFailedException
- If an error occurred at the node or in the network.
-
storeEnvelope
public void storeEnvelope(Envelope env, Agent using) throws EnvelopeAccessDeniedException, EnvelopeOperationFailedException Description copied from interface:Context
Stores the envelope to the network and signs it with the specified agent.- Specified by:
storeEnvelope
in interfaceContext
- Parameters:
env
- The envelope to store.using
- The agent to be used to sign the envelope.- Throws:
EnvelopeAccessDeniedException
- If the specified agent is not allowed to write to the envelope.EnvelopeOperationFailedException
- If an error occurred at the node or in the network.
-
storeEnvelope
public void storeEnvelope(Envelope env) throws EnvelopeAccessDeniedException, EnvelopeOperationFailedException Description copied from interface:Context
Stores the envelope to the network and signs it with the current main agent.- Specified by:
storeEnvelope
in interfaceContext
- Parameters:
env
- The envelope to store.- Throws:
EnvelopeAccessDeniedException
- If the specified agent is not allowed to write to the envelope.EnvelopeOperationFailedException
- If an error occurred at the node or in the network.
-
storeEnvelope
public void storeEnvelope(Envelope env, EnvelopeCollisionHandler handler, Agent using) throws EnvelopeAccessDeniedException, EnvelopeOperationFailedException Description copied from interface:Context
Stores the envelope to the network and signs it with the specified agent.- Specified by:
storeEnvelope
in interfaceContext
- Parameters:
env
- The envelope to store.handler
- An handler to resolve storage conflict (e.g. the envelope has been updated in the meantime).using
- The agent to be used to sign the envelope (and must have signed the envelope or must have access to the signing agent if there are previous versions).- Throws:
EnvelopeAccessDeniedException
- If the specified agent is not allowed to write to the envelope.EnvelopeOperationFailedException
- If an error occurred at the node or in the network.
-
storeEnvelope
public void storeEnvelope(Envelope env, EnvelopeCollisionHandler handler) throws EnvelopeAccessDeniedException, EnvelopeOperationFailedException Description copied from interface:Context
Stores the envelope to the network and signs it with the current main agent.- Specified by:
storeEnvelope
in interfaceContext
- Parameters:
env
- The envelope to store.handler
- An handler to resolve storage conflict (e.g. the envelope has been updated in the meantime).- Throws:
EnvelopeAccessDeniedException
- If the specified agent is not allowed to write to the envelope.EnvelopeOperationFailedException
- If an error occurred at the node or in the network.
-
reclaimEnvelope
public void reclaimEnvelope(String identifier, Agent using) throws EnvelopeAccessDeniedException, EnvelopeNotFoundException, EnvelopeOperationFailedException Description copied from interface:Context
Reclaims the envelope using the specified agent. A reclaim operation marks the envelope as deleted and indicates that the envelope is no longer needed anymore (e.g. can be deleted by other nodes). However, it is not guaranteed that the envelope will be deleted since the nature of a p2p network.- Specified by:
reclaimEnvelope
in interfaceContext
- Parameters:
identifier
- The identifier of the envelope.using
- The agent that has signed the envelope or an agent that has access to the signing agent.- Throws:
EnvelopeAccessDeniedException
- If the agent has not signed the envelope.EnvelopeNotFoundException
- If the envelope does not exist.EnvelopeOperationFailedException
- If an error occurred at the node or in the network.
-
reclaimEnvelope
public void reclaimEnvelope(String identifier) throws EnvelopeAccessDeniedException, EnvelopeNotFoundException, EnvelopeOperationFailedException Description copied from interface:Context
Reclaims the envelope using the current main agent agent. A reclaim operation marks the envelope as deleted and indicates that the envelope is no longer needed anymore (e.g. can be deleted by other nodes). However, it is not guaranteed that the envelope will be deleted since the nature of a p2p network.- Specified by:
reclaimEnvelope
in interfaceContext
- Parameters:
identifier
- The identifier of the envelope.- Throws:
EnvelopeAccessDeniedException
- If the agent has not signed the envelope.EnvelopeNotFoundException
- If the envelope does not exist.EnvelopeOperationFailedException
- If an error occurred at the node or in the network.
-
createEnvelope
public Envelope createEnvelope(String identifier, Agent using) throws EnvelopeOperationFailedException, EnvelopeAccessDeniedException Description copied from interface:Context
Creates a new envelope with the given agent as signing agent and first reader.- Specified by:
createEnvelope
in interfaceContext
- Parameters:
identifier
- Identifier of the envelope.using
- Signing agent (owner) of the envelope.- Returns:
- An envelope that is not stored to the network yet.
- Throws:
EnvelopeOperationFailedException
- If an error occurred at the node or in the network.EnvelopeAccessDeniedException
- If the agent is not allowed to create envelopes (e.g. the AnonymousAgent).
-
createEnvelope
public Envelope createEnvelope(String identifier) throws EnvelopeOperationFailedException, EnvelopeAccessDeniedException Description copied from interface:Context
Creates a new envelope with the current main agent as signing agent and first reader.- Specified by:
createEnvelope
in interfaceContext
- Parameters:
identifier
- Identifier of the envelope.- Returns:
- An envelope that is not stored to the network yet.
- Throws:
EnvelopeOperationFailedException
- If an error occurred at the node or in the network.EnvelopeAccessDeniedException
- If the agent is not allowed to create envelopes (e.g. the AnonymousAgent).
-