public class RemoteCallHandlerObject extends Task implements RemoteCallHandler
If you want to change the method for receiving and sending data (i.e. not via the default stream) you must override boolean sendData(ByteArray data) and TextDecoder getData(ByteArray dest)
To close the RemoteCallHandler simply close the streams. If you want to close the handler without closing the streams, call the close() method.
Handle.ObjectDiscarder, Handle.WaitOnChange
Modifier and Type | Field and Description |
---|---|
static boolean |
alwaysMultiThreaded |
protected boolean |
closed |
protected BlockInputStream |
in |
IOException |
ioException
If an IOException occured, it will be placed here.
|
protected BlockOutputStream |
out |
boolean |
runInSingleThread
If this is set true then only a single thread will be used that will
receive a call request, invoke the method, and then send the reply
and then repeat until the streams are closed.
|
protected static ThreadPool |
threadPool |
int |
timeOut
This is the timeout in milliseconds for receiving a reply.
|
static boolean |
useThreadPool
If this is true then the RemoteCallHandlerObject will use a Thread pool
to run threads.
|
Aborted, Changed, DEFAULT_CHANGE_ACCEPT_TIME, DEFAULT_PROGRESS_RESOLUTION, doing, error, Failed, Failure, OPTION_STOP_IF_NOT_SET, OPTION_TIMEOUT_IF_NOT_SET, progress, progressResolution, returnCode, returnValue, Running, shouldStop, startTime, state, Stopped, stopReason, subHandle, Succeeded, Success, waitChangeAcceptedTime
Constructor and Description |
---|
RemoteCallHandlerObject()
Create a RemoteCallHandler with no streams.
|
RemoteCallHandlerObject(BlockInputStream in,
BlockOutputStream out)
Create a RemoteCallHandler to operate on the specified streams.
|
RemoteCallHandlerObject(InputStream in,
OutputStream out)
Create a RemoteCallHandler to operate on the specified streams.
|
Modifier and Type | Method and Description |
---|---|
void |
addTarget(String targetCode,
Object target,
Class asClass)
Add a target object that incoming remote calls will be invoked on.
|
boolean |
call(RemoteCall rc,
String targetCode)
This dispatches the RemoteCall to the remote handler.
|
void |
close()
Closes the RemoteCallHandler and stops its operation.
|
void |
closeConnection()
Closes the RemoteCallHandler and stops its operation and closes the stream connection.
|
protected ByteArray |
doInvoke(Object target,
RemoteCall rc) |
protected void |
doRun()
Override this to provide functionality for the Task.
|
Object |
findTarget(String targetCode)
Override this to find a target given a text encoded targetCode.
|
void |
freeProxy(String proxyTargetCode)
This is called by the remote entity when a Proxy at the remote end has
been freed (no longer referenced) and this indicates that the object at
this end, which has the specified target code, should be removed from
the table of targets and therefore allowed to be freed on this end as
well.
|
ByteArray |
getData(ByteArray dest)
This is responsible for receiving data - either remote calls or replies
to remote calls.
|
Class |
getTargetClass(Object target) |
static ThreadPool |
getThreadPool()
This returns the ThreadPool being used by the RemoteCallHandlerObjects.
|
protected void |
queueSend(ByteArray toSend,
int id,
boolean isCall) |
protected void |
queueSend(Tag toSend) |
void |
removeTarget(String targetCode) |
void |
runInCurrentThread()
This has the same effect as setting runInSingleThread to true
and then calling run().
|
void |
sendData(ByteArray data)
This is responsible for sending data - either remote calls or replies
to remote calls.
|
void |
setStreams(BlockInputStream in,
BlockOutputStream out) |
void |
setStreams(InputStream in,
OutputStream out) |
void |
stop(int reason)
This will close the RemoteCallHandler.
|
complete, getDaemon, getThread, interrupt, run, setDaemon, setThreadGroup, sleep, start, start
addParent, changeAccepted, changed, check, check, checkAbortFail, checkAny, checkChangeAccepted, checkFailure, convertError, doChangeTo, fail, getChangeState, getErrorText, getFinalReturnValue, getProperties, getReturnValue, getStoppableWaitOnSuccess, getUnwrappedReturnValue, hasStopped, newWaitOnChange, removeParent, resetProgress, set, setFlags, setProgress, setProgress, setResult, setReturnValue, startDoing, succeed, succeeded, throwErrorIfNotStopped, throwRuntimeError, throwRuntimeError, throwRuntimeError, throwRuntimeError, timeout, timeout, waitChangeAccepted, waitForReturnValue, waitOn, waitOn, waitOn, waitOn, waitOnAny, waitOnAny, waitOnAny, waitOnAny, waitOnChange, waitOnResult, waitOnSuccess, waitOnSuccess, waitReturnValue, waitUntilCompletion, waitUntilCompletion, waitUntilStopped, waitUntilStopped, wasAborted, yield
public static boolean useThreadPool
public static boolean alwaysMultiThreaded
public boolean runInSingleThread
protected BlockOutputStream out
protected BlockInputStream in
public int timeOut
public IOException ioException
protected boolean closed
protected static ThreadPool threadPool
public RemoteCallHandlerObject()
public RemoteCallHandlerObject(InputStream in, OutputStream out)
public RemoteCallHandlerObject(BlockInputStream in, BlockOutputStream out)
public void runInCurrentThread()
public void addTarget(String targetCode, Object target, Class asClass)
targetCode
- a distinct name for the Object. If this is null or ""
then this target will be the default target.target
- the target object that will have remote calls invoked on.asClass
- an optional Class that specifies what class or interface
the Object should expose for method invokes. This is because anonymous
objects may not be public and so the method you expect to be public
may not be so. To ensure that the methods are invokes you provide the
Class that will be used when searching for methods. If this is null
then getClass() is called on the target.public void removeTarget(String targetCode)
public Object findTarget(String targetCode)
public static ThreadPool getThreadPool()
public void setStreams(BlockInputStream in, BlockOutputStream out)
public void setStreams(InputStream in, OutputStream out)
public void sendData(ByteArray data) throws IOException
This method may block the current mThread - the other operations of the handler operate in their own mThread threads.
IOException
public ByteArray getData(ByteArray dest) throws IOException
This method should block the current Thread until a full ByteArray object has been read - the other operations of the handler operate in their own Threads.
IOException
public void close()
public void closeConnection()
public void stop(int reason)
protected void doRun()
Task
protected void queueSend(ByteArray toSend, int id, boolean isCall)
protected void queueSend(Tag toSend)
protected ByteArray doInvoke(Object target, RemoteCall rc)
public void freeProxy(String proxyTargetCode)
proxyTargetCode
- the target code assigned to the proxy at this end.public boolean call(RemoteCall rc, String targetCode)
call
in interface RemoteCallHandler