1 #ifndef CACHEEXPORTERWORKER_
2 #define CACHEEXPORTERWORKER_
4 #include "Tourist/LocalNode.h"
5 #include "Tourist/Util/Util.h"
6 #include "Tourist/AvlCache.h"
7 #include "Tourist/Message/RemoteNode.h"
8 #include "Tourist/Message/MessageDispatcher.h"
9 #include "Tourist/Message/MessageNotification.h"
10 #include "Poco/Runnable.h"
11 #include "Poco/AutoPtr.h"
12 #include "Poco/NotificationQueue.h"
14 using Tourist::Message::RemoteNode
;
15 using Tourist::Message::MessageDispatcher
;
16 using Tourist::Message::MessageNotification
;
19 using Poco::NotificationQueue
;
23 //forwar declaration of LocalNode
26 class MsgCacheXferRequest
;
33 class CacheXferWorker
: public Runnable
38 * Creates a worker thread.
40 * @param contactNode Remote node to ask for nodes.
41 * @param threadName Name of the thread
42 * @param request Encapsulate the request parameters.
43 * @param dispatcher Instance of message bus to use for message communication
45 CacheXferWorker (RemoteNode
*contactNode
, string threadName
,
46 Tourist::Message::MsgCacheXferRequest
*request
, MessageDispatcher
*dispatcher
,
49 CacheXferWorker (RemoteNode
*contactNode
, string threadName
, \
50 Tourist::Message::MsgCacheXferRequest
*remoteRequest
, MessageDispatcher
*dispatcher
,
51 LocalNode
*localnode
, int timeout
= 5);
55 //void changeState(int event);
66 //Return the container holding the result of cache exchange.
69 //Return the status of operation performed by this worker thread.
73 * Callback method from the message bus (MessageDispatcher)
74 * This method enquee the message object as delivered by dispatcher
75 * thread this is to ensure the no delay for message delivery task.
77 void onMessage(const AutoPtr
<MessageNotification
>& notification
);
81 static int TASK_REMOTE_TO_LOCAL
;//Transfer routing cache from remote node to local.
82 static int TASK_LOCAL_TO_REMOTE
;//Transfer routing cache from local node to remote.
84 static int STATUS_UNKNOWN
; //Initial transfer status
85 static int STATUS_TIMEDOUT
;// Transfer failed as operation timedout. Usually this means
86 // an error in communication.
87 static int STATUS_TIMEDOUT_PARTIAL
; //Transfer failed as operation timedout. Usually this means
88 // that there was some partial transfer of cache.
89 static int STATUS_CONNECT_FAILED
; //indicates that remote node is not connected.
92 //< state codes declaration > //
93 const static int AWAIT_RESPONSE
; //indicates that worker is waiting for the transfer to finish.
94 const static int PROCESSING_RESPONSE
; //indicates that worker is/was processing response
98 static int RESPONSE_RECVD
;
99 static int RESPONSE_OK
;
100 static int RESPONSE_PARTIAL
;
101 static int STOPPED
; //indicate that controller asked for stopping this thread
109 //called to clean-up any resources used by this
113 void processResponse();
115 void processRequest();
117 RemoteNode
*contactNode
;
119 //suggest if this worker thread should run or not.
120 //No gurantte is made that if the thread will actually be running
122 bool shouldbeRunning
;
124 //Indicates whether the thread is actually stopped or not
127 //Name of the worker thread
132 //Result of worker threads are put in this set to let controller
136 //status are mentioned in the controller class 'CacheXfer'
142 NotificationQueue queue
;
144 //Type of work this worker thread is going to do. Currently
145 //these tasks includes (a) Asking a remote node to transfer its cache
146 //with a specified cache type and range of levels. (b) To transfer
147 //cache of LocalNode to remote node.
150 Tourist::Message::MsgCacheXferRequest
*xferRequest
;
152 MessageDispatcher
*dispatcher
;
154 Tourist::LocalNode
*node
;
156 //for reference counting
158 static int ref_count
;
162 } // namespace Tourist
165 #endif /*CACHEEXPORTERWORKER_*/