public class RemoteCallTask extends Object implements InvocationHandler
A RemoteCallTask provides an easy way to create an object that is to be controlled remotely via RemoteCalls, or to act as a local proxy for a remote object that will be controlled via RemoteCalls.
The usual way to use this is to construct it using a Steaming connection that has been made between the two communicating entities and then provide methods for servicing the remote calls. That is to say, the default method of setup is to have incoming remote calls be invoked on this very object.
Modifier and Type | Field and Description |
---|---|
RemoteCallHandlerObject |
handler
This is the handler used for incoming/outgoing calls.
|
ClassLoader |
proxyClassLoader
If you are using the createProxy() method, this is the ClassLoader
that is used to create the proxy.
|
Constructor and Description |
---|
RemoteCallTask()
Create a new RemoteCallTask.
|
RemoteCallTask(BlockInputStream in,
BlockOutputStream out)
Create a new RemoteCallTask that automatically calls start() with the specified streams.
|
RemoteCallTask(BlockInputStream in,
BlockOutputStream out,
Object target,
Class targetClass)
Create a new RemoteCallTask that automatically calls start() with the specified streams and
target object.
|
RemoteCallTask(InputStream in,
OutputStream out)
Create a new RemoteCallTask that automatically calls start() with the specified streams.
|
RemoteCallTask(InputStream in,
OutputStream out,
Object target,
Class targetClass)
Create a new RemoteCallTask that automatically calls start() with the specified streams and
target object.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the handler, and the stream.
|
static void |
connect(RemoteCallTask one,
RemoteCallTask two)
Make and start a connection between two RemoteCall tasks.
|
protected void |
connectionClosed()
This gets called when the connection between the two RemoteHandlers is
closed.
|
InputStream |
connectToRemoteInputStream(String remoteName,
String myName) |
OutputStream |
connectToRemoteOutputStream(String remoteName,
String myName) |
Object |
createProxy(Class interf)
Create a Proxy for the specified interface that will operate by making
remote calls over this RemoteCall, to the default
target object.
|
Object |
createProxy(Class[] interfaces,
String targetName)
Create a Proxy for the specified interface that will operate by making
remote calls over this RemoteCall.
|
Object |
createProxy(Class interf,
String targetName)
Create a Proxy for the specified interface that will operate by making
remote calls over this RemoteCallTask.
|
static RemoteCallTask |
createProxyClient(Object input,
Object output)
Create a RemoteCallTask that can be used for creating proxies for interfaces which
are then called using a single Thread only.
|
static RemoteCallTask |
createProxyClient(Socket connection)
Create a RemoteCallTask that can be used for creating proxies for interfaces which
are then called using a single Thread only.
|
void |
createServerInputStream(InputStream local,
String name) |
void |
createServerOutputStream(OutputStream local,
String name) |
static RemoteCallTask[] |
createTest(Object target1,
Class target1Class,
Object target2,
Class target2Class)
Create two RemoteCallTask objects connected via MemoryStreams.
|
Object |
invoke(Object proxy,
Method method,
Object[] args) |
RemoteCall |
newCall(Method method)
Get a new RemoteCall to be invoked on the object on the other side of the
connection.
|
RemoteCall |
newCall(String method)
Get a new RemoteCall to be invoked on the object on the other side of the
connection.
|
RemoteCall |
newCall(String methodName,
Class[] parameterTypes,
Class returnType)
Get a new RemoteCall to be invoked on the object on the other side of the
connection.
|
void |
run(RemoteCallHandlerObject handler)
Run and don't return until the RemoteCallTask has closed (due to the connection
being closed).
|
void |
start(BlockInputStream in,
BlockOutputStream out,
Object targetObject,
Class targetClass)
Start the RemoteCallHandler - only use this if you used the default constructor.
|
void |
start(InputStream in,
OutputStream out,
Object targetObject,
Class targetClass)
Start the RemoteCallHandler - only use this if you used the default constructor.
|
void |
start(RemoteCallHandlerObject handler)
Start in multithreaded mode.
|
void |
start(RemoteCallHandlerObject handler,
boolean startMultiThreaded)
Start using a predefined handler.
|
public RemoteCallHandlerObject handler
public ClassLoader proxyClassLoader
public RemoteCallTask()
public RemoteCallTask(InputStream in, OutputStream out, Object target, Class targetClass)
in
- the input stream to the remote application.out
- the output stream to the remote application.target
- The target object that incoming remote calls will be invoked on. If it is null
then incoming remote calls will be invoked on this object.public RemoteCallTask(InputStream in, OutputStream out)
in
- the input stream to the remote application.out
- the output stream to the remote application.target
- The target object that incoming remote calls will be invoked on.public RemoteCallTask(BlockInputStream in, BlockOutputStream out, Object target, Class targetClass)
in
- the input stream to the remote application.out
- the output stream to the remote application.target
- The target object that incoming remote calls will be invoked on. If it is null
then incoming remote calls will be invoked on this object.public RemoteCallTask(BlockInputStream in, BlockOutputStream out)
in
- the input stream to the remote application.out
- the output stream to the remote application.target
- The target object that incoming remote calls will be invoked on.public void start(RemoteCallHandlerObject handler, boolean startMultiThreaded)
public void start(RemoteCallHandlerObject handler)
handler
- the handler for the Task.public void run(RemoteCallHandlerObject handler)
public void start(InputStream in, OutputStream out, Object targetObject, Class targetClass)
in
- the input stream to the remote application.out
- the output stream to the remote application.target
- The target object that incoming remote calls will be invoked on. If it is null
then incoming remote calls will be invoked on this object.public void start(BlockInputStream in, BlockOutputStream out, Object targetObject, Class targetClass)
in
- the input stream to the remote application.out
- the output stream to the remote application.target
- The target object that incoming remote calls will be invoked on. If it is null
then incoming remote calls will be invoked on this object.public RemoteCall newCall(String method)
method
- The full encoded method name and parameters.public RemoteCall newCall(Method method)
method
- A method matching the method to be called on the other side.public RemoteCall newCall(String methodName, Class[] parameterTypes, Class returnType)
methodName
- the name of the method.parameterTypes
- the parameter types.returnType
- the return type of the method.protected void connectionClosed()
public void close()
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
invoke
in interface InvocationHandler
Throwable
public Object createProxy(Class interf, String targetName)
interf
- the interface implemented by the proxy.targetName
- the name of the target object on the remote connection.public Object createProxy(Class[] interfaces, String targetName)
interfaces
- the interfaces implemented by the proxy.targetName
- the name of the target object on the remote connection.public Object createProxy(Class interf)
interf
- the interface implemented by the proxy.public static RemoteCallTask[] createTest(Object target1, Class target1Class, Object target2, Class target2Class)
target1
- the Object that will have calls invoked on in the first
created RemoteCallTask.target1Class
- the Class to use for finding methods on Target1.
If this is null then getClass() will be used on target1 to determine the class.target2
- the Object that will have calls invoked on in the second
created RemoteCallTask.target2Class
- the Class to use for finding methods on Target2.
If this is null then getClass() will be used on target2 to determine the class.public static void connect(RemoteCallTask one, RemoteCallTask two)
one
- the first RemoteCallTask.two
- the second RemoteCallTask.public static RemoteCallTask createProxyClient(Object input, Object output) throws IOException
input
- - this can be an InputStream, a BlockInputStream or a Socket.output
- - this can be an OutputStream, a BlockOutputStream or a Socket.IOException
public static RemoteCallTask createProxyClient(Socket connection) throws IOException
input
- - this can be an InputStream, a BlockInputStream or a Socket.output
- - this can be an OutputStream, a BlockOutputStream or a Socket.IOException
public void createServerInputStream(InputStream local, String name)
public void createServerOutputStream(OutputStream local, String name)
public InputStream connectToRemoteInputStream(String remoteName, String myName)
public OutputStream connectToRemoteOutputStream(String remoteName, String myName)