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,
java.lang.Object[] requestInfo)
Establish a new appserver connection.
|
private static boolean |
connected(java.lang.String connectionId)
Check if the given connection ID is still connected.
|
static boolean |
deleteObject(java.lang.String id,
java.lang.String resId,
int agentId)
Delete the remote object, specified by the resource ID.
|
static boolean |
deleteProcedure(java.lang.String id,
java.lang.String resId,
int agentId,
java.lang.String token)
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 |
disableLegacyErrors(java.lang.String id)
Disable legacy OO errors thrown on this connection.
|
static void |
disconnect(AgentPool pool,
java.lang.String id)
Disconnect the appserver connection, with the given ID.
|
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.
|
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 int |
getNumberOfAgentsInPool(java.lang.String appServer)
Get the number of agents started for that appserver.
|
static character |
getProcedureName(java.lang.String id,
java.lang.String resId,
int agentId)
Get the name of the remote procedure, specified by the resource ID.
|
static java.lang.String |
getServerConnectionContext()
Get the SERVER-CONNECTION-CONTEXT attribute of this session.
|
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.
|
static 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.
|
(package private) static boolean |
hasProcedure(java.lang.Object referent)
Check if current running appserver knows the given procedure.
|
static AppServerInvocationResult |
initializeProxy(java.lang.String id,
int requestId,
java.lang.String code,
int agentId,
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,
int timeout,
JavaInvokeConfig cfg)
Invoke the given Java method directly.
|
static AppServerInvocationResult |
invoke(java.lang.String id,
int requestId,
long timeout,
character name,
java.lang.String procID,
int agentId,
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 |
invoke(java.lang.String id,
int requestId,
long timeout,
InvokeConfig cfg)
Invoke a remote external procedure, internal procedure or user-defined function.
|
static AppServerInvocationResult |
invokeMethod(java.lang.String id,
int requestId,
long timeout,
boolean returnValue,
character name,
java.lang.String resId,
int agentId,
java.lang.String modes,
java.lang.Object... args)
Invoke a method in a remotely instantiated class.
|
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 |
isDisabledLegacyErrors()
Check if the current
connection ID should suppress legacy OO errors. |
static boolean |
isPasoe()
Check if this FWD context is running an Agent under PASOE compatibility.
|
static boolean |
isRemote()
Indicates if the session is an AppServer session or not.
|
static logical |
isServerConnectionBound()
Get the SERVER-CONNECTION-BOUND attribute of this session.
|
static logical |
isServerConnectionBoundRequest()
Get the SERVER-CONNECTION-BOUND-REQUEST attribute of this session.
|
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).
|
static java.lang.String |
lookupP2JAccount(java.lang.String appService,
java.lang.String host,
java.lang.String serviceName,
int port,
boolean directConnect,
boolean sessionFree)
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,
boolean sessionFree)
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,
boolean sessionFree)
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,
boolean sessionFree)
Search through the known remote appservers and determine the name of the appserver
configured for this connection request.
|
static 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.
|
static java.lang.String |
nextContextId(boolean underscore)
Calculate a random string, to be used as a connection ID for PASOE or as a context ID for
OerequestInfo . |
static AppServerInvocationResult |
obtainProxy(java.lang.String id,
java.lang.String name)
Obtain a proxy for the given external procedure.
|
(package private) static void |
registerAgent(Agent agent)
Register the specified agent with this FWD context.
|
(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 void |
setServerConnectionBoundRequest(boolean bind)
Set the SERVER-CONNECTION-BOUND-REQUEST attribute of this session.
|
static void |
setServerConnectionContext(java.lang.String value)
Set the SERVER-CONNECTION-CONTEXT attribute of this session.
|
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 nextContextId(boolean underscore)
OerequestInfo
.underscore
- Flag indicating if the 14 char is an underscore.public static AppServerInvocationResult 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, int agentId, 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
.agentId
- The agent ID where this remote procedure was created.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 isWebServiceTokenInUse(java.lang.String token)
token
- The web service token.true
if Agent.activeWebServiceTokens
contains this token.public static boolean isRemote()
true
if the current session is an AppServer session or false
otherwise.public static boolean isPasoe()
public static logical isServerConnectionBound()
public static logical isServerConnectionBoundRequest()
public static void setServerConnectionBoundRequest(boolean bind)
bind
- The bound state.public static java.lang.String getServerConnectionContext()
public static void setServerConnectionContext(java.lang.String value)
value
- The attribute's value.public static java.lang.String getServerConnectionId()
public static character getProcedureName(java.lang.String id, java.lang.String resId, int agentId)
id
- The appserver connection id.resId
- The ID of a remote procedure.agentId
- The agent ID where this remote procedure was created.getAgentPool(String)
public static boolean deleteProcedure(java.lang.String id, java.lang.String resId, int agentId, java.lang.String token)
id
- The appserver connection id.resId
- The ID of a remote procedure which needs to be deleted.agentId
- The agent ID where this remote procedure was created.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.true
if the remote procedure was deleted.getAgentPool(String)
public static boolean deleteObject(java.lang.String id, java.lang.String resId, int agentId)
id
- The appserver connection id.resId
- The ID of a remote object which needs to be deleted.agentId
- The agent ID where this remote procedure was created.true
if the remote object was deleted.public static AppServerInvocationResult connect(java.lang.String appServer, 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.
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.requestInfo
- The remote OerequestInfo
details, as set by
OerequestInfo.toArray()
.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 void disconnect(AgentPool pool, java.lang.String id)
pool
- The pool to which the connection belongs (may be null
, in which case
getAgentPool(java.lang.String)
is used to resolve it).id
- The connection ID to disconnect.getAgentPool(String)
public static 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 static AppServerInvocationResult invokeMethod(java.lang.String id, int requestId, long timeout, boolean returnValue, character name, java.lang.String resId, int agentId, 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.agentId
- The agent ID where this remote procedure was created.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 static AppServerInvocationResult invoke(java.lang.String id, int requestId, long timeout, character name, java.lang.String procID, int agentId, 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.agentId
- The agent ID where this remote procedure was created.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 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 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 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 static 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.public static void disableLegacyErrors(java.lang.String id)
id
- The appserver connection id.public static boolean isDisabledLegacyErrors()
connection ID
should suppress legacy OO errors.public static java.net.InetSocketAddress lookupP2JServer(java.lang.String appService, java.lang.String host, java.lang.String serviceName, int port, boolean directConnect, boolean sessionFree)
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).sessionFree
- true
to indicate a session-free operating mode, false
to indicate a session-managed operating mode.public static java.lang.String lookupP2JAccount(java.lang.String appService, java.lang.String host, java.lang.String serviceName, int port, boolean directConnect, boolean sessionFree)
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).sessionFree
- true
to indicate a session-free operating mode, false
to indicate a session-managed operating mode.public static java.lang.String lookupTargetAppserver(java.lang.String appService, java.lang.String host, java.lang.String serviceName, int port, boolean directConnect, boolean sessionFree)
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).sessionFree
- true
to indicate a session-free operating mode, false
to indicate a session-managed operating mode.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(java.lang.Object referent)
referent
- A persistent procedure referent.true
if the persistent procedure is known to the current running
appserver.public static AgentPool getAgentPoolForAppserver(java.lang.String appServer)
appServer
- The appserver name.public static int getNumberOfAgentsInPool(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.static void registerAgent(Agent agent)
agent
- The agent handling this FWD context.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, boolean sessionFree)
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).sessionFree
- true
to indicate a session-free operating mode, false
to indicate a session-managed operating mode.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.