Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / orbsvcs / FT_ReplicationManager / FT_FaultConsumer.cpp
blobf01bf130997c00d60a3acc8c4c307a750a371cdd
1 /* -*- C++ -*- */
2 //=============================================================================
3 /**
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 ())
29 , fault_analyzer_ (0)
30 , consumer_id_ (0)
31 , consumer_ref_ (CosNotifyComm::StructuredPushConsumer::_nil ())
32 , notifications_ (0)
36 /// Destructor.
37 TAO::FT_FaultConsumer::~FT_FaultConsumer ()
41 /**
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
50 * object references.
52 int TAO::FT_FaultConsumer::init (
53 PortableServer::POA_ptr poa,
54 FT::FaultNotifier_ptr fault_notifier,
55 TAO::FT_FaultAnalyzer * fault_analyzer)
58 if (TAO_debug_level > 1)
60 ORBSVCS_DEBUG ((LM_DEBUG,
61 ACE_TEXT (
62 "Enter TAO::FT_FaultConsumer::init.\n")
63 ));
66 ACE_ASSERT (!CORBA::is_nil (poa));
67 ACE_ASSERT (!CORBA::is_nil (fault_notifier));
68 ACE_ASSERT (fault_analyzer != 0);
70 // Duplicate the object references passed in.
71 this->poa_ =
72 PortableServer::POA::_duplicate (poa);
73 this->fault_notifier_ =
74 FT::FaultNotifier::_duplicate (fault_notifier);
76 // We have no ownership responsibilities for the Fault Analyzer.
77 this->fault_analyzer_ = fault_analyzer;
79 //@@ Should this init() method activate the consumer in the POA, or
80 // should the application do that?
81 // I don't think this object can activate itself because it doesn't
82 // know the policies on the POA. So, we assume the application has
83 // already activated us.
84 //@@ For now, let's try just activating it in the POA.
86 // Activate this consumer in the POA.
87 this->object_id_ = this->poa_->activate_object (this);
88 CORBA::Object_var obj =
89 this->poa_->id_to_reference (this->object_id_.in());
91 // Narrow it to CosNotifyComm::StructuredPushConsumer.
92 this->consumer_ref_ = CosNotifyComm::StructuredPushConsumer::_narrow (
93 obj.in());
95 // Subscribe to the FaultNotifier.
96 CosNotifyFilter::Filter_var filter = CosNotifyFilter::Filter::_nil ();
97 this->consumer_id_ = fault_notifier_->connect_structured_fault_consumer (
98 this->consumer_ref_.in(), filter.in ());
100 if (TAO_debug_level > 1)
102 ORBSVCS_DEBUG ((LM_DEBUG,
103 ACE_TEXT (
104 "Leave TAO::FT_FaultConsumer::init.\n")
108 // Success.
109 return 0;
113 * Clean house for process shut down.
114 * - Disconnect from FT::FaultNotifier.
115 * - Deactivate from the POA.
117 int TAO::FT_FaultConsumer::fini (void)
120 if (TAO_debug_level > 1)
122 ORBSVCS_DEBUG ((LM_DEBUG,
123 ACE_TEXT ("Enter TAO::FT_FaultConsumer::fini.\n")
127 // Disconnect from the FaultNotifier.
128 // Swallow any exception.
131 if (!CORBA::is_nil (this->fault_notifier_.in()))
134 if (TAO_debug_level > 1)
136 ORBSVCS_DEBUG ((LM_DEBUG,
137 ACE_TEXT ("TAO::FT_FaultConsumer::fini: ")
138 ACE_TEXT ("Disconnecting consumer from FaultNotifier.\n")
142 this->fault_notifier_->disconnect_consumer (
143 this->consumer_id_);
145 if (TAO_debug_level > 1)
147 ORBSVCS_DEBUG ((LM_DEBUG,
148 ACE_TEXT ("TAO::FT_FaultConsumer::fini: ")
149 ACE_TEXT ("Deactivating from POA.\n")
153 // Deactivate ourself from the POA.
154 this->poa_->deactivate_object (
155 this->object_id_.in());
158 catch (const CORBA::Exception& ex)
160 ex._tao_print_exception (
161 ACE_TEXT ("TAO::FT_FaultConsumer::fini: ")
162 ACE_TEXT ("Error disconnecting from notifier (ignored).\n"));
165 if (TAO_debug_level > 1)
167 ORBSVCS_DEBUG ((LM_DEBUG,
168 ACE_TEXT ("TAO::FT_FaultConsumer::fini: ")
169 ACE_TEXT ("Setting our object reference to nil.\n")
173 this->consumer_ref_ = CosNotifyComm::StructuredPushConsumer::_nil ();
175 if (TAO_debug_level > 1)
177 ORBSVCS_DEBUG ((LM_DEBUG,
178 ACE_TEXT ("Leave TAO::FT_FaultConsumer::fini.\n")
182 // Success.
183 return 0;
186 CosNotifyComm::StructuredPushConsumer_ptr
187 TAO::FT_FaultConsumer::consumer_ref ()
189 return CosNotifyComm::StructuredPushConsumer::_duplicate (
190 this->consumer_ref_.in ());
193 size_t TAO::FT_FaultConsumer::notifications () const
195 return this->notifications_;
199 ///////////////////
200 // CORBA operations
202 // Receive and process an incoming fault event from the Fault Notifier.
203 // First, we validate the event to make sure it is something we can
204 // handle. Then, we analyze it. If it is not an event we can handle,
205 // we simply log the error and drop the event.
206 void TAO::FT_FaultConsumer::push_structured_event (
207 const CosNotification::StructuredEvent &event
210 // Debugging support.
211 this->notifications_ += 1;
212 if (TAO_debug_level > 1)
214 ORBSVCS_DEBUG ((LM_DEBUG,
215 ACE_TEXT ("TAO::FT_FaultConsumer::push_structured_event: ")
216 ACE_TEXT ("Received Fault notification(%d):\n"),
217 static_cast<unsigned int> (this->notifications_)
221 int result = 0;
223 // Make sure it is an event type we can handle.
224 if (result == 0)
226 result = this->fault_analyzer_->validate_event_type (event);
227 if (result != 0)
229 ORBSVCS_ERROR ((LM_ERROR,
230 ACE_TEXT ("TAO::FT_FaultConsumer::push_structured_event: ")
231 ACE_TEXT ("Received invalid fault event type.\n")
236 // Analyze the event.
237 if (result == 0)
239 result = this->fault_analyzer_->analyze_fault_event (event);
240 if (result != 0)
242 ORBSVCS_ERROR ((LM_ERROR,
243 ACE_TEXT ("TAO::FT_FaultConsumer::push_structured_event: ")
244 ACE_TEXT ("Could not analyze fault event.\n")
249 return;
252 void TAO::FT_FaultConsumer::offer_change (
253 const CosNotification::EventTypeSeq & added,
254 const CosNotification::EventTypeSeq & removed
257 ACE_UNUSED_ARG (added);
258 ACE_UNUSED_ARG (removed);
259 ORBSVCS_DEBUG ((LM_DEBUG,
260 ACE_TEXT("TAO::FT_FaultConsumer::offer_change() call ignored.\n")
264 void TAO::FT_FaultConsumer::disconnect_structured_push_consumer (
267 //TODO: For now, we are just ignoring the disconnect callback.
268 ORBSVCS_DEBUG ((LM_DEBUG,
269 ACE_TEXT("TAO::FT_FaultConsumer::disconnect_structured_push_consumer() ")
270 ACE_TEXT("call ignored.\n")
274 TAO_END_VERSIONED_NAMESPACE_DECL