2 //=============================================================================
4 * @file FT_FaultConsumer.cpp
6 * This file is part of TAO's implementation of Fault Tolerant CORBA.
7 * This file provides the implementation of the TAO::FT_FaultConsumer
8 * class. The TAO::FT_FaultConsumer connects to the FaultNotifier to
9 * receive fault reports. It interacts with the ReplicationManager
10 * to process fault reports (e.g., to set a new primary on an object
11 * group or to create a new member of an object group).
13 * @author Steve Totten <totten_s@ociweb.com>
15 //=============================================================================
17 #include "orbsvcs/Log_Macros.h"
18 #include "FT_FaultConsumer.h"
19 #include "orbsvcs/FT_ReplicationManagerC.h"
20 #include "orbsvcs/FT_ReplicationManager/FT_FaultAnalyzer.h"
21 #include "tao/debug.h"
23 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
25 /// Default constructor.
26 TAO::FT_FaultConsumer::FT_FaultConsumer ()
27 : poa_ (PortableServer::POA::_nil ())
28 , fault_notifier_ (FT::FaultNotifier::_nil ())
31 , consumer_ref_ (CosNotifyComm::StructuredPushConsumer::_nil ())
37 TAO::FT_FaultConsumer::~FT_FaultConsumer ()
42 * Connect to the FT::FaultNotifier.
43 * Note: We make the following assumptions about what the
44 * application will do:
45 * - Create an instance of this consumer class.
46 * - Obtain the object reference of the FaultNotifier to which this
47 * consumer should connect.
48 * - Call this init() method, passing it the POA with which we
49 * have been activated, the FaultNotifier, and ReplicationManager
52 int TAO::FT_FaultConsumer::init (
53 PortableServer::POA_ptr poa
,
54 FT::FaultNotifier_ptr fault_notifier
,
55 TAO::FT_FaultAnalyzer
* fault_analyzer
)
57 if (TAO_debug_level
> 1)
59 ORBSVCS_DEBUG ((LM_DEBUG
,
61 "Enter TAO::FT_FaultConsumer::init.\n")
65 ACE_ASSERT (!CORBA::is_nil (poa
));
66 ACE_ASSERT (!CORBA::is_nil (fault_notifier
));
67 ACE_ASSERT (fault_analyzer
!= 0);
69 // Duplicate the object references passed in.
71 PortableServer::POA::_duplicate (poa
);
72 this->fault_notifier_
=
73 FT::FaultNotifier::_duplicate (fault_notifier
);
75 // We have no ownership responsibilities for the Fault Analyzer.
76 this->fault_analyzer_
= fault_analyzer
;
78 //@@ Should this init() method activate the consumer in the POA, or
79 // should the application do that?
80 // I don't think this object can activate itself because it doesn't
81 // know the policies on the POA. So, we assume the application has
82 // already activated us.
83 //@@ For now, let's try just activating it in the POA.
85 // Activate this consumer in the POA.
86 this->object_id_
= this->poa_
->activate_object (this);
87 CORBA::Object_var obj
=
88 this->poa_
->id_to_reference (this->object_id_
.in());
90 // Narrow it to CosNotifyComm::StructuredPushConsumer.
91 this->consumer_ref_
= CosNotifyComm::StructuredPushConsumer::_narrow (
94 // Subscribe to the FaultNotifier.
95 CosNotifyFilter::Filter_var filter
= CosNotifyFilter::Filter::_nil ();
96 this->consumer_id_
= fault_notifier_
->connect_structured_fault_consumer (
97 this->consumer_ref_
.in(), filter
.in ());
99 if (TAO_debug_level
> 1)
101 ORBSVCS_DEBUG ((LM_DEBUG
,
103 "Leave TAO::FT_FaultConsumer::init.\n")
112 * Clean house for process shut down.
113 * - Disconnect from FT::FaultNotifier.
114 * - Deactivate from the POA.
116 int TAO::FT_FaultConsumer::fini ()
118 if (TAO_debug_level
> 1)
120 ORBSVCS_DEBUG ((LM_DEBUG
,
121 ACE_TEXT ("Enter TAO::FT_FaultConsumer::fini.\n")
125 // Disconnect from the FaultNotifier.
126 // Swallow any exception.
129 if (!CORBA::is_nil (this->fault_notifier_
.in()))
131 if (TAO_debug_level
> 1)
133 ORBSVCS_DEBUG ((LM_DEBUG
,
134 ACE_TEXT ("TAO::FT_FaultConsumer::fini: ")
135 ACE_TEXT ("Disconnecting consumer from FaultNotifier.\n")
139 this->fault_notifier_
->disconnect_consumer (
142 if (TAO_debug_level
> 1)
144 ORBSVCS_DEBUG ((LM_DEBUG
,
145 ACE_TEXT ("TAO::FT_FaultConsumer::fini: ")
146 ACE_TEXT ("Deactivating from POA.\n")
150 // Deactivate ourself from the POA.
151 this->poa_
->deactivate_object (
152 this->object_id_
.in());
155 catch (const CORBA::Exception
& ex
)
157 ex
._tao_print_exception (
158 ACE_TEXT ("TAO::FT_FaultConsumer::fini: ")
159 ACE_TEXT ("Error disconnecting from notifier (ignored).\n"));
162 if (TAO_debug_level
> 1)
164 ORBSVCS_DEBUG ((LM_DEBUG
,
165 ACE_TEXT ("TAO::FT_FaultConsumer::fini: ")
166 ACE_TEXT ("Setting our object reference to nil.\n")
170 this->consumer_ref_
= CosNotifyComm::StructuredPushConsumer::_nil ();
172 if (TAO_debug_level
> 1)
174 ORBSVCS_DEBUG ((LM_DEBUG
,
175 ACE_TEXT ("Leave TAO::FT_FaultConsumer::fini.\n")
183 CosNotifyComm::StructuredPushConsumer_ptr
184 TAO::FT_FaultConsumer::consumer_ref ()
186 return CosNotifyComm::StructuredPushConsumer::_duplicate (
187 this->consumer_ref_
.in ());
190 size_t TAO::FT_FaultConsumer::notifications () const
192 return this->notifications_
;
199 // Receive and process an incoming fault event from the Fault Notifier.
200 // First, we validate the event to make sure it is something we can
201 // handle. Then, we analyze it. If it is not an event we can handle,
202 // we simply log the error and drop the event.
203 void TAO::FT_FaultConsumer::push_structured_event (
204 const CosNotification::StructuredEvent
&event
207 // Debugging support.
208 this->notifications_
+= 1;
209 if (TAO_debug_level
> 1)
211 ORBSVCS_DEBUG ((LM_DEBUG
,
212 ACE_TEXT ("TAO::FT_FaultConsumer::push_structured_event: ")
213 ACE_TEXT ("Received Fault notification(%d):\n"),
214 static_cast<unsigned int> (this->notifications_
)
220 // Make sure it is an event type we can handle.
223 result
= this->fault_analyzer_
->validate_event_type (event
);
226 ORBSVCS_ERROR ((LM_ERROR
,
227 ACE_TEXT ("TAO::FT_FaultConsumer::push_structured_event: ")
228 ACE_TEXT ("Received invalid fault event type.\n")
233 // Analyze the event.
236 result
= this->fault_analyzer_
->analyze_fault_event (event
);
239 ORBSVCS_ERROR ((LM_ERROR
,
240 ACE_TEXT ("TAO::FT_FaultConsumer::push_structured_event: ")
241 ACE_TEXT ("Could not analyze fault event.\n")
249 void TAO::FT_FaultConsumer::offer_change (
250 const CosNotification::EventTypeSeq
& added
,
251 const CosNotification::EventTypeSeq
& removed
254 ACE_UNUSED_ARG (added
);
255 ACE_UNUSED_ARG (removed
);
256 ORBSVCS_DEBUG ((LM_DEBUG
,
257 ACE_TEXT("TAO::FT_FaultConsumer::offer_change() call ignored.\n")
261 void TAO::FT_FaultConsumer::disconnect_structured_push_consumer (
264 //TODO: For now, we are just ignoring the disconnect callback.
265 ORBSVCS_DEBUG ((LM_DEBUG
,
266 ACE_TEXT("TAO::FT_FaultConsumer::disconnect_structured_push_consumer() ")
267 ACE_TEXT("call ignored.\n")
271 TAO_END_VERSIONED_NAMESPACE_DECL