public class AppServerManager
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
AppServerManager.RemoteAppServer
Container for the information needed to identify an appserver, by the data configured at the
CONNECT statement's options.
|
private static class |
AppServerManager.WorkArea
Container for agent-related info.
|
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.String,java.util.Set<Agent>> |
activeAgents
For each connection ID, this map includes the Agents which are currently executing requests.
|
private static java.util.Map<java.lang.String,AgentPool> |
appServers
Map of appservers to their associated pool, managed by this P2J server.
|
private static java.util.Map<java.lang.String,java.util.Set<java.lang.Integer>> |
authorizedSessions
A map of authorized sessions which can access the given connection ID.
|
private static ContextLocal<AppServerManager.WorkArea> |
local
This context-local data is used only to determine which appserver is authenticated and its
mode (manager or agent).
|
private static java.lang.Object |
lock
Lock used to sync access to
requests and stoppedRequests . |
private static org.apache.commons.logging.Log |
LOG
Logger
|
private static java.util.Map<java.lang.String,java.lang.String> |
nameServerDefaults
Provides a map of default appService names, for each name server.
|
private static int |
nextId
The next request ID.
|
private static java.util.List<AppServerManager.RemoteAppServer> |
remoteAppServers
The list of the known, remote, appservers.
|
private static java.util.Map<java.lang.Integer,Agent> |
requests
Map of executing requests to their associated Agents.
|
private static java.util.Set<java.lang.Integer> |
stoppedRequests
Set of stopped requests.
|
private static java.util.Map<java.lang.String,java.lang.String> |
subjectToAppserver
Map of subject IDs to appserver names.
|
Constructor and Description |
---|
AppServerManager() |
Modifier and Type | Method and Description |
---|---|
(package private) static void |
addActiveAgent(java.lang.String connectionId,
Agent agent)
Collect an
Agent as is currently executing a task on the specified connection ID. |
static AppServerInvocationResult |
connect(java.lang.String appServer,
boolean sessionFree,
java.lang.String user,
java.lang.String pwd,
java.lang.String serverInfo)
Establish a new appserver connection.
|
private static boolean |
connected(java.lang.String connectionId)
Check if the given connection ID is still connected.
|
static boolean |
deleteProcedure(java.lang.String id,
java.lang.String resId)
Delete the remote procedure, specified by the resource id.
|
(package private) static void |
deregisterRequest(int requestId)
Deregister the specified request from the
requests map. |
static void |
disconnect(java.lang.String id)
Disconnect the appserver connection, with the given ID.
|
static logical |
export(character procList)
Method that specifies the remote procedures the client can execute from the AppServer
session.
|
static logical |
export(java.lang.String procList)
Method that specifies the remote procedures the client can execute from the AppServer
session.
|
private static AgentPool |
getAgentPool(java.lang.String connectionId)
Get the agent pool for the given connection ID.
|
private static AgentPool |
getAgentPoolBySubject(java.lang.String subjectId)
Get the agent pool for the given subject ID.
|
(package private) static AgentPool |
getAgentPoolForAppserver(java.lang.String appServer)
Get the agent pool for the given appserver.
|
private static java.lang.String |
getAppserverBySubject(java.lang.String subjectId)
Get the appserver name started by the given subject ID.
|
static character |
getProcedureName(java.lang.String id,
java.lang.String resId)
Get the name of the remote procedure, specified by the resource ID.
|
static java.lang.String |
getServerConnectionId()
Get the value of SESSION:SERVER-CONNECTION-ID attribute.
|
static character |
getServerOperatingMode()
Method implementation for getting the SERVER-OPERATING-MODE attribute of the session handle.
|
(package private) static boolean |
hasProcedure(PersistentProcedure pp)
Check if current running appserver knows the given procedure.
|
static AppServerInvocationResult |
initializeProxy(java.lang.String id,
int requestId,
java.lang.String code,
boolean transactionDistinct,
java.lang.String modes,
java.lang.Object[] args)
Initialize the specified proxy procedure, by calling the
execute method. |
private static void |
initRemoteAppServers()
Init the data related to remote appservers, from the directory.
|
static AppServerInvocationResult |
invoke(java.lang.String id,
int requestId,
long timeout,
character name,
java.lang.String procID,
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.
|
static 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.
|
static boolean |
isRemote()
Indicates if the session is an AppServer session or not.
|
static java.lang.String |
lookupP2JAccount(java.lang.String appService,
java.lang.String host,
java.lang.String serviceName,
int port,
boolean directConnect)
Search through the known remote appservers and determine the P2J account configured for this
appserver connection request.
|
static java.net.InetSocketAddress |
lookupP2JServer(java.lang.String appService,
java.lang.String host,
java.lang.String serviceName,
int port,
boolean directConnect)
Search through the known remote appservers and determine the address of the P2J server on
which the target appserver is running.
|
private static AppServerManager.RemoteAppServer |
lookupRemoteAppServer(java.lang.String appService,
java.lang.String host,
java.lang.String serviceName,
int port,
boolean directConnect)
Search through and determine the remote appserver associated with the given options.
|
static java.lang.String |
lookupTargetAppserver(java.lang.String appService,
java.lang.String host,
java.lang.String serviceName,
int port,
boolean directConnect)
Search through the known remote appservers and determine the name of the appserver
configured for this connection request.
|
static java.lang.String |
obtainProxy(java.lang.String id,
java.lang.String name)
Obtain a proxy for the given external procedure.
|
(package private) static boolean |
registerRequest(int requestId,
Agent a)
Associate the specified thread with the specified request, in the
requests map. |
(package private) static void |
removeActiveAgent(java.lang.String connectionId,
Agent agent)
Remove the
Agent as it finished executing a task on the specified connection ID. |
static void |
sendStop(java.lang.String id)
Send a STOP condition to the request currently being executed on the specified connection.
|
static void |
sendStop(java.lang.String id,
int requestId)
Send the STOP condition to the request running with the specified ID.
|
(package private) static void |
setConnectionId(java.lang.String id)
Set the current Agent's connection ID.
|
static boolean |
startAppServer()
Start this P2J client as an appserver agent or manager.
|
static int |
uniqueId()
Obtain an unique ID from the remote side.
|
private static final org.apache.commons.logging.Log LOG
private static java.util.Map<java.lang.String,java.lang.String> nameServerDefaults
private static java.util.List<AppServerManager.RemoteAppServer> remoteAppServers
private static final java.util.Map<java.lang.String,java.lang.String> subjectToAppserver
private static final java.util.Map<java.lang.String,AgentPool> appServers
private static final java.util.Map<java.lang.String,java.util.Set<java.lang.Integer>> authorizedSessions
private static final java.util.Map<java.lang.Integer,Agent> requests
private static final java.util.Set<java.lang.Integer> stoppedRequests
private static final java.util.Map<java.lang.String,java.util.Set<Agent>> activeAgents
private static final java.lang.Object lock
requests
and stoppedRequests
.private static int nextId
private static ContextLocal<AppServerManager.WorkArea> local
public static int uniqueId()
public static java.lang.String obtainProxy(java.lang.String id, java.lang.String name)
id
- The appserver connection id.name
- A name of a remote external procedure.public static AppServerInvocationResult initializeProxy(java.lang.String id, int requestId, java.lang.String code, boolean transactionDistinct, java.lang.String modes, java.lang.Object[] args)
execute
method.id
- The appserver connection id.requestId
- The ID of the request.code
- The code of a persistent external procedure to which the agent is associated. May
be null
.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 static void sendStop(java.lang.String id, int requestId)
id
- The appserver connection id.requestId
- The ID of the request.public static void sendStop(java.lang.String id)
id
- The appserver connection id.public static logical export(java.lang.String procList)
procList
- The list of procedure and name-patterns separated by comma.true
if the method succeeded.public static logical export(character procList)
procList
- The list of procedure and name-patterns separated by comma.true
if the method succeeded.public static character getServerOperatingMode()
Possible values:
public static boolean isRemote()
true
if the current session is an AppServer session or false
otherwise.public static java.lang.String getServerConnectionId()
public static character getProcedureName(java.lang.String id, java.lang.String resId)
id
- The appserver connection id.resId
- The ID of a remote procedure.getAgentPool(String)
public static boolean deleteProcedure(java.lang.String id, java.lang.String resId)
id
- The appserver connection id.resId
- The ID of a remote procedure which needs to be deleted.true
if the remote procedure was deleted.getAgentPool(String)
public static AppServerInvocationResult connect(java.lang.String appServer, 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.
appServer
- The name of the target 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.public static void disconnect(java.lang.String id)
id
- The connection ID to disconnect.getAgentPool(String)
public static AppServerInvocationResult invoke(java.lang.String id, int requestId, long timeout, character name, java.lang.String procID, 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.procID
- 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.getAgentPool(String)
public static 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.getAgentPool(String)
public static java.net.InetSocketAddress lookupP2JServer(java.lang.String appService, java.lang.String host, java.lang.String serviceName, int port, boolean directConnect)
appService
- The appserver's service name (the -AppService connect parameter).host
- The -H connect parameter.serviceName
- The network service name, specified by the -S parameter.port
- The network port, specified by the -S parameter.directConnect
- Flag indicating this is a direct connect (the -DirectConnect parameter).public static java.lang.String lookupP2JAccount(java.lang.String appService, java.lang.String host, java.lang.String serviceName, int port, boolean directConnect)
appService
- The appserver's service name (the -AppService connect parameter).host
- The -H connect parameter.serviceName
- The network service name, specified by the -S parameter.port
- The network port, specified by the -S parameter.directConnect
- Flag indicating this is a direct connect (the -DirectConnect parameter).public static java.lang.String lookupTargetAppserver(java.lang.String appService, java.lang.String host, java.lang.String serviceName, int port, boolean directConnect)
appService
- The appserver's service name (the -AppService connect parameter).host
- The -H connect parameter.serviceName
- The network service name, specified by the -S parameter.port
- The network port, specified by the -S parameter.directConnect
- Flag indicating this is a direct connect (the -DirectConnect parameter).public static boolean startAppServer()
true
if this was an appserver. On false
, normal P2J
conversation mode will be started.static void setConnectionId(java.lang.String id)
id
- The connection ID.static boolean hasProcedure(PersistentProcedure pp)
pp
- A persistent procedure instance.true
if the persistent procedure is known to the current running
appserver.static AgentPool getAgentPoolForAppserver(java.lang.String appServer)
appServer
- The appserver name.static void addActiveAgent(java.lang.String connectionId, Agent agent)
Agent
as is currently executing a task on the specified connection ID.connectionId
- The connection ID.agent
- The agent instance.static void removeActiveAgent(java.lang.String connectionId, Agent agent)
Agent
as it finished executing a task on the specified connection ID.connectionId
- The connection ID.agent
- The agent instance.static boolean registerRequest(int requestId, Agent a)
requests
map.requestId
- The request ID.a
- The agent executing the request.true
if a STOP was not already received for this request.static void deregisterRequest(int requestId)
requests
map.requestId
- The request ID.private static AgentPool getAgentPool(java.lang.String connectionId)
connectionId
- The connection ID.private static boolean connected(java.lang.String connectionId)
connectionId
- The connection ID.true
if the connection is still alive.private static AppServerManager.RemoteAppServer lookupRemoteAppServer(java.lang.String appService, java.lang.String host, java.lang.String serviceName, int port, boolean directConnect)
appService
- The appserver's service name (the -AppService connect parameter).host
- The -H connect parameter.serviceName
- The network service name, specified by the -S parameter.port
- The network port, specified by the -S parameter.directConnect
- Flag indicating this is a direct connect (the -DirectConnect parameter).private static void initRemoteAppServers()
private static AgentPool getAgentPoolBySubject(java.lang.String subjectId)
subjectId
- The subject ID.private static java.lang.String getAppserverBySubject(java.lang.String subjectId)
subjectId
- The subject ID used to start an appserver.