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 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 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 ExternalProgramWrapper |
extProg
An instance of an external program to which this agent is dedicated.
|
private static org.apache.commons.logging.Log |
LOG
Logger
|
private AgentPool |
pool
The agent's pool.
|
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.
|
Constructor and Description |
---|
Agent(AgentPool pool)
Build a new agent and associate it with the given pool.
|
Modifier and Type | Method and Description |
---|---|
void |
bind()
Bind the agent to the connection.
|
java.lang.String |
connect()
Establish a new connection and call the CONNECT procedure.
|
void |
deleteProcedure(PersistentProcedure proc)
Delete the specified procedure, under the Agent's context.
|
ExternalProgramWrapper |
getProcedure()
Get the external procedure associated with this agent.
|
AppServerInvocationResult |
initializeProxy(java.lang.String id,
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.
|
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.
|
private static boolean |
invokeFailure(StopConditionException e)
Check if the given STOP condition is from an invoke failure.
|
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 static void |
invokeScoped(java.lang.String id,
character name)
Invoke an external procedure with no parameters.
|
private static BaseDataType |
invokeScoped(java.lang.String id,
character name,
handle proc,
boolean function,
boolean dynamicFunction,
boolean superCall,
boolean transactionDistinct,
character exports,
java.lang.Runnable popTask,
java.lang.String modes,
java.lang.Object... args)
Invoke an external procedure, internal procedure or user-defined function.
|
boolean |
isBound()
Check if the agent is bound to the connection.
|
void |
listen()
Start the agent and listen for commands.
|
(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 localModes,
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 localModes,
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 |
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.
|
void |
setProcedure(ExternalProgramWrapper extProg)
Set the external procedure associated with this agent.
|
(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.
|
private void |
waitForCommand(AppServerInvocationResult result,
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 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 ExternalProgramWrapper extProg
public Agent(AgentPool pool)
pool
- The agent's pool.private static void invokeScoped(java.lang.String id, character name)
id
- The appserver connection id.name
- The legacy 4GL name for the procedure/function.private static BaseDataType invokeScoped(java.lang.String id, character name, handle proc, boolean function, boolean dynamicFunction, boolean superCall, boolean transactionDistinct, character exports, java.lang.Runnable popTask, java.lang.String modes, java.lang.Object... args)
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.exports
- The appserver's exports.popTask
- A task to be execued before the global scope is popped.modes
- A string representation of the modes of each parameter. May be null
args
- The procedure's arguments.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 void setProcedure(ExternalProgramWrapper extProg)
extProg
- The external procedure. May be null
.public ExternalProgramWrapper getProcedure()
procedure
associated with this agent or null
if
no procedure is associated.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 java.lang.String connect() throws NumberedException
NumberedException
- If a connection could not be established.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 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.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, int requestId, boolean transactionDistinct, java.lang.String modes, java.lang.Object[] args)
execute
method.id
- The appserver connection 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 void terminate()
public boolean terminated()
public void bind()
public void unbind()
public boolean isBound()
public void deleteProcedure(PersistentProcedure proc)
proc
- A persistent procedure.void stop()
java.lang.IllegalStateException
- If the appserver is not connected.private void sendCommand(Agent.AgentCommand command)
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 localModes, java.lang.String requesterModes, java.lang.Object[] args)
TableWrapper
instancesmemptr
instances from all MemoryBuffer
instanceslocalModes
- The parameter modes as defined at the external procedure or internal entry.requesterModes
- 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 localModes, java.lang.String requesterModes, java.lang.Object[] localArgs, java.lang.Object[] requesterArgs)
TableWrapper
instancesmemptr
instances to MemoryBuffer
instanceslocalModes
- The parameter modes as defined at the external procedure or internal entry.requesterModes
- 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()