summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Event/ECG_Reconnect_ConsumerEC_Control.h
blob: 16a43c799d702b7e0d2cfa0b6ba2a1b36f8d5e3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/* -*- C++ -*- */
/**
 *  @file   ECG_Reconnect_ConsumerEC_Control.h
 *
 *  $Id$
 *
 *  @author Johnny Willemsen (jwillemsen@remedy.nl)
 *
 */

#ifndef TAO_ECG_RECONNECT_CONSUMEREC_CONTROL_H
#define TAO_ECG_RECONNECT_CONSUMEREC_CONTROL_H

#include /**/ "ace/pre.h"

#include "ECG_ConsumerEC_Control.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "tao/ORB.h"

#include "ace/Event_Handler.h"

class TAO_ECG_Reconnect_ConsumerEC_Control;
class TAO_EC_Gateway_IIOP;

/**
 * @class TAO_ECG_Reconnect_ConsumerEC_Control_Adapter
 *
 * @brief Forwards timeout events to the Reconnect ConsumerControl
 *
 * The Reconnect ConsumerControl strategy uses the reactor to
 * periodically wakeup and verify the state of the consumers
 * registered with the Event Channel.
 */
class TAO_RTEvent_Export TAO_ECG_Reconnect_ConsumerEC_Control_Adapter
  : public ACE_Event_Handler
{
public:
  /// Constructor
  TAO_ECG_Reconnect_ConsumerEC_Control_Adapter (TAO_ECG_Reconnect_ConsumerEC_Control *adaptee);

  // = Documented in ACE_Event_Handler.
  virtual int handle_timeout (const ACE_Time_Value &tv,
                              const void *arg = 0);

private:
  /// The adapted object
  TAO_ECG_Reconnect_ConsumerEC_Control *adaptee_;
};

/**
 * @class TAO_ECG_Reconnect_ConsumerEC_Control
 *
 * @brief Consumer event channel control
 *
 * Defines the interface for the consumer event channel control strategy.
 * This strategy handles misbehaving or failing consumer event channels.
 *
 * This control tries to reconnect to the consumer ec incase of a connection
 * loss and then does a reconnect when the connection is back again. When also
 * a restart of the consumer ec must be handled correctly, then the consumer
 * ec must use a persistent IOR.
 */
class TAO_RTEvent_Export TAO_ECG_Reconnect_ConsumerEC_Control
  : public TAO_ECG_ConsumerEC_Control
{
public:
  /// Constructor.  It does not assume ownership of the @a event_channel
  /// parameter.
  TAO_ECG_Reconnect_ConsumerEC_Control (const ACE_Time_Value &rate,
                                                const ACE_Time_Value &timeout,
                                                TAO_EC_Gateway_IIOP* gateway,
                                                CORBA::ORB_ptr orb);

  /// Destructor.
  virtual ~TAO_ECG_Reconnect_ConsumerEC_Control (void);

  /// Receive the timeout from the adapter
  void handle_timeout (const ACE_Time_Value &tv,
                       const void* arg);

  // = Documented in TAO_EC_ConsumerControl
  virtual int activate (void);
  virtual int shutdown (void);
  virtual void event_channel_not_exist (TAO_EC_Gateway_IIOP *gateway
                                        ACE_ENV_ARG_DECL_NOT_USED);
  virtual void system_exception (TAO_EC_Gateway_IIOP *gateway,
                                 CORBA::SystemException &
                                 ACE_ENV_ARG_DECL_NOT_USED);

private:
  /// Check if the consumers still exists.  It is a helper method for
  /// handle_timeout() to isolate the exceptions.
  void query_eventchannel (ACE_ENV_SINGLE_ARG_DECL);

  /// Look if we can reconnect again.
  void try_reconnect (ACE_ENV_SINGLE_ARG_DECL);

  /// Reconnect to the consumer ec.
  void reconnect (ACE_ENV_SINGLE_ARG_DECL);

private:
  /// The polling rate
  ACE_Time_Value rate_;

  /// The polling timeout
  ACE_Time_Value timeout_;

  /// The Adapter for the reactor events
  TAO_ECG_Reconnect_ConsumerEC_Control_Adapter adapter_;

  /// The gateway
  TAO_EC_Gateway_IIOP* gateway_;

  /// The ORB
  CORBA::ORB_var orb_;

  /// To control the timeout policy in the thread
  CORBA::PolicyCurrent_var policy_current_;

  /// Precomputed policy list to the set timeout.
  CORBA::PolicyList policy_list_;

  /// The ORB reactor
  ACE_Reactor *reactor_;

  /// Do we have a connection to the consumer ec
  int is_consumer_ec_connected_;
};

#include /**/ "ace/post.h"

#endif /* TAO_ECG_RECONNECT_CONSUMEREC_CONTROL_H */