00001
#ifndef maciHeartbeatController_H
00002
#define maciHeartbeatController_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
#ifndef __cplusplus
00016
#error This is a C++ include file and cannot be used from plain C
00017
#endif
00018
00019
#include <acsutil.h>
00020
#include <maciExport.h>
00021
00022
#include <maciC.h>
00023
00024
#include <ace/Timer_Heap_T.h>
00025
#include <ace/Timer_Queue_Adapters.h>
00026
00027
#include <ace/Hash_Map_Manager.h>
00028
00029
namespace maci {
00030
00031
00032
class HeartbeatController;
00033
00041 class HeartbeatHandler :
public ACE_Event_Handler
00042 {
00043
public:
00044
00051
HeartbeatHandler(
HeartbeatController * controller, maci::Handle handle, maci::Client_ptr client);
00052
00058
virtual int handle_timeout (
const ACE_Time_Value ¤tTime,
00059
const void *arg);
00060
00065
virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask);
00066
00071
void setTimerID(
long timerID);
00072
00077
long getTimerID();
00078
00083
void updateClient(maci::Client_ptr client);
00084
00085
private:
00086
00088 static int m_failureLimit;
00089
00091 maci::Handle
m_handle;
00092
00094 long m_timerID;
00095
00097 int m_failureCount;
00098
00100 maci::Client_var
m_client;
00101
00103 HeartbeatController *
m_controller;
00104
00105 };
00106
00113 class HeartbeatInitializationHandler :
public ACE_Event_Handler
00114 {
00115
public:
00116
00118 static CORBA::ULong
defaultInvocationTimeout;
00119
00125
HeartbeatInitializationHandler(CORBA::ORB_ptr orb, CORBA::ULong invocationTimeout);
00126
00132
virtual int handle_timeout (
const ACE_Time_Value ¤tTime,
00133
const void *arg);
00134
00139
virtual int handle_close (ACE_HANDLE, ACE_Reactor_Mask);
00140
00141
private:
00142
00144 CORBA::ORB_var
m_orb;
00145
00147 CORBA::ULong
m_invocationTimeout;
00148
00149 };
00150
00168 class maci_EXPORT HeartbeatController
00169 {
00170
00171
public:
00172
00173
00177 HeartbeatController(maci::Manager_ptr manager);
00178
00182 ~HeartbeatController();
00183
00190
int start(CORBA::ORB_ptr orb, CORBA::ULong invocationTimeout);
00191
00196
int stop();
00197
00202
int registerClient(maci::Handle handle, maci::Client_ptr client);
00203
00208
int deregisterClient(maci::Handle handle);
00209
00214 maci::Manager_ptr getManager();
00215
00216
private:
00217
00222
int removeClient(maci::Handle handle);
00223
00224
00226 maci::Manager_var m_manager;
00227
00228
00230
typedef ACE_Timer_Heap_T<ACE_Event_Handler *,
00231 ACE_Event_Handler_Handle_Timeout_Upcall<ACE_SYNCH_RECURSIVE_MUTEX>,
00232 ACE_SYNCH_RECURSIVE_MUTEX>
00233 HB_TIMER_QUEUE;
00234
00236
typedef ACE_Timer_Heap_Iterator_T<ACE_Event_Handler *,
00237 ACE_Event_Handler_Handle_Timeout_Upcall<ACE_SYNCH_RECURSIVE_MUTEX>,
00238 ACE_SYNCH_RECURSIVE_MUTEX>
00239 HB_TIMER_QUEUE_ITERATOR;
00240
00241 typedef ACE_Thread_Timer_Queue_Adapter<HB_TIMER_QUEUE>
HB_TIMER_THREAD;
00242
00244 HB_TIMER_THREAD m_timerThread;
00245
00247 typedef ACE_Hash_Map_Manager <maci::Handle, long, ACE_Recursive_Thread_Mutex>
HB_HASH_MAP;
00249 typedef ACE_Hash_Map_Iterator <maci::Handle, long, ACE_Recursive_Thread_Mutex>
HB_HASH_MAP_ITER;
00251 typedef ACE_Hash_Map_Entry <maci::Handle, long>
HB_HASH_MAP_ENTRY;
00252
00254 HB_HASH_MAP m_clients;
00255
00256
00257 bool m_deactivated;
00258
00259
friend class HeartbeatHandler;
00260
00261 };
00262
00263 };
00264
00265
#endif
00266
00267