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 java.util.Set<Agent> |
all
All started agents.
|
private AppServerDefinition |
appDef
The appserver definition.
|
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.
|
private java.util.Map<java.lang.String,java.util.Map<java.lang.String,PersistentProcedure>> |
persistentProcedures
The remote persistent procedures exposed as proxy procedures to the requester.
|
private java.util.Map<java.lang.Object,Agent> |
procsByAgent
Identify the procedure's parent agent.
|
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) abstract Agent |
acquireAgent(java.lang.String id,
java.lang.String code)
Acquire a new agent from the pool to handle requests incoming via the given connection ID.
|
(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)
Establish a new appserver connection.
|
(package private) void |
deleteProcedure(PersistentProcedure proc)
Delete the specified procedure, under the Agent's context.
|
(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) 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) PersistentProcedure |
getProcedure(java.lang.String id,
java.lang.String procId)
Get the persistent procedure associated with the given ID; this returns a non-null instance
only if the procedure was not deleted from the context specified by the connection ID.
|
(package private) java.lang.String |
getPropath()
Get the appserver's propath.
|
(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(PersistentProcedure proc)
Check if the given persistent procedure was started as a remote procedure with the appserver
associated with this pool.
|
(package private) boolean |
isEmpty()
Check if this pool is empty.
|
(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) PersistentProcedure |
removeProcedure(java.lang.String id,
java.lang.String procId)
Remove the specified persistent procedure.
|
(package private) void |
saveProcedure(java.lang.String id,
Agent agent,
java.lang.String procId,
PersistentProcedure proc)
Save the given persistent procedure and associate it with the given connection ID.
|
(package private) void |
setExports(character exports)
Set the exports for this appserver.
|
(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.Set<Agent> all
private final java.util.Map<java.lang.String,java.util.Map<java.lang.String,PersistentProcedure>> persistentProcedures
private final java.util.Map<java.lang.Object,Agent> procsByAgent
private final AppServerDefinition appDef
private java.lang.String exports
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)
id
- The connection ID.code
- The code of a persistent external procedure to which the agent is associated. May
be null
.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.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)
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.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.void deleteProcedure(PersistentProcedure proc)
proc
- A persistent procedure.AppServerOperatingMode getOperatingMode()
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()
void saveProcedure(java.lang.String id, Agent agent, java.lang.String procId, PersistentProcedure proc)
id
- The connection ID.agent
- The agent used to instantiate the persistent procedure.procId
- The procedure's ID.proc
- The persistent procedure.boolean hasProcedure(PersistentProcedure proc)
proc
- The persistent procedure.PersistentProcedure removeProcedure(java.lang.String id, java.lang.String procId)
id
- The connection ID.procId
- The procedure ID.PersistentProcedure getProcedure(java.lang.String id, java.lang.String procId)
id
- The connection ID.procId
- The procedure ID.null
if none found.void trimAgents()
AppServerDefinition.getMinAgents()
as possible.Agent getFromMainPool()
null
.null
if all agents are busy.