Package org.apfloat.samples
Class PiDistributed.Node
- java.lang.Object
-
- org.apfloat.samples.RemoteOperationExecutor
-
- org.apfloat.samples.PiDistributed.Node
-
- All Implemented Interfaces:
java.lang.Comparable<PiDistributed.Node>
,OperationExecutor
- Enclosing class:
- PiDistributed
protected static class PiDistributed.Node extends RemoteOperationExecutor implements java.lang.Comparable<PiDistributed.Node>
RemoteOperationExecutor that implements the weight property.
-
-
Field Summary
Fields Modifier and Type Field Description private int
numberOfProcessors
private int
weight
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(PiDistributed.Node that)
Compare this Node to another Node.<T> T
execute(Operation<T> operation)
Execute an operation remotely.<T> BackgroundOperation<T>
executeBackground(Operation<T> operation)
Execute an operation remotely.int
getNumberOfProcessors()
Get the number of processors.int
getWeight()
Returns the relative weight of this executor.void
setNumberOfProcessors(int numberOfProcessors)
Set the number of processors.void
setWeight(int weight)
Set the weight.java.lang.String
toString()
Convert to String.-
Methods inherited from class org.apfloat.samples.RemoteOperationExecutor
getHost, getPort
-
-
-
-
Constructor Detail
-
Node
public Node(java.lang.String host, int port, int weight)
Construct a Node with the specified parameters and one processor.- Parameters:
host
- The remote host.port
- The remote port.weight
- The weight.
-
Node
public Node(java.lang.String host, int port, int weight, int numberOfProcessors)
Construct a Node with the specified parameters.- Parameters:
host
- The remote host.port
- The remote port.weight
- The weight.numberOfProcessors
- The number of processors.
-
-
Method Detail
-
execute
public <T> T execute(Operation<T> operation)
Description copied from class:RemoteOperationExecutor
Execute an operation remotely. This method will block until the return value has been received.- Specified by:
execute
in interfaceOperationExecutor
- Overrides:
execute
in classRemoteOperationExecutor
- Type Parameters:
T
- Return value type of the operation.- Parameters:
operation
- The operation to execute remotely.- Returns:
- The result of the operation.
-
executeBackground
public <T> BackgroundOperation<T> executeBackground(Operation<T> operation)
Description copied from class:RemoteOperationExecutor
Execute an operation remotely. This method starts a new thread running the remote call and returns immediately.- Specified by:
executeBackground
in interfaceOperationExecutor
- Overrides:
executeBackground
in classRemoteOperationExecutor
- 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.
-
setWeight
public void setWeight(int weight)
Set the weight.- Parameters:
weight
- The weight.
-
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
- Overrides:
getWeight
in classRemoteOperationExecutor
- Returns:
- The relative weight of this operation executor.
-
setNumberOfProcessors
public void setNumberOfProcessors(int numberOfProcessors)
Set the number of processors.- Parameters:
numberOfProcessors
- The number of processors.
-
getNumberOfProcessors
public int getNumberOfProcessors()
Get the number of processors.- Returns:
- The number of processors.
-
compareTo
public int compareTo(PiDistributed.Node that)
Compare this Node to another Node.- Specified by:
compareTo
in interfacejava.lang.Comparable<PiDistributed.Node>
- Parameters:
that
- The other node to compare to.- Returns:
- A number less than zero if this Node should be ordered before the other node, or gerater than zero for the reverse order. Should not return zero.
-
toString
public java.lang.String toString()
Convert to String.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The string representation.
-
-