class Agent
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
Agent.AgentCommand
Defines a command to be sent to an agent.
|
private static class |
Agent.AgentRemoteProcedure
Defines some data which is required by the agent to know about any persistent procedure ran on it.
|
private class |
Agent.AgentStopper
Class used to stop a command currently being executed by this Agent, by sendint an interrupt
request via
Control.interrupt() . |
(package private) static class |
Agent.InvocationModes
List of possible invocation modes:
Agent.InvocationModes.IMMEDIATELY - in this thread (the thread must be an agent thread)
Agent.InvocationModes.AGENT_WAIT - in a different agent, wait for response
Agent.InvocationModes.AGENT_NO_WAIT in a different agent, do not wait for response
|
private class |
Agent.ResetContextCommand
Implements the reset context command.
|
Modifier and Type | Field and Description |
---|---|
private static java.util.Set<java.lang.String> |
activeWebServiceTokens
The set of web service tokens currently being active (with an API call in progress).
|
private int |
agentId
The agent's ID, unique.
|
private boolean |
bound
Flag indicating the agent has been bound to the connection.
|
private java.util.Queue<Agent.AgentCommand> |
commands
The command queue for this agent.
|
private static org.apache.commons.logging.Log |
LOG
Logger
|
private AgentPool |
pool
The agent's pool.
|
private java.util.Map<java.lang.String,Agent.AgentRemoteProcedure> |
remoteProcedures
The remote procedures ran on this agent.
|
private AssociatedThread |
stopper
Dedicated thread to stop any job currently being executed by this Agent.
|
private Agent.AgentStopper |
stopperWorker
The agent's stopper worker.
|
private boolean |
terminated
Flag indicating if the agent has been terminated.
|
private java.lang.Thread |
thread
The agent's listening thread.
|
Constructor and Description |
---|
Agent(AgentPool pool,
int agentId)
Build a new agent and associate it with the given pool.
|
Modifier and Type | Method and Description |
---|---|
void |
addProcedure(handle extProg)
Register the given external procedure with this agent, as a remote procedure.
|
void |
bind()
Bind the agent to the connection.
|
private void |
checkError(AppServerInvocationResult invocationResult,
ErrorConditionException e)
Check if the specified ERROR condition needs to be reported.
|
void |
deleteObject(java.lang.String resId)
Delete the specified legacy object, under the Agent's context.
|
void |
deleteProcedure(java.lang.String resId,
java.lang.String token)
Delete the specified procedure, under the Agent's context.
|
void |
deleteProcedures()
Delete the agent's currently bound
procedures . |
private static BaseDataType |
executeScoped(java.util.function.Supplier<BaseDataType> task)
Execute the specified task scoped to a topmost, global block.
|
int |
getAgentId()
Get the agentId for this session.
|
(package private) AppServerOperatingMode |
getOperatingMode()
Get the operating mode for this appserver.
|
ExternalProgramWrapper |
getProcedure(java.lang.String resId)
Get the external procedure associated with this agent.
|
java.lang.String |
getProcedureName(java.lang.String resId)
Get the procedure name for the given resource ID.
|
(package private) java.lang.String |
getServerConnectionContext(java.lang.String connectionID)
Get the SERVER-CONNECTION-CONTEXT attribute of this session.
|
private java.lang.Integer |
getSessionId()
Get the sessionId for this session.
|
private java.lang.Integer |
getThreadId()
Get the threadId for this session.
|
AppServerInvocationResult |
handleWebService(java.lang.String id,
int requestId,
long timeout,
java.lang.Class<? extends WebHandler> handler,
java.lang.String basepath,
java.lang.String[] paths,
java.lang.String token,
java.lang.String target,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Handle a generic web service request.
|
boolean |
hasProcedure(java.lang.String resId)
Check if the given resource ID is for a persistent procedure an on this agent.
|
(package private) boolean |
hasProcedures(java.lang.String id)
Check if this agent has persistent procedures ran on that connection ID.
|
AppServerInvocationResult |
initializeProxy(java.lang.String id,
java.lang.String code,
int requestId,
boolean transactionDistinct,
java.lang.String modes,
java.lang.Object[] args)
Initialize the specified proxy procedure, by calling the
execute method. |
boolean |
invoke(AppServerInvocationResult res,
java.lang.String id,
Agent.InvocationModes mode,
java.lang.String proc,
handle hProc,
java.lang.String kind,
java.lang.String modes,
java.lang.Object... args)
Invoke the specified external procedure as persistent and wait (or not) for it to complete.
|
boolean |
invoke(java.lang.Object[] requestInfo,
AppServerInvocationResult res,
java.lang.String id,
Agent.InvocationModes mode,
java.lang.String proc,
handle hProc,
java.lang.String kind,
java.lang.String modes,
java.lang.Object... args)
Invoke the specified external procedure as persistent and wait (or not) for it to complete.
|
AppServerInvocationResult |
invoke(java.lang.String id,
int requestId,
int timeout,
JavaInvokeConfig cfg)
Invoke the given Java method directly.
|
AppServerInvocationResult |
invoke(java.lang.String id,
int requestId,
long timeout,
character name,
java.lang.String resId,
boolean function,
boolean dynamicFunction,
boolean superCall,
boolean transactionDistinct,
java.lang.String modes,
java.lang.Object... args)
Invoke a remote external procedure, internal procedure or user-defined function.
|
AppServerInvocationResult |
invoke(java.lang.String id,
int requestId,
long timeout,
InvokeConfig cfg)
Invoke a remote external procedure, internal procedure or user-defined function.
|
private boolean |
invokeActivate(java.lang.String id,
AppServerInvocationResult invocationResult)
Invoke the activate procedure on the specified connection ID.
|
private void |
invokeDeactivate(java.lang.String id)
Invoke the deactivate procedure on the specified connection ID.
|
private static boolean |
invokeFailure(StopConditionException e)
Check if the given STOP condition is from an invoke failure.
|
private boolean |
invokeImpl(AppServerInvocationResult invocationResult,
java.lang.String id,
character name,
handle proc,
boolean function,
boolean dynamicFunction,
boolean superCall,
boolean transactionDistinct,
java.lang.String modes,
java.lang.Object... args)
Invoke an external procedure, internal procedure or user-defined function.
|
private boolean |
invokeJavaMethod(AppServerInvocationResult invocationResult,
java.lang.String id,
JavaInvokeConfig cfg)
Invoke the given Java method directly.
|
AppServerInvocationResult |
invokeMethod(java.lang.String id,
int requestId,
long timeout,
boolean returnValue,
character name,
java.lang.String resId,
java.lang.String modes,
java.lang.Object... args)
Invoke a method in a remotely instantiated class.
|
private void |
invokeMethodImpl(AppServerInvocationResult invocationResult,
java.lang.String id,
character name,
object<?> ref,
boolean returnValue,
java.lang.String modes,
java.lang.Object... args)
Invoke a legacy OO method.
|
AppServerInvocationResult |
invokePersistent(java.lang.String id,
int requestId,
long timeout,
character name,
boolean transactionDistinct,
java.lang.String modes,
java.lang.Object... args)
Invoke a remote external procedure, persistently.
|
private void |
invokePersistentImpl(AppServerInvocationResult invocationResult,
java.lang.String id,
character name,
handle hProc,
boolean transactionDistinct,
java.lang.String modes,
java.lang.Object... args)
Invoke a remote external procedure, persistently.
|
private static void |
invokeScoped(character name)
Invoke an external procedure with no parameters.
|
boolean |
isBound()
Check if the agent is bound to the connection.
|
(package private) boolean |
isPasoe()
Check if this appserver definition is for PASOE.
|
(package private) static boolean |
isWebServiceTokenInUse(java.lang.String token)
Check if the specified web service token is currently in use (there is an active API call on an agent).
|
void |
listen()
Start the agent and listen for commands.
|
AppServerInvocationResult |
newInstance(java.lang.String id,
int requestId,
long timeout,
character name,
java.lang.String modes,
java.lang.Object... args)
Create a new instance of the specified qualified class name.
|
(package private) ExternalProgramWrapper |
obtainProxy(java.lang.String id,
java.lang.String name)
Obtain a proxy for the given external procedure.
|
private java.lang.Object[] |
postProcessArguments(java.lang.String requesterModes,
java.lang.Object[] localArgs,
java.lang.Object[] requesterArgs)
Post-process the given arguments so that all OUTPUT and INPUT-OUTPUT arguments will be sent
back to the requester.
|
private void |
prepare()
Prepare this agent by setting some batch-processing related configuration.
|
private void |
preProcessArguments(java.lang.String requesterModes,
java.lang.Object[] args)
Preprocess the arguments sent by the requester so that they are converted to instances
compatible with the P2J runtime.
|
void |
removeProcedure(java.lang.String procId)
Remove the external procedure from this agent, as it was deleted.
|
void |
resetContext(Agent.InvocationModes mode)
Reset the context of this agent.
|
private void |
sendCommand(Agent.AgentCommand command)
Send the given command to this agent and return immediately.
|
(package private) void |
setConnectionId(java.lang.String id)
Set the current Agent's connection ID.
|
(package private) void |
setServerConnectionContext(java.lang.String connectionID,
java.lang.String serverConnectionContext)
Set the SERVER-CONNECTION-CONTEXT attribute of this session.
|
(package private) void |
stop()
Send a STOP condition to the request currently being executed on this connection.
|
void |
terminate()
Send the terminate command to this agent.
|
boolean |
terminated()
Check if this agent has been terminated.
|
void |
unbind()
Unbind the agent from the connection.
|
(package private) void |
validateRequest(java.lang.String id,
java.lang.String procId)
Validate the connection ID and procedure ID with this agent - the connection ID must be the same as
the
Agent.AgentRemoteProcedure.requesterConnectionId which created the remote procedure, and the
procedure ID must be registered with this agent. |
private void |
waitForCommand(AppServerInvocationResult result,
Agent.AgentCommand command)
Send the given command to the agent and wait for it to complete.
|
private void |
waitForCommand(AppServerInvocationResult result,
java.lang.String token,
Agent.AgentCommand command)
Send the given command to the agent and wait for it to complete.
|
private static final org.apache.commons.logging.Log LOG
private static final java.util.Set<java.lang.String> activeWebServiceTokens
private final java.util.Queue<Agent.AgentCommand> commands
private final AgentPool pool
private final Agent.AgentStopper stopperWorker
private final AssociatedThread stopper
private boolean terminated
private boolean bound
private java.lang.Thread thread
private final int agentId
private java.util.Map<java.lang.String,Agent.AgentRemoteProcedure> remoteProcedures
public Agent(AgentPool pool, int agentId)
pool
- The agent's pool.agentId
- The agent ID.static boolean isWebServiceTokenInUse(java.lang.String token)
token
- The web service token.true
if activeWebServiceTokens
contains this token.private static void invokeScoped(character name)
name
- The legacy 4GL name for the procedure/function.private static BaseDataType executeScoped(java.util.function.Supplier<BaseDataType> task)
task
- The task to execute.private void checkError(AppServerInvocationResult invocationResult, ErrorConditionException e)
invocationResult
- The result where to save the error.e
- The ERROR condition.private static boolean invokeFailure(StopConditionException e)
e
- The STOP condition.true
if the cause if this STOP is a NumberedException
known
to be produced by invoke failures.public int getAgentId()
agentId
.public void removeProcedure(java.lang.String procId)
procId
- The remote procedure ID.public void addProcedure(handle extProg)
extProg
- The external procedure.public ExternalProgramWrapper getProcedure(java.lang.String resId)
null
if is not registered with
remoteProcedures
.public boolean hasProcedure(java.lang.String resId)
resId
- The procedure ID.public java.lang.String getProcedureName(java.lang.String resId)
resId
- The procedure ID.public void listen()
public void resetContext(Agent.InvocationModes mode)
mode
- How to execute the reset context command - immediately or send it to the agent.public AppServerInvocationResult newInstance(java.lang.String id, int requestId, long timeout, character name, java.lang.String modes, java.lang.Object... args)
id
- The appserver connection id.requestId
- The ID of the request.timeout
- The maximum allowed time for this invocation to complete. In milliseconds.
Use 0
to disable the timeout.name
- The legacy qualified class name for the legacy class.modes
- A string representation of the modes of each parameter. May be null
args
- The constructor's arguments.AppServerInvocationResult
instance, which holds the code for the remote
object, all updated OUTPUT/INPUT-OUTPUT arguments and any returned value.public AppServerInvocationResult invokeMethod(java.lang.String id, int requestId, long timeout, boolean returnValue, character name, java.lang.String resId, java.lang.String modes, java.lang.Object... args)
id
- The appserver connection id.requestId
- The ID of the request.timeout
- The maximum allowed time for this invocation to complete. In milliseconds.
Use 0
to disable the timeout.returnValue
- Flag indicating if the return value is required.name
- The legacy 4GL name for the class method.resId
- The code of a remotely instantiated object in which to invoke the method.modes
- A string representation of the modes of each parameter. May be null
args
- The method's arguments.AppServerInvocationResult
instance with all updated OUTPUT/INPUT-OUTPUT
arguments and any returned value.public boolean invoke(AppServerInvocationResult res, java.lang.String id, Agent.InvocationModes mode, java.lang.String proc, handle hProc, java.lang.String kind, java.lang.String modes, java.lang.Object... args)
The "kind" parameter will always receive one of the "Startup", "Shutdown", "Connect" or "Disconnect" values.
res
- The instance where to save the invocation result. May be null
.id
- The appserver connection id.mode
- Flag indicating how to invoke the external procedure.proc
- The legacy 4GL name for the external procedure.hProc
- If not-null, the handle where to save this procedure.kind
- A helper text about this procedure.modes
- A string representation of the modes of each parameter. May be null
args
- The procedure's arguments.true
if no error was raised during the procedure invocation.public boolean invoke(java.lang.Object[] requestInfo, AppServerInvocationResult res, java.lang.String id, Agent.InvocationModes mode, java.lang.String proc, handle hProc, java.lang.String kind, java.lang.String modes, java.lang.Object... args)
The "kind" parameter will always receive one of the "Startup", "Shutdown", "Connect" or "Disconnect" values.
requestInfo
- The remote OerequestInfo
details, as set by
OerequestInfo.toArray()
.res
- The instance where to save the invocation result. May be null
.id
- The appserver connection id.mode
- Flag indicating how to invoke the external procedure.proc
- The legacy 4GL name for the external procedure.hProc
- If not-null, the handle where to save this procedure.kind
- A helper text about this procedure.modes
- A string representation of the modes of each parameter. May be null
args
- The procedure's arguments.true
if no error was raised during the procedure invocation.public AppServerInvocationResult invoke(java.lang.String id, int requestId, long timeout, InvokeConfig cfg)
id
- The appserver connection id.requestId
- The ID of the request.timeout
- The maximum allowed time for this invocation to complete. In milliseconds.
Use 0
to disable the timeout.cfg
- The invoke configuration.AppServerInvocationResult
instance with all updated OUTPUT/INPUT-OUTPUT
arguments and any returned value.public AppServerInvocationResult invoke(java.lang.String id, int requestId, long timeout, character name, java.lang.String resId, boolean function, boolean dynamicFunction, boolean superCall, boolean transactionDistinct, java.lang.String modes, java.lang.Object... args)
id
- The appserver connection id.requestId
- The ID of the request.timeout
- The maximum allowed time for this invocation to complete. In milliseconds.
Use 0
to disable the timeout.name
- The legacy 4GL name for the procedure/function.resId
- The code of a remote procedure in which to invoke the procedure or function.function
- true
if this is a function call.dynamicFunction
- true
if this is a DYNAMIC-FUNCTION call.superCall
- true
if this is a RUN SUPER or SUPER() call.transactionDistinct
- Flag indicating if the TRANSACTION DISTINCT clause is in effect.modes
- A string representation of the modes of each parameter. May be null
args
- The procedure's arguments.AppServerInvocationResult
instance with all updated OUTPUT/INPUT-OUTPUT
arguments and any returned value.public AppServerInvocationResult invoke(java.lang.String id, int requestId, int timeout, JavaInvokeConfig cfg)
All arguments are sent by references: if it was marked as an OUTPUT or INPUT-OUTPUT, any change to that instance will be reflected back to the caller.
id
- The appserver connection id.requestId
- The ID of the request.timeout
- The maximum allowed time for this invocation to complete. In milliseconds.
Use 0
to disable the timeout.cfg
- The configuration with the Java method to be invoked.AppServerInvocationResult
instance with all updated OUTPUT/INPUT-OUTPUT
arguments and any returned value.ExternalProgramWrapper obtainProxy(java.lang.String id, java.lang.String name)
id
- The appserver connection id.name
- A name of a remote external procedure.public AppServerInvocationResult initializeProxy(java.lang.String id, java.lang.String code, int requestId, boolean transactionDistinct, java.lang.String modes, java.lang.Object[] args)
execute
method.id
- The appserver connection id.code
- The external procedure id.requestId
- The ID of the request.transactionDistinct
- Flag indicating if the TRANSACTION DISTINCT clause is in effect.modes
- A string representation of the modes of each parameter. May be null
args
- The procedure's arguments.public AppServerInvocationResult invokePersistent(java.lang.String id, int requestId, long timeout, character name, boolean transactionDistinct, java.lang.String modes, java.lang.Object... args)
id
- The appserver connection id.requestId
- The ID of the request.timeout
- The maximum allowed time for this invocation to complete. In milliseconds.
Use 0
to disable the timeout.name
- The legacy 4GL name for the procedure.transactionDistinct
- Flag indicating if the TRANSACTION DISTINCT clause is in effect.modes
- A string representation of the modes of each parameter. May be null
args
- The procedure's arguments.AppServerInvocationResult
instance, which holds the code for the remote
procedure, all updated OUTPUT/INPUT-OUTPUT arguments and any returned value.public AppServerInvocationResult handleWebService(java.lang.String id, int requestId, long timeout, java.lang.Class<? extends WebHandler> handler, java.lang.String basepath, java.lang.String[] paths, java.lang.String token, java.lang.String target, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
id
- The appserver connection id.requestId
- The ID of the request.timeout
- The maximum allowed time for this invocation to complete. In milliseconds.
Use 0
to disable the timeout.handler
- The WebHandler
implementation.basepath
- The service basepath.paths
- The split paths for this handler.token
- When not null, it represents the token of a FWD context created for an authenticated and
authorized web service call. The API call will be performed in that context.target
- The request original target.request
- The Jetty request.response
- The Jetty response.AppServerInvocationResult
instance with any error throw during the web service
processing.public void terminate()
public boolean terminated()
public void bind()
public void unbind()
public boolean isBound()
public void deleteProcedures()
procedures
.public void deleteProcedure(java.lang.String resId, java.lang.String token)
resId
- The resource ID for this procedure.token
- When not null, it represents the token of a FWD context created for an authenticated and
authorized web service call. The API call will be performed in that context.public void deleteObject(java.lang.String resId)
resId
- The resource ID for this legacy object.void setConnectionId(java.lang.String id)
id
- The connection ID.void validateRequest(java.lang.String id, java.lang.String procId)
Agent.AgentRemoteProcedure.requesterConnectionId
which created the remote procedure, and the
procedure ID must be registered
with this agent.id
- The connection ID to validate.procId
- The procedure ID to validate.java.lang.IllegalArgumentException
- If the connection ID and procedure ID are not for this agent, as the client performs an illegal
request.AppServerOperatingMode getOperatingMode()
boolean hasProcedures(java.lang.String id)
id
- The connection ID.boolean isPasoe()
void stop()
java.lang.IllegalStateException
- If the appserver is not connected.java.lang.String getServerConnectionContext(java.lang.String connectionID)
connectionID
- The connection ID for this appserver.void setServerConnectionContext(java.lang.String connectionID, java.lang.String serverConnectionContext)
connectionID
- The connection ID for this appserver.serverConnectionContext
- The attribute's value.private java.lang.Integer getSessionId()
null
.private java.lang.Integer getThreadId()
null
.private void invokeMethodImpl(AppServerInvocationResult invocationResult, java.lang.String id, character name, object<?> ref, boolean returnValue, java.lang.String modes, java.lang.Object... args)
invocationResult
- The result where to save the arguments and any return value.id
- The appserver connection id.name
- The legacy 4GL name for the OO method.ref
- The object where to invoke the method.returnValue
- Flag indicating if this OO method call must return a value.modes
- The method argument's modes, at the caller.args
- The arguments.private void invokePersistentImpl(AppServerInvocationResult invocationResult, java.lang.String id, character name, handle hProc, boolean transactionDistinct, java.lang.String modes, java.lang.Object... args)
invocationResult
- The result to be sent back to the remote side.id
- The appserver connection id.name
- The legacy 4GL name for the procedure.hProc
- The handle where to save the persistent procedure.transactionDistinct
- Flag indicating if the TRANSACTION DISTINCT clause is in effect.modes
- A string representation of the modes of each parameter. May be null
args
- The procedure's arguments.private boolean invokeImpl(AppServerInvocationResult invocationResult, java.lang.String id, character name, handle proc, boolean function, boolean dynamicFunction, boolean superCall, boolean transactionDistinct, java.lang.String modes, java.lang.Object... args)
invocationResult
- The result where to save the arguments and any return value.id
- The appserver connection id.name
- The legacy 4GL name for the procedure/function.proc
- The external procedure in which to invoke the procedure or function.function
- true
if this is a function call.dynamicFunction
- true
if this is a DYNAMIC-FUNCTION call.superCall
- true
if this is a RUN SUPER or SUPER() call.transactionDistinct
- Flag indicating if the TRANSACTION DISTINCT clause is in effect.modes
- A string representation of the modes of each parameter. May be null
args
- The procedure's arguments.private boolean invokeJavaMethod(AppServerInvocationResult invocationResult, java.lang.String id, JavaInvokeConfig cfg)
All arguments are sent by references: if it was marked as an OUTPUT or INPUT-OUTPUT, any change to that instance will be reflected back to the caller.
invocationResult
- The instance where to save the method's returned value or any error.id
- The appserver connection id.cfg
- The configuration with the Java method to be invoked.true
if no error was raised during the method invocation.private void invokeDeactivate(java.lang.String id)
id
- The appserver connection id.private boolean invokeActivate(java.lang.String id, AppServerInvocationResult invocationResult)
id
- The appserver connection id.invocationResult
- The result where to save the arguments and any return value.private void sendCommand(Agent.AgentCommand command)
command
- The command to be executed.private void waitForCommand(AppServerInvocationResult result, java.lang.String token, Agent.AgentCommand command)
result
- The instance where to place the command result.token
- When not null, it represents the token of a FWD context created for an authenticated and
authorized web service call. The API call will be performed in that context.command
- The command to be executed.private void waitForCommand(AppServerInvocationResult result, Agent.AgentCommand command)
result
- The instance where to place the command result.command
- The command to be executed.private void preProcessArguments(java.lang.String requesterModes, java.lang.Object[] args)
TableWrapper
instancesmemptr
instances from all MemoryBuffer
instancesrequesterModes
- The parameter modes sent by the requester.args
- The argument list sent by the requester. The elements in this array will be
changed as needed.private java.lang.Object[] postProcessArguments(java.lang.String requesterModes, java.lang.Object[] localArgs, java.lang.Object[] requesterArgs)
TableWrapper
instancesmemptr
instances to MemoryBuffer
instancesrequesterModes
- The parameter modes sent by the requester.localArgs
- The argument list after the call has been performed.requesterArgs
- The argument list sent by the requester.private void prepare()