Global Positioning System Reference
In-Depth Information
}
...
By explicitly defining the maximum waiting time (in milliseconds), the
method call can always return within the given time window. Otherwise,
it will throw a
TimeoutException
. If the method does not return, or throws
a
RemoteException
, additional handling is necessary:
...
catch ( InterruptedException ie) { /* TODO */ }
catch ( ExecutionException ee) {
if ( ee.getCause() instanceof RemoteException )
/* TODO */
}
catch (CancellationException ce) { /* TODO */ }
catch (Exception e)
{ /* TODO: unexpected Exception ... */ }
//
finally { /* TODO */ }
return null;
}
Although
RemoteMethod.call
can only throw
RemoteException
s, the excep-
tion has to be picked up via
ExecutionException.getCause()
, which is part
of the executor concept. If a task throws an exception,
Future.get
wraps
it in the
ExecutionException
.
In case the external client chooses to ultimately wait for a method return,
it should get the chance to cancel the task explicitly, i.e., to shut down the
application or server:
public boolean cancel( boolean mayInterruptIfRunning )
{
if ( remoteTask == null ) return false;
return remoteTask.cancel( mayInterruptIfRunning );
}
RemoteCall<V>
supports waiting for client responses for a maximum time.
If there is no return (value) after the given time span, the calling (SO-)
method can implement a fall-back strategy.
Using
RemoteCall.submit()
, the
RemoteMethod
can be submitted exclu-
sively. In case the client method is void and/or the server does not bother
to wait for its return, there is no further need to use
get
. Nevertheless, the
result (or exception) can be retrieved at a later time via
get
.
Using the remote concept. After this excursion on threading concepts,
the developer needs a recipe to apply the chosen concept for his remote
method calls. In terms of program flow, the text has not reached the end
of
ROServer.identify
yet! The client has been mapped to the
connected
Clients
and is then asked to identify itself with a single line of code:
Object ID = candidate.getIdentity();
Search WWH ::
Custom Search