abstract class AgentPool
extends java.lang.Object
newConnection()
call will return a:
AgentPool.BoundPool
for State-reset and State-aware modes.AgentPool.UnboundPool
for State-free and Stateless modes.mainPool
as connection or procedure requests are incoming
and put back in the pool only after the connection terminates or it becomes unbound.Modifier and Type | Class and Description |
---|---|
(package private) static class |
AgentPool.BoundPool
Class implementing the behavior for STATE-RESET and STATE-AWARE operating modes.
|
(package private) static class |
AgentPool.UnboundPool
Class implementing the behavior for STATE-FREE and STATELESS operating modes.
|
Modifier and Type | Field and Description |
---|---|
private int |
agentIdGenerator
The generator for Agent IDs.
|
private java.util.Map<java.lang.Integer,Agent> |
agents
The map of agents.
|
private java.util.Set<Agent> |
all
All started agents.
|
private AppServerDefinition |
appDef
The appserver definition.
|
private java.util.Set<java.lang.String> |
disabledLegacyErrors
Set of connection IDs which can't throw legacy OO errors on the remote side.
|
private java.lang.String |
exports
The EXPORTS for this appserver.
|
private static java.util.Map<java.lang.String,java.lang.String> |
idsToAppserver
Map of connection IDs to appserver name.
|
private static org.apache.commons.logging.Log |
LOG
Logger.
|
private java.util.Set<Agent> |
mainPool
The pool of agents.
|
protected java.util.Map<java.lang.Object,Agent> |
persistentProcedures
The remote persistent procedures exposed as proxy procedures to the requester.
|
private java.util.Map<java.lang.String,java.lang.String> |
serverConnectionContext
The value of SESSSION:SERVER-CONNECTION-CONTEXT set for each connection.
|
Modifier | Constructor and Description |
---|---|
private |
AgentPool(AppServerDefinition def)
Build a new agent pool, for the specified appserver.
|
Modifier and Type | Method and Description |
---|---|
(package private) Agent |
acquireAgent(java.lang.String id)
Acquire a new agent from the pool to handle requests incoming via the given connection ID.
|
(package private) abstract Agent |
acquireAgent(java.lang.String id,
java.lang.String code,
int agentId)
Acquire a new agent from the pool to handle requests incoming via the given connection ID.
|
(package private) void |
addProcedure(java.lang.Object referent,
Agent agent)
Register the given persistent procedure with the
Agent which created it. |
(package private) AppServerInvocationResult |
connect(java.util.concurrent.atomic.AtomicBoolean sessionTerminated,
java.lang.String subjectId,
boolean sessionFree,
java.lang.String user,
java.lang.String pwd,
java.lang.String serverInfo,
java.lang.Object[] requestInfo)
Establish a new appserver connection.
|
(package private) void |
disableLegacyErrors(java.lang.String id)
Disable legacy OO errors thrown on this connection.
|
(package private) void |
disconnect(java.lang.String id)
Disconnect the appserver connection, with the given ID.
|
(package private) java.lang.String |
getActivate()
Get the activate procedure for the appserver handled by this pool.
|
(package private) Agent |
getAgent(int agentId)
Get the agent for the given ID.
|
(package private) static java.lang.String |
getAppserver(java.lang.String connectionId)
Get the appserver name used to established the given connection.
|
(package private) java.lang.String |
getDeactivate()
Get the deactivate procedure for the appserver handled by this pool.
|
(package private) character |
getExports()
Get the exports for this appserver.
|
(package private) Agent |
getFromMainPool()
Extract an agent from the main pool; if non available, attempt to start one.
|
(package private) java.lang.String |
getName()
Get the name of the appserver handled by this pool.
|
(package private) AppServerOperatingMode |
getOperatingMode()
Get the operating mode for this appserver.
|
(package private) java.lang.String |
getPropath()
Get the appserver's propath.
|
(package private) java.lang.String |
getServerConnectionContext(java.lang.String connectionID)
Get the SERVER-CONNECTION-CONTEXT attribute of the specified connection.
|
(package private) java.lang.String |
getShutdown()
Get the shutdown procedure for the appserver handled by this pool.
|
(package private) java.lang.String |
getStartup()
Get the startup procedure for the appserver handled by this pool.
|
(package private) java.lang.String |
getStartupParameter()
Get the startup parameters for the appserver handled by this pool.
|
(package private) boolean |
hasProcedure(java.lang.Object referent)
Check if the given persistent procedure was started as a remote procedure with the appserver associated
with this pool.
|
(package private) boolean |
isDisabledLegacyErrors(java.lang.String id)
Check if the given connection ID should suppress legacy OO errors.
|
(package private) boolean |
isEmpty()
Check if this pool is empty.
|
(package private) boolean |
isPasoe()
Check if this appserver definition is for PASOE.
|
(package private) abstract java.lang.String |
newConnection()
Establish a new connection.
|
(package private) static AgentPool |
newPool(java.lang.String appServer)
Instantiate a new agent pool for the given appserver, based on the operating mode.
|
(package private) java.lang.String |
nextId()
Get the next connection ID.
|
(package private) void |
poolAgent(Agent agent,
boolean newlyCreated)
Add an agent back to the
mainPool . |
(package private) abstract void |
releaseAgent(java.lang.String id,
Agent agent)
Release the given agent and place it back in the pool.
|
(package private) void |
removeAgent(Agent agent)
Remove the given agent entirely from the pool.
|
(package private) void |
removeProcedure(java.lang.String id,
java.lang.Object referent)
De-register the persistent procedure from
persistentProcedures . |
(package private) void |
setExports(character exports)
Set the exports for this appserver.
|
(package private) void |
setServerConnectionContext(java.lang.String connectionID,
java.lang.String serverConnectionContext)
Set the SERVER-CONNECTION-CONTEXT attribute of the specifiedconnection.
|
(package private) int |
size()
Get the pool size.
|
(package private) void |
start()
Start listening for appserver-related commands.
|
(package private) void |
terminateAll()
Send the terminate command to all agents in this pool.
|
(package private) void |
terminateConnection(java.lang.String id,
boolean running)
Terminate the connection with the given ID.
|
(package private) void |
trimAgents()
Trim the running agents so the pool size is as close to
AppServerDefinition.getMinAgents() as possible. |
private static final org.apache.commons.logging.Log LOG
private static final java.util.Map<java.lang.String,java.lang.String> idsToAppserver
private final java.util.Set<Agent> mainPool
private final java.util.Map<java.lang.Integer,Agent> agents
private final java.util.Map<java.lang.String,java.lang.String> serverConnectionContext
protected final java.util.Map<java.lang.Object,Agent> persistentProcedures
private final java.util.Set<Agent> all
private final java.util.Set<java.lang.String> disabledLegacyErrors
private final AppServerDefinition appDef
private java.lang.String exports
private int agentIdGenerator
private AgentPool(AppServerDefinition def)
def
- The appserver definition.static java.lang.String getAppserver(java.lang.String connectionId)
connectionId
- The connection ID.static AgentPool newPool(java.lang.String appServer)
appServer
- The appserver's name.java.lang.IllegalArgumentException
- If the operating mode can not be resolved to one of AppServerOperatingMode
constants.abstract Agent acquireAgent(java.lang.String id, java.lang.String code, int agentId) throws NumberedException
id
- The connection ID.code
- The code of a persistent external procedure to which the agent is associated. May
be null
.agentId
- The agent ID which created the given procedure code, a negative number means the procedure
code will not be used.NumberedException
- If there was no agent available.abstract void releaseAgent(java.lang.String id, Agent agent)
id
- The connection ID.agent
- The agent which needs to be released.abstract java.lang.String newConnection() throws NumberedException
NumberedException
- If the connection could not be established.void disableLegacyErrors(java.lang.String id)
id
- The appserver connection id.boolean isDisabledLegacyErrors(java.lang.String id)
id
- The appserver connection id.Agent acquireAgent(java.lang.String id) throws NumberedException
id
- The connection ID.NumberedException
- If there was no agent available.Agent getAgent(int agentId)
agentId
- The agent ID.java.lang.String nextId()
character getExports()
void setExports(character exports)
exports
- The appserver's exports.java.lang.String getName()
java.lang.String getPropath()
java.lang.String getStartup()
java.lang.String getStartupParameter()
java.lang.String getShutdown()
java.lang.String getActivate()
java.lang.String getDeactivate()
AppServerInvocationResult connect(java.util.concurrent.atomic.AtomicBoolean sessionTerminated, java.lang.String subjectId, boolean sessionFree, java.lang.String user, java.lang.String pwd, java.lang.String serverInfo, java.lang.Object[] requestInfo)
user
, pwd
and serverInfo
parameters will be passed.
The appserver connection must be configured to start under the given P2J-level subject ID.
sessionTerminated
- A special var to inform us if the session has been terminated. The session state
can't be invoked directly from here, as a deadlock might occur.subjectId
- The subject ID associated with this appserver.sessionFree
- Flag indicating if the connection request is for a session-free operating mode.user
- The first parameter to pass to the connect procedure, if any.pwd
- The second parameter to pass to the connect procedure, if any.serverInfo
- The third parameter to pass to the connect procedure, if any.requestInfo
- The remote OerequestInfo
details, as set by
OerequestInfo.toArray()
.AppServerInvocationResult
instance with any result or caught errors.void disconnect(java.lang.String id)
id
- The connection ID to disconnect.void start()
void terminateAll()
void terminateConnection(java.lang.String id, boolean running)
id
- The connection ID.running
- Flag indicating the Agent is already processing a command.AppServerOperatingMode getOperatingMode()
boolean isPasoe()
void poolAgent(Agent agent, boolean newlyCreated)
mainPool
.agent
- The agent to add back to the pool.newlyCreated
- When this flag is true
, the agent is added to the global
pool too.boolean isEmpty()
true
if the pool is empty, false
otherwise.void removeAgent(Agent agent)
agent
- The agent which was terminated and needs to be removed.int size()
boolean hasProcedure(java.lang.Object referent)
referent
- The persistent procedure.void addProcedure(java.lang.Object referent, Agent agent)
Agent
which created it.referent
- The persistent procedure.agent
- The agent which created the persistent procedure.void removeProcedure(java.lang.String id, java.lang.Object referent)
persistentProcedures
.id
- The connection ID.referent
- The persistent procedure.void trimAgents()
AppServerDefinition.getMinAgents()
as possible.Agent getFromMainPool()
null
.null
if all agents are busy.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.