~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to TAO/orbsvcs/FT_ReplicationManager/FT_FaultConsumer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- C++ -*- */
2
 
//=============================================================================
3
 
/**
4
 
 *  @file    FT_FaultConsumer.cpp
5
 
 *
6
 
 *  FT_FaultConsumer.cpp,v 1.3 2003/12/30 23:53:58 wilson_d Exp
7
 
 *
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).
14
 
 *
15
 
 *  @author Steve Totten <totten_s@ociweb.com>
16
 
 */
17
 
//=============================================================================
18
 
 
19
 
#include "FT_FaultConsumer.h"
20
 
#include "orbsvcs/FT_ReplicationManagerC.h"
21
 
#include "orbsvcs/FT_ReplicationManager/FT_FaultAnalyzer.h"
22
 
#include <tao/debug.h>
23
 
 
24
 
ACE_RCSID (FT_FaultConsumer,
25
 
           FT_FaultConsumer,
26
 
           "FT_FaultConsumer.cpp,v 1.3 2003/12/30 23:53:58 wilson_d Exp")
27
 
 
28
 
/// Default constructor.
29
 
TAO::FT_FaultConsumer::FT_FaultConsumer ()
30
 
  : poa_ (PortableServer::POA::_nil ())
31
 
  , fault_notifier_ (FT::FaultNotifier::_nil ())
32
 
  , fault_analyzer_ (0)
33
 
  , consumer_id_ (0)
34
 
  , consumer_ref_ (CosNotifyComm::StructuredPushConsumer::_nil ())
35
 
  , notifications_ (0)
36
 
{
37
 
}
38
 
 
39
 
/// Destructor.
40
 
TAO::FT_FaultConsumer::~FT_FaultConsumer ()
41
 
{
42
 
}
43
 
 
44
 
/**
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
53
 
*   object references.
54
 
*/
55
 
int TAO::FT_FaultConsumer::init (
56
 
  PortableServer::POA_ptr poa,
57
 
  FT::FaultNotifier_ptr fault_notifier,
58
 
  TAO::FT_FaultAnalyzer * fault_analyzer
59
 
  ACE_ENV_ARG_DECL)
60
 
{
61
 
 
62
 
  if (TAO_debug_level > 1)
63
 
  {
64
 
    ACE_DEBUG ((LM_DEBUG,
65
 
      ACE_TEXT (
66
 
        "Enter TAO::FT_FaultConsumer::init.\n")
67
 
    ));
68
 
  }
69
 
 
70
 
  ACE_ASSERT (!CORBA::is_nil (poa));
71
 
  ACE_ASSERT (!CORBA::is_nil (fault_notifier));
72
 
  ACE_ASSERT (fault_analyzer != 0);
73
 
 
74
 
  // Duplicate the object references passed in.
75
 
  this->poa_ =
76
 
    PortableServer::POA::_duplicate (poa);
77
 
  this->fault_notifier_ =
78
 
    FT::FaultNotifier::_duplicate (fault_notifier);
79
 
 
80
 
  // We have no ownership responsibilities for the Fault Analyzer.
81
 
  this->fault_analyzer_ = fault_analyzer;
82
 
 
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.
89
 
 
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);
96
 
 
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);
101
 
 
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);
107
 
 
108
 
  if (TAO_debug_level > 1)
109
 
  {
110
 
    ACE_DEBUG ((LM_DEBUG,
111
 
      ACE_TEXT (
112
 
        "Leave TAO::FT_FaultConsumer::init.\n")
113
 
    ));
114
 
  }
115
 
 
116
 
  // Success.
117
 
  return 0;
118
 
}
119
 
 
120
 
/**
121
 
* Clean house for process shut down.
122
 
* - Disconnect from FT::FaultNotifier.
123
 
* - Deactivate from the POA.
124
 
*/
125
 
int TAO::FT_FaultConsumer::fini (ACE_ENV_SINGLE_ARG_DECL)
126
 
{
127
 
 
128
 
  if (TAO_debug_level > 1)
129
 
  {
130
 
    ACE_DEBUG ((LM_DEBUG,
131
 
      ACE_TEXT ("Enter TAO::FT_FaultConsumer::fini.\n")
132
 
    ));
133
 
  }
134
 
 
135
 
  // Disconnect from the FaultNotifier.
136
 
  // Swallow any exception.
137
 
  ACE_TRY_NEW_ENV
138
 
  {
139
 
    if (!CORBA::is_nil (this->fault_notifier_.in()))
140
 
    {
141
 
 
142
 
      if (TAO_debug_level > 1)
143
 
      {
144
 
        ACE_DEBUG ((LM_DEBUG,
145
 
          ACE_TEXT (
146
 
            "TAO::FT_FaultConsumer::fini: "
147
 
            "Disconnecting consumer from FaultNotifier.\n")
148
 
        ));
149
 
      }
150
 
 
151
 
      this->fault_notifier_->disconnect_consumer (
152
 
        this->consumer_id_ ACE_ENV_ARG_PARAMETER);
153
 
      ACE_TRY_CHECK;
154
 
 
155
 
      if (TAO_debug_level > 1)
156
 
      {
157
 
        ACE_DEBUG ((LM_DEBUG,
158
 
          ACE_TEXT (
159
 
            "TAO::FT_FaultConsumer::fini: "
160
 
            "Deactivating from POA.\n")
161
 
        ));
162
 
      }
163
 
 
164
 
      // Deactivate ourself from the POA.
165
 
      this->poa_->deactivate_object (
166
 
        this->object_id_.in() ACE_ENV_ARG_PARAMETER);
167
 
      ACE_TRY_CHECK;
168
 
    }
169
 
  }
170
 
  ACE_CATCHANY
171
 
  {
172
 
    ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
173
 
      ACE_TEXT (
174
 
        "TAO::FT_FaultConsumer::fini: "
175
 
        "Error disconnecting from notifier (ignored).\n")
176
 
    );
177
 
  }
178
 
  ACE_ENDTRY;
179
 
  ACE_CHECK_RETURN(1);
180
 
 
181
 
  if (TAO_debug_level > 1)
182
 
  {
183
 
    ACE_DEBUG ((LM_DEBUG,
184
 
      ACE_TEXT (
185
 
        "TAO::FT_FaultConsumer::fini: "
186
 
        "Setting our object reference to nil.\n")
187
 
    ));
188
 
  }
189
 
 
190
 
  this->consumer_ref_ = CosNotifyComm::StructuredPushConsumer::_nil ();
191
 
 
192
 
  if (TAO_debug_level > 1)
193
 
  {
194
 
    ACE_DEBUG ((LM_DEBUG,
195
 
      ACE_TEXT ("Leave TAO::FT_FaultConsumer::fini.\n")
196
 
    ));
197
 
  }
198
 
 
199
 
  // Success.
200
 
  return 0;
201
 
}
202
 
 
203
 
CosNotifyComm::StructuredPushConsumer_ptr
204
 
TAO::FT_FaultConsumer::consumer_ref ()
205
 
{
206
 
  return CosNotifyComm::StructuredPushConsumer::_duplicate (
207
 
      this->consumer_ref_.in ());
208
 
}
209
 
 
210
 
size_t TAO::FT_FaultConsumer::notifications () const
211
 
{
212
 
  return this->notifications_;
213
 
}
214
 
 
215
 
 
216
 
///////////////////
217
 
// CORBA operations
218
 
 
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
226
 
  )
227
 
  ACE_THROW_SPEC ((CORBA::SystemException, CosEventComm::Disconnected))
228
 
{
229
 
  // Debugging support.
230
 
  this->notifications_ += 1;
231
 
  if (TAO_debug_level > 1)
232
 
  {
233
 
    ACE_DEBUG ((LM_DEBUG,
234
 
      ACE_TEXT (
235
 
        "TAO::FT_FaultConsumer::push_structured_event: "
236
 
        "Received Fault notification(%d):\n"),
237
 
      ACE_static_cast (unsigned int, this->notifications_)
238
 
    ));
239
 
  }
240
 
 
241
 
  int result = 0;
242
 
 
243
 
  // Make sure it is an event type we can handle.
244
 
  if (result == 0)
245
 
  {
246
 
    result = this->fault_analyzer_->validate_event_type (event);
247
 
    if (result != 0)
248
 
    {
249
 
      ACE_ERROR ((LM_ERROR,
250
 
        ACE_TEXT (
251
 
          "TAO::FT_FaultConsumer::push_structured_event: "
252
 
          "Received invalid fault event type.\n")
253
 
      ));
254
 
    }
255
 
  }
256
 
 
257
 
  // Analyze the event.
258
 
  if (result == 0)
259
 
  {
260
 
    result = this->fault_analyzer_->analyze_fault_event (event);
261
 
    if (result != 0)
262
 
    {
263
 
      ACE_ERROR ((LM_ERROR,
264
 
        ACE_TEXT (
265
 
          "TAO::FT_FaultConsumer::push_structured_event: "
266
 
          "Could not analyze fault event.\n")
267
 
      ));
268
 
    }
269
 
  }
270
 
 
271
 
  return;
272
 
}
273
 
 
274
 
void TAO::FT_FaultConsumer::offer_change (
275
 
    const CosNotification::EventTypeSeq & added,
276
 
    const CosNotification::EventTypeSeq & removed
277
 
    ACE_ENV_ARG_DECL_NOT_USED
278
 
  )
279
 
  ACE_THROW_SPEC ((CORBA::SystemException, CosNotifyComm::InvalidEventType))
280
 
{
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")
285
 
  ));
286
 
}
287
 
 
288
 
void TAO::FT_FaultConsumer::disconnect_structured_push_consumer (
289
 
    ACE_ENV_SINGLE_ARG_DECL_NOT_USED
290
 
  )
291
 
  ACE_THROW_SPEC ((CORBA::SystemException))
292
 
{
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() "
296
 
             "call ignored.\n")
297
 
    ));
298
 
}
299