public class RemoteCall extends Handle implements ByteEncodable
See the EweSyncDemo application for an example of how to do this.
Please note the following restrictions when using remote calls.
A RemoteCall represents a single method which is specified in its constructor. Once you have a RemoteCall object you set parameters for a call by calling the add() methods in sequence. The RemoteCall knows the exact type of each parameter so the data specified in each add() method is cast to the correct parameter type. Each add() method returns the RemoteCall object itself so it is easy to concatenate add() calls together.
Modifier and Type | Class and Description |
---|---|
static interface |
RemoteCall.IncomingCallLogger |
static class |
RemoteCall.UnknownException |
Handle.ObjectDiscarder, Handle.WaitOnChange
Modifier and Type | Field and Description |
---|---|
Class |
classCreator
Deprecated.
- this is not needed.
|
String |
id |
Throwable |
invocationError
This will hold any exception generated by the remote object when the
method was invoked.
|
String |
method |
RemoteCallHandler |
myHandler
This is initially null but can be set before calling call.
|
boolean |
replied
This is set true once a reply has been received.
|
String |
retType |
int |
timeOut
This is the timeout for the call.
|
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 |
---|
RemoteCall(byte[] source,
int offset,
int length)
This is used to create a RemoteCall from a sequence of bytes.
|
RemoteCall(Method method) |
RemoteCall(String method)
Create a new RemoteCall targeted at the specified method.
|
RemoteCall(String methodName,
Class[] parameterTypes,
Class returnType) |
Modifier and Type | Method and Description |
---|---|
RemoteCall |
add(boolean value)
Use this to add a parameter of type boolean.
|
RemoteCall |
add(char value)
Use this to add a char parameter.
|
RemoteCall |
add(double value)
Use this to add a parameter of type float or double.
|
RemoteCall |
add(long value)
Use this to add a parameter of type byte, short, int and long.
|
RemoteCall |
add(Object value)
Use this to add an object or array parameter (including null) -
do not use this to add a Java Wrapper Object for a primitive parameter..
|
RemoteCall |
addParameter(Object value)
Add a standard Java parameter.
|
RemoteCall |
addParameter(Wrapper w)
This is used to add a parameter.
|
Wrapper |
call()
Invokes the remote call using the myHandler value as the transport mechanism and specifying a null (default) target object.
|
Wrapper |
call(RemoteCallHandler handler,
String targetCode)
Invokes the remote call using the specified handler as the transport mechanism.
|
Wrapper |
call(String targetCode)
Invokes the remote call using the myHandler value as the transport mechanism.
|
RemoteCall |
callAndWait(RemoteCallHandler handler,
String targetCode)
This calls and waits for the remote call to complete, fail or timeout.
|
RemoteCall |
callAsync() |
RemoteCall |
callAsync(RemoteCallHandler handler,
String targetCode) |
byte[] |
encodeBytes() |
int |
encodeBytes(ByteArray dest)
This requests the Object to encode itself as a stream of bytes which is appended
to the destination ByteArray.
|
RemoteCall |
getCopy()
Get a copy of a RemoteCall that you can use for another invocation.
|
Throwable |
getException() |
static RemoteCall.IncomingCallLogger |
getIncomingCallLogger() |
Wrapper |
getReturnValue() |
ByteArray |
invokeOn(Object dest,
Class r)
Invoke the remote call on a target object of the specified class.
|
protected boolean |
invokeOn(Object dest,
Class r,
ByteArray ba,
RemoteCallTask rct) |
ByteArray |
invokeOn(Object dest,
Class r,
RemoteCallTask rct) |
void |
reply(ByteArray reply)
This is used to provide a reply to the remote call from an encoded
reply from the remote host.
|
void |
sent()
This is used to tell the RemoteCall that it is in the process of transmission
to the remote object.
|
RemoteCall |
set(Wrapper[] parameters) |
RemoteCall |
setClassCreator(Class creator)
This is used to set a special class creator.
|
static void |
setIncomingCallLogger(RemoteCall.IncomingCallLogger logger) |
RemoteCall |
setParameters(Object[] parameters)
Use this to set the parameters as standard Java Wrappers - the same
as you would use with java.lang.reflect.Method invokation.
|
RemoteCall |
setTimeout(int milliseconds)
This sets the timeout time for this RemoteCall.
|
String |
toString()
Create a remote call from a received encoded call.
|
addParent, changeAccepted, changed, check, check, checkAbortFail, checkAny, checkChangeAccepted, checkFailure, convertError, doChangeTo, fail, getChangeState, getErrorText, getFinalReturnValue, getProperties, getReturnValue, getStoppableWaitOnSuccess, getUnwrappedReturnValue, hasStopped, interrupt, newWaitOnChange, removeParent, resetProgress, set, setFlags, setProgress, setProgress, setResult, setReturnValue, start, startDoing, stop, 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 String method
public String retType
public String id
public Class classCreator
public Throwable invocationError
public int timeOut
public RemoteCallHandler myHandler
public boolean replied
public RemoteCall(String method)
Standard Java type specifiers are used, specifically.
B - byte, C - char, S - short, I - int, J - long, F - float, D - Double
Z - boolean, V - void (for method types only)
[type-specifier - for an array.
LclassName; - for object (NOTE the ending semi-colon).
For object (L) you should use / instead of . as the package separator.
The format for a method is: method_name(concatenated parameter type specifiers)return_type
There are no separators between the parameter type specifiers. If the the method is void you should use V as the return type.
public RemoteCall(Method method)
public RemoteCall(byte[] source, int offset, int length) throws StreamCorruptedException, ClassNotFoundException
public RemoteCall getCopy()
public RemoteCall setClassCreator(Class creator)
creator
- A Class object that was loaded from the same class loader.public RemoteCall addParameter(Wrapper w)
w
- a Wrapper with the parameter value. It must be of the correct type.public RemoteCall add(char value)
value
- The character parameterpublic RemoteCall add(long value)
value
- The long value to add.public RemoteCall add(double value)
value
- The double or float value to add.public RemoteCall add(boolean value)
value
- The boolean value to add.public RemoteCall add(Object value)
value
- The object or array value to add.public RemoteCall addParameter(Object value)
value
- the parameter to add.public RemoteCall set(Wrapper[] parameters)
public RemoteCall setParameters(Object[] parameters)
parameters
- the parameter list.public int encodeBytes(ByteArray dest) throws IllegalStateException
ByteEncodable
encodeBytes
in interface ByteEncodable
dest
- The destination ByteArray, or null to determine the number of bytes needed to encode.IllegalStateException
public ByteArray invokeOn(Object dest, Class r)
dest
- The destination Object to invoke the method on - can ber
- The Reflect object for the destination Object.public ByteArray invokeOn(Object dest, Class r, RemoteCallTask rct)
public static void setIncomingCallLogger(RemoteCall.IncomingCallLogger logger)
public static RemoteCall.IncomingCallLogger getIncomingCallLogger()
protected boolean invokeOn(Object dest, Class r, ByteArray ba, RemoteCallTask rct)
public void sent()
public RemoteCall setTimeout(int milliseconds)
milliseconds
- the timeout in milliseconds. Setting it to zero will cause the
remote call handler timeout to be used instead.public void reply(ByteArray reply)
public RemoteCall callAndWait(RemoteCallHandler handler, String targetCode)
public Wrapper call(RemoteCallHandler handler, String targetCode) throws InvocationTargetException, RemoteCallException, TimedOutException
handler
- the RemoteCallHandler handling the call.targetCode
- the target object.RemoteCallException
- if an error occured during the RemoteCall.TimedOutException
- if the remote call timed out before a reply was made.InvocationTargetException
public RemoteCall callAsync(RemoteCallHandler handler, String targetCode)
public RemoteCall callAsync()
public Wrapper getReturnValue()
public Throwable getException()
public Wrapper call(String targetCode) throws RemoteCallException, TimedOutException, InvocationTargetException
targetCode
- the target object.RemoteCallException
- if an error occured during the RemoteCall.TimedOutException
InvocationTargetException
public Wrapper call() throws RemoteCallException, TimedOutException, InvocationTargetException
RemoteCallException
- if an error occured during the RemoteCall.TimedOutException
- if the operation took too long to complete.InvocationTargetException
public String toString()
public byte[] encodeBytes()
encodeBytes
in interface ByteEncodable