Global Positioning System Reference
In-Depth Information
should experiment with different implementations as the execution policies
offer a wide range of transaction management configurations.
11.7.3 The Remote Concept for Server Objects
The java.concurrent package provides concurrency on a higher (i.e., server)
level than the low-level methods in Object s and Thread s. For the application
designer, it would be even more pleasant to have one concept for all remote
client calls pre-implemented in the ServerObject . For the actual scenario,
all SOs are treated as local RealObject s|which, in fact, they are.
The executor service is instantiated in the ROServer and can be refer-
enced by all SOs. A different approach to provide the service could be a
static executor service inside the ServerObject class.
First, Callable is restricted to remote calls with
protected interface RemoteMethod<V> extends Callable<V>
{ V call() throws RemoteException; }
// read: "RemoteMethod.call throws RemoteException"
The interface is placed in ServerObject to be used by all extenders. Generic
placeholders indicate that the actual values need to be supplied with the
implementation and before compiling. Therefore any method using the
RemoteMethod<V> has to be coded as a class, which can be implemented
and instantiated for a dedicated remote method. The class RemoteCall<V>
wraps all executor options to hide their complexity from the external client.
The concept does not need to distinguish methods with or without return
values as the <V> includes the class Void as a virtual return value with a
precise time of return.
The constructor is used to store the RemoteMethod for the RemoteCall
submission:
protected class RemoteCall<V> {
private RemoteMethod<V> remoteMethod;
public RemoteCall( RemoteMethod<V> rm )
{ remoteMethod = rm; }
...
Then, the different Future strategies are handled in a single method:
public V get( int waitMillis )
{
Future<V> remoteTask
= executorService.submit( remoteMethod );
try {
if ( waitMillis == -1 ) // wait for return
return remoteTask.get(); // can block!
else
return remoteTask
.get( waitMillis, TimeUnit.MILLISECONDS );
 
Search WWH ::




Custom Search