public class RemoteObject
extends java.lang.Object
No net package processing is needed in the implementation class or in the interface. This class is designed for convenience. Usage avoids the tedious, hard-coded requirements of exporting and importing network interfaces. To use it:
registerNetworkServer(java.lang.Class<?>, java.lang.Object)
method
passing the list of interfaces to be exported and the instance
that provides the implementation. This exports your interface.
Calls will now be dispatched to this object with no further
work.
registerStaticNetworkServer(java.lang.Class<?>[], java.lang.Class<?>)
method with the
list of interfaces to be exported and the class object that
provides the static
implementation. This exports
your interface. Calls will now be dispatched to the
static
methods of that class with no further work.
obtainNetworkInstance(java.lang.Class<?>)
method passing the
interface that is being requested. This assumes that a connection
to the remote node already exists. The object returned will
provide transparent access to the remote API with no further
effort.
obtainLocalInstance(java.lang.Class<?>, boolean)
method. No network connection or
session is needed.
Modifier and Type | Class and Description |
---|---|
private static class |
RemoteObject.RemoteAccess
Provides the proxy implementation for a remote object.
|
private static class |
RemoteObject.WorkArea
Stores global data relating to the state of the current context.
|
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.Class,java.lang.Class> |
localImplStaticServers
Stores static server mappings (global for the server JVM).
|
private static java.util.Map<java.lang.Class,java.util.Map<java.lang.reflect.Method,java.lang.reflect.Method>> |
localStaticServers
Stores static server method mappings (global for the server JVM).
|
private static java.util.logging.Logger |
LOG
Logger (safe as a JVM-wide value rather than as context-local).
|
private static ContextLocal<RemoteObject.WorkArea> |
work
Stores context-local state variables.
|
Constructor and Description |
---|
RemoteObject() |
Modifier and Type | Method and Description |
---|---|
private static java.lang.reflect.Method[] |
calcExportedMethods(java.lang.Class<?> iface)
Return a list of methods in a deterministic order such that for the
same interface (with identical methods) the list will be identical
on both the server and client.
|
private static java.lang.reflect.Method[][] |
calcExportedMethods(java.lang.Class<?>[] list)
Return the list of methods for all interfaces in the given list.
|
(package private) static java.lang.String |
calcGroupName(java.lang.Class<?> iface)
Return a unique group name for exporting this interface.
|
(package private) static java.lang.String |
calcKeyName(java.lang.reflect.Method method)
Return a unique method name corresponding to this given method.
|
(package private) static boolean |
deregisterStaticNetworkServer(java.lang.Class<?>[] list)
Remove all exported
static methods in the given list of
interfaces. |
static boolean |
deregisterStaticNetworkServer(java.lang.String[] list)
Lock all static exports which are specified in the given list.
|
static java.lang.reflect.Method |
findMatchingStaticMethod(java.lang.Class<?> cls,
java.lang.reflect.Method method)
Find the matching
static method in the given class that
corresponds to the given method. |
static java.lang.Class<?> |
getImplClass(java.lang.String ifaceName)
Get the implementation class for the given interface, exported as a
static server.
|
private static LocalStateSync |
getSynchronizer(RemoteObject.WorkArea wa,
boolean leftSide)
Configure and return an instance of the local state synchronizer.
|
private static void |
logExport(java.lang.String group,
java.lang.String name)
If logging is enabled at
FINER or greater detail, log
that an export has been created for the given group and method name. |
static java.lang.Object |
obtainInstance(java.lang.Class<?> cls,
boolean left)
Convenience method which returns a unique instance of an object that
implements the given interface.
|
static java.lang.Object |
obtainLocalInstance(java.lang.Class<?> cls,
boolean left)
Creates a unique instance of an object that implements the given
interface and upon which any method calls will be transparently
executed by the exported methods of the registered server in the
SAME JVM.
|
static java.lang.Object |
obtainNetworkInstance(java.lang.Class<?> iface)
Creates a unique instance of an object that implements the given
interface and upon which any method calls will be transparently
executed by the exported methods on the other side of the current
session's network connection (message queue).
|
static java.lang.Object |
obtainNetworkInstance(java.lang.Class<?>[] list)
Creates a unique instance of an object that implements the given
interfaces and upon which any method calls will be transparently
executed by the exported methods on the other side of the current
session's network connection (message queue).
|
static java.lang.Object |
obtainNetworkInstance(java.lang.Class<?>[] list,
int timeout)
Creates a unique instance of an object that implements the given
interfaces and upon which any method calls will be transparently
executed by the exported methods on the other side of the current
session's network connection (message queue).
|
static java.lang.Object |
obtainNetworkInstance(java.lang.Class<?>[] list,
Session session)
Creates a unique instance of an object that implements the given
interfaces and upon which any method calls will be transparently
executed by the exported methods on the other side of the specified
network connection (message queue).
|
static java.lang.Object |
obtainNetworkInstance(java.lang.Class<?>[] list,
Session session,
int timeout)
Creates a unique instance of an object that implements the given
interfaces and upon which any method calls will be transparently
executed by the exported methods on the other side of the specified
network connection (message queue).
|
static java.lang.Object |
obtainNetworkInstance(java.lang.Class<?> iface,
int timeout)
Creates a unique instance of an object that implements the given
interface and upon which any method calls will be transparently
executed by the exported methods on the other side of the current
session's network connection (message queue).
|
static java.lang.Object |
obtainNetworkInstance(java.lang.Class<?> iface,
Session session)
Creates a unique instance of an object that implements the given
interface and upon which any method calls will be transparently
executed by the exported methods on the other side of the specified
network connection (message queue).
|
static java.lang.Object |
obtainNetworkInstance(java.lang.Class<?> iface,
Session session,
int timeout)
Creates a unique instance of an object that implements the given
interface and upon which any method calls will be transparently
executed by the exported methods on the other side of the specified
network connection (message queue).
|
static void |
registerLeftSynchronizer(StateSynchronizer left)
Sets the instance of the state synchronizer for the "left" side of a
"local" (same-JVM) proxy environment.
|
static java.lang.Object |
registerLocalServer(java.lang.Class<?>[] list,
java.lang.Object impl,
java.lang.Object modToken)
Register all methods in the given list of interfaces from the local node
as a local server.
|
static java.lang.Object |
registerLocalServer(java.lang.Class<?> iface,
java.lang.Object impl,
java.lang.Object modToken)
Register all methods in the given interface from the local node as a
local server.
|
static java.lang.Object |
registerNetworkServer(java.lang.Class<?>[] list,
java.lang.Object impl)
Exports all methods in the given list of interfaces from the local node
(to other nodes).
|
static java.lang.Object |
registerNetworkServer(java.lang.Class<?>[] list,
java.lang.Object impl,
java.lang.Object modToken)
Exports all methods in the given list of interfaces from the local node
(to other nodes).
|
static java.lang.Object |
registerNetworkServer(java.lang.Class<?> iface,
java.lang.Object impl)
Exports all methods of the given interface from the local node (to
other nodes).
|
static java.lang.Object |
registerNetworkServer(java.lang.Class<?> iface,
java.lang.Object impl,
java.lang.Object modToken)
Exports all methods of the given interface from the local node (to
other nodes).
|
static void |
registerRightSynchronizer(StateSynchronizer right)
Sets the instance of the state synchronizer for the "right" side of a
"local" (same-JVM) proxy environment.
|
static java.lang.Object |
registerServer(java.lang.Class<?>[] list,
java.lang.Object impl,
java.lang.Object modToken,
boolean local)
Register all methods in the given interface from the local node as EITHER:
|
static java.lang.Object |
registerServer(java.lang.Class<?> iface,
java.lang.Object impl,
java.lang.Object modToken,
boolean local)
Register all methods in the given interface from the local node as EITHER:
|
static java.lang.Object |
registerStaticNetworkServer(java.lang.Class<?>[] list,
java.lang.Class<?> backing)
Exports all
static methods in the given backing class that
exactly match the method signatures in the given list of interfaces
from the local node (to other nodes). |
static java.lang.Object |
registerStaticNetworkServer(java.lang.Class<?>[] list,
java.lang.Class<?> backing,
java.lang.Object modToken)
Exports all
static methods in the given backing class that
exactly match the method signatures in the given list of interfaces
from the local node (to other nodes). |
private static final java.util.logging.Logger LOG
private static final ContextLocal<RemoteObject.WorkArea> work
private static final java.util.Map<java.lang.Class,java.util.Map<java.lang.reflect.Method,java.lang.reflect.Method>> localStaticServers
private static final java.util.Map<java.lang.Class,java.lang.Class> localImplStaticServers
public static java.lang.Object registerNetworkServer(java.lang.Class<?> iface, java.lang.Object impl)
iface
- The interface to export. It will be exported using
the fully qualified interface name as the group and each
method will be exported by its name.impl
- The instance of an object that implements the exported
interface. All method calls to the exported methods will be
redirected to the given instance.public static java.lang.Object registerNetworkServer(java.lang.Class<?> iface, java.lang.Object impl, java.lang.Object modToken)
iface
- The interface to export. It will be exported using
the fully qualified interface name as the group and each
method will be exported by its name.impl
- The instance of an object that implements the exported
interface. All method calls to the exported methods will be
redirected to the given instance.modToken
- The modification token retured from the original registration
call (to this same method). May be null
on the
first call for this interface (a new token will be created
and returned in this case). If non-null
on the
first call, that object will be used as the modification token
from then on.public static java.lang.Object registerNetworkServer(java.lang.Class<?>[] list, java.lang.Object impl)
list
- The interfaces to export. Each one will be exported using
the fully qualified interface name as the group and each
method will be exported by its name.impl
- The instance of an object that implements all of the
exported interfaces. All method calls to the exported
methods will be redirected to the given instance.public static java.lang.Object registerNetworkServer(java.lang.Class<?>[] list, java.lang.Object impl, java.lang.Object modToken)
list
- The interfaces to export. Each one will be exported using
the fully qualified interface name as the group and each
method will be exported by its name.impl
- The instance of an object that implements all of the
exported interfaces. All method calls to the exported
methods will be redirected to the given instance.modToken
- The modification token retured from the original registration
call (to this same method). May be null
on the
first call for this interface (a new token will be created
and returned in this case). If non-null
on the
first call, that object will be used as the modification token
from then on.public static java.lang.Object registerLocalServer(java.lang.Class<?> iface, java.lang.Object impl, java.lang.Object modToken)
iface
- The interface to register.impl
- The instance of an object that implements all of the
exported interfaces. All method calls to the registered
methods will be redirected to the given instance.modToken
- The modification token retured from the original registration
call (to this same method). May be null
on the
first call for this interface (a new token will be created
and returned in this case). If non-null
on the
first call, that object will be used as the modification token
from then on.public static java.lang.Object registerLocalServer(java.lang.Class<?>[] list, java.lang.Object impl, java.lang.Object modToken)
list
- The interfaces to register.impl
- The instance of an object that implements all of the
exported interfaces. All method calls to the registered
methods will be redirected to the given instance.modToken
- The modification token retured from the original registration
call (to this same method). May be null
on the
first call for this interface (a new token will be created
and returned in this case). If non-null
on the
first call, that object will be used as the modification token
from then on.public static java.lang.Object registerServer(java.lang.Class<?> iface, java.lang.Object impl, java.lang.Object modToken, boolean local)
single
is true
then the methods
will be exported for remote access using
registerNetworkServer(java.lang.Class<?>, java.lang.Object)
.
single
is false
then the methods
will be exported for local access using
registerLocalServer(java.lang.Class<?>, java.lang.Object, java.lang.Object)
.
iface
- The interface to register.impl
- The instance of an object that implements all of the
exported interfaces. All method calls to the registered
methods will be redirected to the given instance.modToken
- The modification token retured from the original registration
call (to this same method). May be null
on the
first call for this interface (a new token will be created
and returned in this case). If non-null
on the
first call, that object will be used as the modification token
from then on.local
- true
to register purely on a local basis (no
remote/network access to these methods).public static java.lang.Object registerServer(java.lang.Class<?>[] list, java.lang.Object impl, java.lang.Object modToken, boolean local)
single
is true
then the methods
will be exported for remote access using
registerNetworkServer(java.lang.Class<?>, java.lang.Object)
.
single
is false
then the methods
will be exported for local access using
registerLocalServer(java.lang.Class<?>, java.lang.Object, java.lang.Object)
.
list
- The interfaces to register.impl
- The instance of an object that implements all of the
exported interfaces. All method calls to the registered
methods will be redirected to the given instance.modToken
- The modification token retured from the original registration
call (to this same method). May be null
on the
first call for this interface (a new token will be created
and returned in this case). If non-null
on the
first call, that object will be used as the modification token
from then on.local
- true
to register purely on a local basis (no
remote/network access to these methods).public static java.lang.Object registerStaticNetworkServer(java.lang.Class<?>[] list, java.lang.Class<?> backing)
static
methods in the given backing class that
exactly match the method signatures in the given list of interfaces
from the local node (to other nodes). All remote calls to these
exported methods will be subsequently dispatched to the given
implementation class.
The nature of Java interfaces precludes a static
implementation. This means that the backing class can't use the
implements
keyword even though it must have an exact
match of the exported methods actually implemented.
list
- The interfaces to export. Each one will be exported using
the fully qualified interface name as the group and each
method will be exported by its name.backing
- The class that implements all of the exported interfaces as
static
methods. All method calls to the
exported methods will be redirected to that class on a
static
basis.public static java.lang.Class<?> getImplClass(java.lang.String ifaceName)
null
ifaceName
- The interface name.public static boolean deregisterStaticNetworkServer(java.lang.String[] list)
list
- The interface name list.true
if all static exports in this list were
locked.public static java.lang.Object registerStaticNetworkServer(java.lang.Class<?>[] list, java.lang.Class<?> backing, java.lang.Object modToken)
static
methods in the given backing class that
exactly match the method signatures in the given list of interfaces
from the local node (to other nodes). All remote calls to these
exported methods will be subsequently dispatched to the given
implementation class.
The nature of Java interfaces precludes a static
implementation. This means that the backing class can't use the
implements
keyword even though it must have an exact
match of the exported methods actually implemented.
list
- The interfaces to export. Each one will be exported using
the fully qualified interface name as the group and each
method will be exported by its name.backing
- The class that implements all of the exported interfaces as
static
methods. All method calls to the
exported methods will be redirected to that class on a
static
basis.modToken
- The modification token retured from the original registration
call (to this same method). May be null
on the
first call for this interface (a new token will be created
and returned in this case). If non-null
on the
first call, that object will be used as the modification token
from then on.static boolean deregisterStaticNetworkServer(java.lang.Class<?>[] list)
static
methods in the given list of
interfaces.
If there are active sessions which have used API(s) in these exported interface, the deregistration will not be performed for any of the exported interface.
The deregistration bypasses the modToken
check, as this
will be done by other clients (i.e. from the admin applet).
list
- The exported interfaces to be removed.true
if deregistration was completed fully.public static java.lang.Object obtainNetworkInstance(java.lang.Class<?> iface)
Synchronous transactions will have a timeout set to 0 (indefinite wait).
iface
- The interface for which a network instance must be created.public static java.lang.Object obtainNetworkInstance(java.lang.Class<?> iface, int timeout)
iface
- The interface for which a network instance must be created.timeout
- Timeout in milliseconds for synchronous transactions to
wait before automatically unblocking. Use 0 to set an
indefinite wait.public static java.lang.Object obtainNetworkInstance(java.lang.Class<?> iface, Session session)
Synchronous transactions will have a timeout set to 0 (indefinite wait).
iface
- The interface for which a network instance must be created.session
- The network connection which the returned object should
represent. If null
the current session will be
used.public static java.lang.Object obtainNetworkInstance(java.lang.Class<?> iface, Session session, int timeout)
iface
- The interface for which a network instance must be created.session
- The network connection which the returned object should
represent. If null
the current session will be
used.timeout
- Timeout in milliseconds for synchronous transactions to
wait before automatically unblocking. Use 0 to set an
indefinite wait.public static java.lang.Object obtainNetworkInstance(java.lang.Class<?>[] list)
Synchronous transactions will have a timeout set to 0 (indefinite wait).
list
- The interfaces for which a network instance must be created.public static java.lang.Object obtainNetworkInstance(java.lang.Class<?>[] list, int timeout)
list
- The interfaces for which a network instance must be created.timeout
- Timeout in milliseconds for synchronous transactions to
wait before automatically unblocking. Use 0 to set an
indefinite wait.public static java.lang.Object obtainNetworkInstance(java.lang.Class<?>[] list, Session session)
Synchronous transactions will have a timeout set to 0 (indefinite wait).
list
- The interfaces for which a network instance must be created.session
- The network connection which the returned object should
represent. If null
the current session will be
used.public static java.lang.Object obtainNetworkInstance(java.lang.Class<?>[] list, Session session, int timeout)
list
- The interfaces for which a network instance must be created.session
- The network connection which the returned object should
represent. If null
the current session will be
used.timeout
- Timeout in milliseconds for synchronous transactions to
wait before automatically unblocking. Use 0 to set an
indefinite wait.public static java.lang.Object obtainInstance(java.lang.Class<?> cls, boolean left)
obtainNetworkInstance(java.lang.Class<?>)
.
obtainLocalInstance(java.lang.Class<?>, boolean)
.
cls
- The interface for which a local instance must be created.left
- true
if the caller is considered the "left"
side of the local session, false
for the "right"
side. This controls the direction of synchronization on method
calls for the returned instance.null
is
returned.public static void registerLeftSynchronizer(StateSynchronizer left)
left
- The synchronizer to register or null
if the
currently registered synchronizer should be deregistered.public static void registerRightSynchronizer(StateSynchronizer right)
right
- The synchronizer to register or null
if the
currently registered synchronizer should be deregistered.public static java.lang.Object obtainLocalInstance(java.lang.Class<?> cls, boolean left)
cls
- The interface for which a local instance must be created.left
- true
if the caller is considered the "left"
side of the local session, false
for the "right"
side. This controls the direction of synchronization on method
calls for the returned instance.null
is returned.public static java.lang.reflect.Method findMatchingStaticMethod(java.lang.Class<?> cls, java.lang.reflect.Method method)
static
method in the given class that
corresponds to the given method. A match is based on method name,
return type and parameter number/order/types. All criteria must
match exactly. Note that only the static
modifier is
ignored in this comparison.cls
- The class in which to search.method
- The instance method signature to match.null
if no match was
found.static java.lang.String calcGroupName(java.lang.Class<?> iface)
iface
- The interface to be exported.private static LocalStateSync getSynchronizer(RemoteObject.WorkArea wa, boolean leftSide)
wa
- Context-local state.leftSide
- true
if the caller is considered the "left"
side of the local session, false
for the "right"
side. This controls the direction of synchronization on method
calls for the returned instance.null
if state synchronization is not enabled.private static void logExport(java.lang.String group, java.lang.String name)
FINER
or greater detail, log
that an export has been created for the given group and method name.group
- Group name of the export.name
- Method name of the export.private static java.lang.reflect.Method[][] calcExportedMethods(java.lang.Class<?>[] list)
list
- The list of interfaces to be exported.private static java.lang.reflect.Method[] calcExportedMethods(java.lang.Class<?> iface)
iface
- The interface to be exported.static java.lang.String calcKeyName(java.lang.reflect.Method method)
method
- The method for which a name must be calculated.