public abstract class DistributedAlgorithm extends Algorithm implements Startable
Algorithm.AlgorithmConstructor
Modifier and Type | Field and Description |
---|---|
protected MessageDispatcher |
messageDisp
Message dispatcher for this distributed algorithm
|
log, maximalConcurrentOperations
Constructor and Description |
---|
DistributedAlgorithm(java.lang.String algorithmName)
Creates a new instance of DistributedAlgorithm without broadcast capabilities.
|
DistributedAlgorithm(java.lang.String algorithmName,
int port)
Creates a new instance of DistributedAlgorithm without broadcast capabilities.
|
DistributedAlgorithm(java.lang.String algorithmName,
int port,
int broadcastPort)
Creates a new instance of DistributedAlgorithm.
|
DistributedAlgorithm(java.lang.String algorithmName,
MessageDispatcher parentDispatcher,
int nodeID)
Creates a new instance of DistributedAlgorithm with a higher-level message dispatcher queue.
|
Modifier and Type | Method and Description |
---|---|
protected DistAlgReplyMessage |
createReplyMessage(DistAlgRequestMessage msg)
Creates a reply message used by this algorithm.
|
protected DistAlgRequestMessage |
createRequestMessage(AbstractOperation operation)
Creates a request message used by this algorithm.
|
protected void |
deregisterMessageStatistics(java.util.Collection<Statistics<?>> stats)
Unbind given statistics.
|
<T extends AbstractOperation> |
executeOperation(T operation)
Execute operation on this algorithm.
|
void |
finalize()
Finalize the algorithm.
|
protected java.lang.Class<?>[] |
getExecutorParamClasses()
This method should return an array of additional parameters that are needed for operation execution.
|
MessageDispatcher |
getMessageDispatcher()
Returns the message dispatcher of this distributed algorithm.
|
java.lang.String |
getName()
Returns the name of this algorithm with host:port of its message dispatcher
|
NetworkNode |
getThisNode()
Returns the network node of this distributed algorithm.
|
static void |
mergeOperationsFromReplies(AbstractOperation targetOperation,
java.util.Collection<? extends DistAlgReplyMessage> replyMessages)
Update supplied operation answer with partial answers from reply messages
|
void |
mergeStatisticsFromReplies(OperationStatistics targetStatistics,
java.util.Collection<? extends ReplyMessage> replyMessages)
Update supplied statistics with partial statistics from reply messages
|
void |
mergeStatisticsFromReplies(OperationStatistics targetStatistics,
java.util.Collection<? extends ReplyMessage> replyMessages,
OperationStatistics localStats)
Update supplied statistics with partial statistics from reply messages
|
protected int |
navigationAfterProcessing(AbstractOperation operation,
DistAlgRequestMessage request,
ReplyReceiver<? extends DistAlgReplyMessage> receiver)
Processes navigation after the local processing.
|
protected ReplyReceiver<? extends DistAlgReplyMessage> |
navigationBeforeProcessing(AbstractOperation operation,
DistAlgRequestMessage request,
java.util.Collection<NetworkNode> nodes)
Processes navigation before the local processing.
|
protected ReplyReceiver<? extends DistAlgReplyMessage> |
navigationBeforeProcessing(AbstractOperation operation,
DistAlgRequestMessage request,
NetworkNode node)
Processes navigation before the local processing.
|
protected void |
navigationNoProcessing(AbstractOperation operation,
DistAlgRequestMessage request,
java.util.Collection<NetworkNode> nodes)
Processes navigation when there will be no local processing.
|
protected void |
navigationNoProcessing(AbstractOperation operation,
DistAlgRequestMessage request,
NetworkNode node)
Processes navigation when there will be no local processing.
|
protected void |
receiveRequest(DistAlgRequestMessage msg)
Execute algorithm operation from received message.
|
protected java.util.Collection<Statistics<?>> |
setupMessageStatistics(Message msg)
Given a just-arrived message, this method registers (binds) DC, DC.Savings and BlockReads statistics
for current thread.
|
afterStoreToFile, backgroundExecuteOperation, backgroundExecuteOperationIndependent, backgroundExecuteOperationWithStatistics, beforeStoreToFile, createBackgroundExecutionCallable, destroy, execute, executeMethodWithStringArguments, executeUsingNavDir, getAllRunningOperations, getAnnotatedConstructors, getAnnotatedConstructorsArray, getConstructorArgumentDescriptions, getConstructorDescription, getConstructorDescriptionSimple, getFirstSupportedOperation, getObjectClass, getObjectCount, getOperationStatistics, getOperationsThreadPool, getOperationSubClasses, getQueryAnswer, getQueryAnswer, getRunningOperationById, getRunningOperationsCount, getSupportedOperations, getSupportedOperations, methodExecute, resetOperationStatistics, restoreFromFile, restoreFromFile, setExecutedOperationsLogVerbosity, setOperationsThreadPool, setupStatsAndExecuteOperation, statisticsAfterOperation, statisticsBeforeOperation, storeToFile, terminateOperation, terminateOperation, waitBackgroundExecution
protected final MessageDispatcher messageDisp
public DistributedAlgorithm(java.lang.String algorithmName, int port, int broadcastPort) throws java.lang.IllegalArgumentException
algorithmName
- the name of this algorithmport
- the TCP/UDP port on which this distributed algorithm communicatesbroadcastPort
- the UDP multicast port that this distributed algorithm uses for broadcastjava.lang.IllegalArgumentException
- if the prototype returned by getExecutorParamClasses
has no items or there was a problem starting message dispatcherpublic DistributedAlgorithm(java.lang.String algorithmName, int port) throws java.lang.IllegalArgumentException
algorithmName
- the name of this algorithmport
- the TCP/UDP port on which this distributed algorithm communicatesjava.lang.IllegalArgumentException
- if the prototype returned by getExecutorParamClasses
has no items or there was a problem starting message dispatcherpublic DistributedAlgorithm(java.lang.String algorithmName) throws java.lang.IllegalArgumentException
getThisNode()
.algorithmName
- the name of this algorithmjava.lang.IllegalArgumentException
- if the prototype returned by getExecutorParamClasses
has no items or there was a problem starting message dispatcherpublic DistributedAlgorithm(java.lang.String algorithmName, MessageDispatcher parentDispatcher, int nodeID) throws java.lang.IllegalArgumentException
algorithmName
- the name of this algorithmparentDispatcher
- the higher level dispatcher this algorithm's dispacher is connected tonodeID
- the sub-identification of this algorithm's dispatcher for the higher leveljava.lang.IllegalArgumentException
- if the prototype returned by getExecutorParamClasses
has no items or there was a problem starting message dispatcherpublic void finalize() throws java.lang.Throwable
Algorithm
public java.lang.String getName()
public NetworkNode getThisNode()
public MessageDispatcher getMessageDispatcher()
protected void receiveRequest(DistAlgRequestMessage msg) throws AlgorithmMethodException
msg
- the received message that holds the operationAlgorithmMethodException
- if there was an error executing operationprotected java.util.Collection<Statistics<?>> setupMessageStatistics(Message msg) throws java.lang.InstantiationException
msg
- new arrived messagejava.lang.InstantiationException
protected void deregisterMessageStatistics(java.util.Collection<Statistics<?>> stats)
stats
- set of stats to unbindpublic <T extends AbstractOperation> T executeOperation(T operation) throws AlgorithmMethodException, java.lang.NoSuchMethodException
executeOperation
in class Algorithm
T
- the type of executed operationoperation
- the operation to execute on this algorithmAlgorithmMethodException
- if the execution has thrown an exceptionjava.lang.NoSuchMethodException
- if the operation is unsupported (there is no method for the operation)protected java.lang.Class<?>[] getExecutorParamClasses()
Algorithm.execute(boolean, java.lang.Object...)
and #backgroundExecute
.getExecutorParamClasses
in class Algorithm
protected DistAlgRequestMessage createRequestMessage(AbstractOperation operation)
operation
- the operation for which to create the request messageprotected DistAlgReplyMessage createReplyMessage(DistAlgRequestMessage msg)
msg
- the request message for which to create a responseprotected void navigationNoProcessing(AbstractOperation operation, DistAlgRequestMessage request, NetworkNode node) throws java.io.IOException
DistAlgRequestMessage
is created, sent to the specified node
and the method waits for all the responses. This method blocks until all the
responses are gathered.operation
- the operation that is processedrequest
- the request from which the the operation arrived (the first node has null request)node
- the destination node where to forward the requestjava.io.IOException
- if there was an I/O error during sending or receiving messagesprotected void navigationNoProcessing(AbstractOperation operation, DistAlgRequestMessage request, java.util.Collection<NetworkNode> nodes) throws java.io.IOException
DistAlgRequestMessage
is created, sent to the specified nodes
and the method waits for all the responses. This method blocks until all the
responses are gathered.operation
- the operation that is processedrequest
- the request from which the the operation arrived (the first node has null request)nodes
- the destination nodes where to forward the requestjava.io.IOException
- if there was an I/O error during sending or receiving messagesprotected ReplyReceiver<? extends DistAlgReplyMessage> navigationBeforeProcessing(AbstractOperation operation, DistAlgRequestMessage request, java.util.Collection<NetworkNode> nodes) throws java.io.IOException
DistAlgRequestMessage
is created, sent to the specified nodes
and the reply receiver for waiting for their responses is returned (i.e. the processing is not blocked).operation
- the operation that is processedrequest
- the request from which the the operation arrived (the first node has null request)nodes
- the destination nodes where to forward the requestjava.io.IOException
- if there was an I/O error during sending messagesprotected ReplyReceiver<? extends DistAlgReplyMessage> navigationBeforeProcessing(AbstractOperation operation, DistAlgRequestMessage request, NetworkNode node) throws java.io.IOException
DistAlgRequestMessage
is created, sent to the specified node
and the reply receiver for waiting for their responses is returned (i.e. the processing is not blocked).operation
- the operation that is processedrequest
- the request from which the the operation arrived (the first node has null request)node
- the destination node where to forward the requestjava.io.IOException
- if there was an I/O error during sending messagesprotected int navigationAfterProcessing(AbstractOperation operation, DistAlgRequestMessage request, ReplyReceiver<? extends DistAlgReplyMessage> receiver) throws java.io.IOException
operation
- the operation that is processedrequest
- the request from which the the operation arrived (the first node has null request)receiver
- the receiver that is used for waiting for messages (can be null)java.io.IOException
- if there was an I/O error during sending messagespublic static void mergeOperationsFromReplies(AbstractOperation targetOperation, java.util.Collection<? extends DistAlgReplyMessage> replyMessages)
targetOperation
- the operation that should be updatedreplyMessages
- the list of reply messages received with partial answerspublic void mergeStatisticsFromReplies(OperationStatistics targetStatistics, java.util.Collection<? extends ReplyMessage> replyMessages)
targetStatistics
- the operation statistics object that should be updatedreplyMessages
- the list of reply messages received with partial statisticspublic void mergeStatisticsFromReplies(OperationStatistics targetStatistics, java.util.Collection<? extends ReplyMessage> replyMessages, OperationStatistics localStats)
targetStatistics
- the operation statistics object that should be updatedreplyMessages
- the list of reply messages received with partial statisticslocalStats
- statistics of local processing of the operation on this node