2 //=============================================================================
4 * @file Fault_Detector_i.cpp
6 * This file is part of Fault Tolerant CORBA.
7 * This file implements the Fault_Detector_i class as declared in Fault_Detector_i.h.
9 * @author Dale Wilson <wilson_d@ociweb.com>
11 //=============================================================================
12 #include "orbsvcs/Log_Macros.h"
13 #include "Fault_Detector_i.h"
14 #include "FT_FaultDetectorFactory_i.h"
15 #include "tao/debug.h"
17 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
19 ///////////////////////////////
20 // Fault_Detector_i static data
22 ACE_Time_Value
TAO::Fault_Detector_i::sleep_time_(1,0);
25 /////////////////////////////////////////
26 // Fault_Detector_i public static methods
28 void TAO::Fault_Detector_i::set_time_for_all_detectors(ACE_Time_Value value
)
33 ////////////////////////////////////////////
34 // Fault_Detector_i construction/destruction
36 TAO::Fault_Detector_i::Fault_Detector_i (
37 FT_FaultDetectorFactory_i
& factory
,
39 FT::FaultNotifier_ptr
& notifier
,
40 FT::PullMonitorable_ptr
& monitorable
,
41 FT::FTDomainId domain_id
,
42 const PortableGroup::Location
& object_location
,
43 PortableGroup::TypeId object_type
,
44 PortableGroup::ObjectGroupId group_id
48 , domain_id_(domain_id
)
49 , object_location_(object_location
)
50 , object_type_(object_type
)
52 , sleep_(0) // initially not signaled
55 this->notifier_
= FT::FaultNotifier::_duplicate(notifier
);
56 this->monitorable_
= FT::PullMonitorable::_duplicate(monitorable
);
57 ORBSVCS_DEBUG ((LM_DEBUG
,
58 "Object type %s\n", object_type
62 TAO::Fault_Detector_i::~Fault_Detector_i ()
66 ////////////////////////////////////
67 // Fault_Detector_i public interface
70 void TAO::Fault_Detector_i::request_quit()
72 this->quit_requested_
= 1;
74 this->sleep_
.signal ();
77 void TAO::Fault_Detector_i::start(ACE_Thread_Manager
& threadManager
)
79 threadManager
.spawn(thr_func
, this);
82 ///////////////////////////////////////////////////
83 // Fault_Detector_i private implementation methods
85 void TAO::Fault_Detector_i::run()
87 while ( ! this->quit_requested_
)
91 if (this->monitorable_
->is_alive())
93 // use this rather than ACE_OS::sleep
94 // to allow the nap to be interruped see request_quit
95 this->sleep_
.wait (&sleep_time_
, 0);
99 ORBSVCS_ERROR ((LM_INFO
,
100 "FaultDetector%d FAULT: not alive.\n",
104 this->quit_requested_
= 1;
107 catch (const CORBA::Exception
&)// todo refine this
109 ORBSVCS_ERROR ((LM_ERROR
,
110 "FaultDetector FAULT: exception.\n"
113 this->quit_requested_
= 1;
116 // warning: The following call will delete
117 // this object. Be careful not to reference
118 // member data after making this call.
119 // todo: use "scoped resource management" to make
120 // this exception-safe and stupid-return-safe.
121 this->factory_
.remove_detector (this->id_
, this);
124 void TAO::Fault_Detector_i::notify()
126 CosNotification::StructuredEvent_var vEvent
;
127 ACE_NEW_NORETURN(vEvent
, CosNotification::StructuredEvent
);
128 if (vEvent
.ptr() != 0)
130 CORBA::ULong length
= 2;
131 if( this->object_type_
!= 0)
134 if (this->group_id_
!= 0)
140 vEvent
->header
.fixed_header
.event_type
.domain_name
= FT::FT_EVENT_TYPE_DOMAIN
;
141 vEvent
->header
.fixed_header
.event_type
.type_name
= FT::FT_EVENT_TYPE_NAME
;
142 vEvent
->filterable_data
.length(length
);
143 vEvent
->filterable_data
[0].name
= FT::FT_DOMAIN_ID
;
144 (vEvent
->filterable_data
[0].value
) <<= this->domain_id_
;
145 vEvent
->filterable_data
[1].name
= FT::FT_LOCATION
;
146 (vEvent
->filterable_data
[1].value
) <<= this->object_location_
;
147 if (this->object_type_
!= 0)
149 vEvent
->filterable_data
[2].name
= FT::FT_TYPE_ID
;
150 (vEvent
->filterable_data
[2].value
) <<= this->object_type_
;
151 if (this->group_id_
!= 0)
153 vEvent
->filterable_data
[3].name
= FT::FT_GROUP_ID
;
154 vEvent
->filterable_data
[3].value
<<= this->group_id_
;
159 if (TAO_debug_level
> 5)
161 ORBSVCS_ERROR ((LM_ERROR
,
162 "call Fault Detector push Structured Event.\n"
165 this->notifier_
->push_structured_fault(vEvent
.in());
166 if (TAO_debug_level
> 5)
168 ORBSVCS_ERROR ((LM_ERROR
,
169 "return from Fault Detector push Structured Event.\n"
173 catch (const CORBA::Exception
& ex
)
175 ex
._tao_print_exception ("Fault Detector cannot send notification.");
180 ORBSVCS_ERROR ((LM_ERROR
,
181 "Fault Detector cannot create Structured Event.\n"
187 /////////////////////////////////////////////////////////
188 // Fault_Detector_i private static implementation methods
191 ACE_THR_FUNC_RETURN
TAO::Fault_Detector_i::thr_func (void * arg
)
193 TAO::Fault_Detector_i
* detector
= static_cast<TAO::Fault_Detector_i
* > (arg
);
198 TAO_END_VERSIONED_NAMESPACE_DECL