public class StandardServer
extends java.lang.Object
In particular, exported entry points are read from directory objects /server/serverID/exports/groupID/methodID where methodID is a named string object. The name of this object is the well known exported method name. The "value" attribute is a string encoding fully qualified class name, method name and, possibly, the signature as in class.method(signature)
The directory also encodes the standard entry point of the P2J converted
application which is to be invoked. This class provides the mechanism
to look up this entry point and invoke it (see standardEntry()
and
invoke(int, com.goldencode.p2j.main.Isolatable)
).
Modifier and Type | Class and Description |
---|---|
(package private) static class |
StandardServer.AbstractInitTermListener
Abstract adapter for a basic init/term listener.
|
private static class |
StandardServer.MainInvoker
Prepares the exported entry point to be called in the properly
initialized transactionable environment.
|
Modifier and Type | Field and Description |
---|---|
private AdminServerExtension |
adminServerExtension
Admin extension.
|
private java.util.Map<java.lang.String,java.lang.Object> |
inst
Map that keeps instantiated classes by name.
|
private static ContextLocal<ClientParameters> |
localParams
Context-local client-side parameters exposed to the server.
|
private static java.util.logging.Logger |
LOG
Logger (this is JVM-wide rather than being context-local).
|
private java.util.concurrent.CountDownLatch |
ready
Signals when the non-network portions of the server are ready.
|
private static java.util.ArrayList<InitTermListener> |
serverHooks
Server hooks.
|
private static boolean |
shutdownDone
Flag which is set to
true when shutdown is done. |
private static java.lang.Object |
shutdownLock
Lock object for shutdown synchronization.
|
Constructor and Description |
---|
StandardServer() |
Modifier and Type | Method and Description |
---|---|
void |
bootstrap(BootstrapConfig config)
Bootstrap the server environment by initializing network services,
exporting all standard entry points for this server, loading all
application specific startup classes, and starting the server socket
listening loop.
|
private boolean |
exportMethod(java.lang.String group,
java.lang.String entry,
java.lang.String methodSpec)
Registers an entry point as an export.
|
static ClientParameters |
getClientParameters()
Get the parameters exposed by the client-side exposed, for this context.
|
static java.lang.String |
getHookForJar(java.lang.String jarName)
Get the registered hook which is defined in the given jar, if any.
|
private java.lang.String |
getSignature(java.lang.reflect.Method method)
Returns method's signature as text.
|
private void |
hookInitialize()
Notify server hook about application initialization.
|
private void |
hookTerminate(java.lang.Throwable t)
Notify server hook about application termination.
|
private void |
initClassLoaders(DirectoryService ds)
Initialize the class loaders for all the jars defined in the directory.
|
static java.lang.Object |
invoke(int stopDisp,
Isolatable entry)
Initializes the
TransactionManager environment and other
user-specific runtime initialization and then executes the given entry
point. |
static InitTermListener |
loadHook(java.lang.String hook,
java.lang.String hookPath)
Load
InitTermListener hook using specified class and path. |
private static void |
loadStartup(DirectoryService ds)
Reads the portion of the directory where all preloaded application
classes are listed and instantiates them.
|
static void |
register(InitTermListener hook)
Add server hook which will be notified about server startup and shutdown.
|
private void |
registerDefaultServices(SecurityManager sm,
BootstrapConfig config)
Register default services:
SharedVariableManager
UnnamedStreams
LogicalTerminal
Persistence
AccumulatorManager
WebServer
custom account extension plugin
|
static void |
removeHook(java.lang.String hookClass)
Terminate and remove the given server hook.
|
static void |
setClientParams(ClientParameters params)
Set the client parameters.
|
static boolean |
standardEntry()
Serves as a standard transaction entry point to be called from the
client which reroutes control to a specific entry point which is defined
in the directory.
|
void |
waitUntilReady()
Block the calling thread until the non-network portions of the server
are fully initialized.
|
private static final java.util.logging.Logger LOG
private static final ContextLocal<ClientParameters> localParams
private static java.lang.Object shutdownLock
private static boolean shutdownDone
true
when shutdown is done.private static java.util.ArrayList<InitTermListener> serverHooks
private java.util.Map<java.lang.String,java.lang.Object> inst
private java.util.concurrent.CountDownLatch ready
private AdminServerExtension adminServerExtension
public static void setClientParams(ClientParameters params)
params
- A container with any client-related parameters.public static boolean standardEntry()
The entry point definition is the subject to a standardized directory lookup, which allows server or account specific definitions as well as server-wide or system-wide defaults.
method-name should refer to a public method of the class. It can be either a static or an instance method taking no arguments. The class is instantiated before calling the named method. The returned object, if any, is discarded.
The invoke(int, com.goldencode.p2j.main.Isolatable)
method is the worker that actually handles the
method's invocation using reflection.
If directory contains definition for context hook, then it is
instantiated. Hook definition directory entry is searched using the same
rules as application entry point (refer to
Utils.findDirectoryNodePath(DirectoryService, String, String, boolean)
for more details), appropriate variable has name context-hook.
Context hook class must implement InitTermListener
interface.
true
if re-logon should be performed.public static java.lang.String getHookForJar(java.lang.String jarName)
jarName
- public static void removeHook(java.lang.String hookClass)
hookClass
- The hook class name.public static void register(InitTermListener hook)
hook
- Server hook to add.public static InitTermListener loadHook(java.lang.String hook, java.lang.String hookPath)
InitTermListener
hook using specified class and path.hook
- Full class name.hookPath
- Hook path in directory.public static ClientParameters getClientParameters()
ClientParameters
instance, with the context's parameters.public void waitUntilReady() throws java.lang.InterruptedException
java.lang.InterruptedException
public void bootstrap(BootstrapConfig config) throws java.lang.Exception
The implementation looks up the directory under the path
/server/serverID/exports
to figure out the subtree of
registrations.
If no such subtree exists, /server/default/exports
is
checked next.
Entries have the format export-group-ID/export-method-ID
where the export-group-ID
is a container naming a group and
export-method-ID
is an object naming the export and
providing its implementation location through its string type "value"
attribute as class-name.method-name(signature)
.
method-name
should refer to a public method of the class.
It can be either a static or instance method. The class is instantiated
once for the first instance method reference.
Specifying a method without signature is allowed if the method is not overloaded.
Once all the generic directory-driven exports are processed, then all
the following are registered using the simpler RemoteObject
mechanism:
Interface Type Target ----------------- ----------- ---------------------------------- ServerExports static LogicalTerminal RemoteErrorData static ErrorManager MainEntry static StandardServer
When basic initialization is finished, this method registers default
services and then loads user defined services if they are defined in
startups directory entry under either
/server/serverID
or /server/default
entry.
User defined services must implement InitTermListener
interface
and its InitTermListener.initialize()
will be invoked right
before server will start listen for incoming connections while its
InitTermListener.terminate(Throwable)
method will be invoked
when server stopped accepting incoming connections and all active
sessions are terminated. If server is stopped in graceful way (via
remote request) then null
is passed as a parameter into
InitTermListener.terminate(Throwable)
method. If server is
stopped in abnormal way, for example, because user typed Ctrl-C, then
some non-null value is passed as a parameter. Passed value should not be
relied on to determine real cause of server stop.
config
- Bootstrap configuration information for this server.java.lang.Exception
private void initClassLoaders(DirectoryService ds)
java.system.class.loader
property is set to the custom class loader
.ds
- The directory service.private void registerDefaultServices(SecurityManager sm, BootstrapConfig config)
SharedVariableManager
UnnamedStreams
LogicalTerminal
Persistence
AccumulatorManager
WebServer
sm
- The initialized instance of SecurityManager
.config
- The bootstrap configuration information for this server.public static java.lang.Object invoke(int stopDisp, Isolatable entry) throws java.lang.NullPointerException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException, java.lang.InstantiationException
TransactionManager
environment and other
user-specific runtime initialization and then executes the given entry
point.stopDisp
- STOP condition disposition.
entry
- instance of the Isolatable interface that provides the entry
point to be executedvoid
return then this will return
null
. Note that it is a limitation of the
design of Java method signatures such that we do not
distinguish between a method with a void
return
and a method that has a real return value which is set to
null
.java.lang.NullPointerException
java.lang.IllegalAccessException
java.lang.IllegalArgumentException
java.lang.reflect.InvocationTargetException
java.lang.InstantiationException
private static void loadStartup(DirectoryService ds) throws ConfigurationException
ds
- instance of DirectoryService
to read fromConfigurationException
- when a class listed in the directory cannot be loadedprivate boolean exportMethod(java.lang.String group, java.lang.String entry, java.lang.String methodSpec)
The entry point method can be specified either by name or by name and signature. The short form is acceptable when the method is unique (not overloaded). Overloaded methods require signature specification to be fully resolved.
group
- export group nameentry
- export entry namemethodSpec
- class and method specification as in class.method(signature)
where the (signature) is optional.true
if succeededprivate java.lang.String getSignature(java.lang.reflect.Method method)
method
- Method
to get the signature for.private void hookInitialize() throws ConfigurationException
ConfigurationException
private void hookTerminate(java.lang.Throwable t)
t
- Parameter which will be passed to
InitTermListener.terminate(Throwable)
.