2
//=============================================================================
4
* @file FT_FaultConsumer.cpp
6
* FT_FaultConsumer.cpp,v 1.3 2003/12/30 23:53:58 wilson_d Exp
8
* This file is part of TAO's implementation of Fault Tolerant CORBA.
9
* This file provides the implementation of the TAO::FT_FaultConsumer
10
* class. The TAO::FT_FaultConsumer connects to the FaultNotifier to
11
* receive fault reports. It interacts with the ReplicationManager
12
* to process fault reports (e.g., to set a new primary on an object
13
* group or to create a new member of an object group).
15
* @author Steve Totten <totten_s@ociweb.com>
17
//=============================================================================
19
#include "FT_FaultConsumer.h"
20
#include "orbsvcs/FT_ReplicationManagerC.h"
21
#include "orbsvcs/FT_ReplicationManager/FT_FaultAnalyzer.h"
22
#include <tao/debug.h>
24
ACE_RCSID (FT_FaultConsumer,
26
"FT_FaultConsumer.cpp,v 1.3 2003/12/30 23:53:58 wilson_d Exp")
28
/// Default constructor.
29
TAO::FT_FaultConsumer::FT_FaultConsumer ()
30
: poa_ (PortableServer::POA::_nil ())
31
, fault_notifier_ (FT::FaultNotifier::_nil ())
34
, consumer_ref_ (CosNotifyComm::StructuredPushConsumer::_nil ())
40
TAO::FT_FaultConsumer::~FT_FaultConsumer ()
45
* Connect to the FT::FaultNotifier.
46
* Note: We make the following assumptions about what the
47
* application will do:
48
* - Create an instance of this consumer class.
49
* - Obtain the object reference of the FaultNotifier to which this
50
* consumer should connect.
51
* - Call this init() method, passing it the POA with which we
52
* have been activated, the FaultNotifier, and ReplicationManager
55
int TAO::FT_FaultConsumer::init (
56
PortableServer::POA_ptr poa,
57
FT::FaultNotifier_ptr fault_notifier,
58
TAO::FT_FaultAnalyzer * fault_analyzer
62
if (TAO_debug_level > 1)
66
"Enter TAO::FT_FaultConsumer::init.\n")
70
ACE_ASSERT (!CORBA::is_nil (poa));
71
ACE_ASSERT (!CORBA::is_nil (fault_notifier));
72
ACE_ASSERT (fault_analyzer != 0);
74
// Duplicate the object references passed in.
76
PortableServer::POA::_duplicate (poa);
77
this->fault_notifier_ =
78
FT::FaultNotifier::_duplicate (fault_notifier);
80
// We have no ownership responsibilities for the Fault Analyzer.
81
this->fault_analyzer_ = fault_analyzer;
83
//@@ Should this init() method activate the consumer in the POA, or
84
// should the application do that?
85
// I don't think this object can activate itself because it doesn't
86
// know the policies on the POA. So, we assume the application has
87
// already activated us.
88
//@@ For now, let's try just activating it in the POA.
90
// Activate this consumer in the POA.
91
this->object_id_ = this->poa_->activate_object (this ACE_ENV_ARG_PARAMETER);
92
ACE_CHECK_RETURN (-1);
93
CORBA::Object_var obj =
94
this->poa_->id_to_reference (this->object_id_.in() ACE_ENV_ARG_PARAMETER);
95
ACE_CHECK_RETURN (-1);
97
// Narrow it to CosNotifyComm::StructuredPushConsumer.
98
this->consumer_ref_ = CosNotifyComm::StructuredPushConsumer::_narrow (
99
obj.in() ACE_ENV_ARG_PARAMETER);
100
ACE_CHECK_RETURN (-1);
102
// Subscribe to the FaultNotifier.
103
CosNotifyFilter::Filter_var filter = CosNotifyFilter::Filter::_nil ();
104
this->consumer_id_ = fault_notifier_->connect_structured_fault_consumer (
105
this->consumer_ref_.in(), filter.in () ACE_ENV_ARG_PARAMETER);
106
ACE_CHECK_RETURN (-1);
108
if (TAO_debug_level > 1)
110
ACE_DEBUG ((LM_DEBUG,
112
"Leave TAO::FT_FaultConsumer::init.\n")
121
* Clean house for process shut down.
122
* - Disconnect from FT::FaultNotifier.
123
* - Deactivate from the POA.
125
int TAO::FT_FaultConsumer::fini (ACE_ENV_SINGLE_ARG_DECL)
128
if (TAO_debug_level > 1)
130
ACE_DEBUG ((LM_DEBUG,
131
ACE_TEXT ("Enter TAO::FT_FaultConsumer::fini.\n")
135
// Disconnect from the FaultNotifier.
136
// Swallow any exception.
139
if (!CORBA::is_nil (this->fault_notifier_.in()))
142
if (TAO_debug_level > 1)
144
ACE_DEBUG ((LM_DEBUG,
146
"TAO::FT_FaultConsumer::fini: "
147
"Disconnecting consumer from FaultNotifier.\n")
151
this->fault_notifier_->disconnect_consumer (
152
this->consumer_id_ ACE_ENV_ARG_PARAMETER);
155
if (TAO_debug_level > 1)
157
ACE_DEBUG ((LM_DEBUG,
159
"TAO::FT_FaultConsumer::fini: "
160
"Deactivating from POA.\n")
164
// Deactivate ourself from the POA.
165
this->poa_->deactivate_object (
166
this->object_id_.in() ACE_ENV_ARG_PARAMETER);
172
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
174
"TAO::FT_FaultConsumer::fini: "
175
"Error disconnecting from notifier (ignored).\n")
181
if (TAO_debug_level > 1)
183
ACE_DEBUG ((LM_DEBUG,
185
"TAO::FT_FaultConsumer::fini: "
186
"Setting our object reference to nil.\n")
190
this->consumer_ref_ = CosNotifyComm::StructuredPushConsumer::_nil ();
192
if (TAO_debug_level > 1)
194
ACE_DEBUG ((LM_DEBUG,
195
ACE_TEXT ("Leave TAO::FT_FaultConsumer::fini.\n")
203
CosNotifyComm::StructuredPushConsumer_ptr
204
TAO::FT_FaultConsumer::consumer_ref ()
206
return CosNotifyComm::StructuredPushConsumer::_duplicate (
207
this->consumer_ref_.in ());
210
size_t TAO::FT_FaultConsumer::notifications () const
212
return this->notifications_;
219
// Receive and process an incoming fault event from the Fault Notifier.
220
// First, we validate the event to make sure it is something we can
221
// handle. Then, we analyze it. If it is not an event we can handle,
222
// we simply log the error and drop the event.
223
void TAO::FT_FaultConsumer::push_structured_event (
224
const CosNotification::StructuredEvent &event
225
ACE_ENV_ARG_DECL_NOT_USED
227
ACE_THROW_SPEC ((CORBA::SystemException, CosEventComm::Disconnected))
229
// Debugging support.
230
this->notifications_ += 1;
231
if (TAO_debug_level > 1)
233
ACE_DEBUG ((LM_DEBUG,
235
"TAO::FT_FaultConsumer::push_structured_event: "
236
"Received Fault notification(%d):\n"),
237
ACE_static_cast (unsigned int, this->notifications_)
243
// Make sure it is an event type we can handle.
246
result = this->fault_analyzer_->validate_event_type (event);
249
ACE_ERROR ((LM_ERROR,
251
"TAO::FT_FaultConsumer::push_structured_event: "
252
"Received invalid fault event type.\n")
257
// Analyze the event.
260
result = this->fault_analyzer_->analyze_fault_event (event);
263
ACE_ERROR ((LM_ERROR,
265
"TAO::FT_FaultConsumer::push_structured_event: "
266
"Could not analyze fault event.\n")
274
void TAO::FT_FaultConsumer::offer_change (
275
const CosNotification::EventTypeSeq & added,
276
const CosNotification::EventTypeSeq & removed
277
ACE_ENV_ARG_DECL_NOT_USED
279
ACE_THROW_SPEC ((CORBA::SystemException, CosNotifyComm::InvalidEventType))
281
ACE_UNUSED_ARG (added);
282
ACE_UNUSED_ARG (removed);
283
ACE_DEBUG ((LM_DEBUG,
284
ACE_TEXT("TAO::FT_FaultConsumer::offer_change() call ignored.\n")
288
void TAO::FT_FaultConsumer::disconnect_structured_push_consumer (
289
ACE_ENV_SINGLE_ARG_DECL_NOT_USED
291
ACE_THROW_SPEC ((CORBA::SystemException))
293
//TODO: For now, we are just ignoring the disconnect callback.
294
ACE_DEBUG ((LM_DEBUG,
295
ACE_TEXT("TAO::FT_FaultConsumer::disconnect_structured_push_consumer() "