Package org.apfloat.samples
Class RemoteOperationExecutor
- java.lang.Object
-
- org.apfloat.samples.RemoteOperationExecutor
-
- All Implemented Interfaces:
OperationExecutor
- Direct Known Subclasses:
PiDistributed.Node
public class RemoteOperationExecutor extends java.lang.Object implements OperationExecutor
Class to call anOperationServer
to executeOperation
s remotely.- Version:
- 1.9.0
-
-
Field Summary
Fields Modifier and Type Field Description private static int
BUFFER_SIZE
private java.lang.String
host
private int
port
-
Constructor Summary
Constructors Constructor Description RemoteOperationExecutor(java.lang.String host, int port)
Create a new client that will connect to the server running at the specified host and port.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
execute(Operation<T> operation)
Execute an operation remotely.<T> BackgroundOperation<T>
executeBackground(Operation<T> operation)
Execute an operation remotely.java.lang.String
getHost()
Returns the host name.int
getPort()
Returns the host port.int
getWeight()
Returns the relative weight of this executor.
-
-
-
Field Detail
-
BUFFER_SIZE
private static final int BUFFER_SIZE
- See Also:
- Constant Field Values
-
host
private java.lang.String host
-
port
private int port
-
-
Method Detail
-
execute
public <T> T execute(Operation<T> operation)
Execute an operation remotely. This method will block until the return value has been received.- Specified by:
execute
in interfaceOperationExecutor
- Type Parameters:
T
- Return value type of the operation.- Parameters:
operation
- The operation to execute remotely.- Returns:
- The result of the operation.
- Throws:
java.lang.RuntimeException
- In case of network error or if the return value class is unknown.
-
executeBackground
public <T> BackgroundOperation<T> executeBackground(Operation<T> operation)
Execute an operation remotely. This method starts a new thread running the remote call and returns immediately.- Specified by:
executeBackground
in interfaceOperationExecutor
- Type Parameters:
T
- Return value type of the operation.- Parameters:
operation
- The operation to execute remotely.- Returns:
- A
BackgroundOperation
for retrieving the result of the operation later.
-
getWeight
public int getWeight()
Description copied from interface:OperationExecutor
Returns the relative weight of this executor. The weights of different operation executors can be used to distribute work more equally.- Specified by:
getWeight
in interfaceOperationExecutor
- Returns:
- The relative weight of this operation executor.
-
getHost
public java.lang.String getHost()
Returns the host name.- Returns:
- The host name.
-
getPort
public int getPort()
Returns the host port.- Returns:
- The host port.
-
-