summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Notify/lib/Activation_Manager.h
blob: 838516b3d64650ccc49f2e4b7df4cd11055328dc (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
137
138
139
/* -*- C++ -*- */
/**
 *  @file Activation_Manager.h
 *
 *  $Id$
 *
 *  @author Pradeep Gore <pradeep@oomworks.com>
 *
 *
 */

#ifndef TAO_Notify_Tests_ACTIVATION_MANAGER_H
#define TAO_Notify_Tests_ACTIVATION_MANAGER_H
#include /**/ "ace/pre.h"

#include "notify_test_export.h"

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

#include "ace/Null_Mutex.h"
#include "ace/SString.h"
#include "ace/Hash_Map_Manager.h"
#include "Task_Callback.h"
#include "Periodic_Supplier.h"
#include "Periodic_Consumer.h"
#include "Activation_ManagerS.h"

ACE_BEGIN_VERSIONED_NAMESPACE_DECL
class ACE_Barrier;
ACE_END_VERSIONED_NAMESPACE_DECL

/**
 * @class TAO_Notify_Tests_Activation_Manager
 *
 * @brief Class to handle Suppliers and Consumers.
 *
 */
class TAO_NOTIFY_TEST_Export TAO_Notify_Tests_Activation_Manager : public TAO_Notify_Tests_Task_Callback
                                                       , public POA_Notify_Test::Activation_Manager
{
  typedef ACE_Hash_Map_Manager<ACE_CString, TAO_Notify_Tests_Periodic_Supplier*, ACE_SYNCH_NULL_MUTEX> TAO_Notify_Tests_PeriodicSupplier_Map;
  typedef ACE_Hash_Map_Manager<ACE_CString, TAO_Notify_Tests_Periodic_Consumer*, ACE_SYNCH_NULL_MUTEX> TAO_Notify_Tests_PeriodicConsumer_Map;
  typedef ACE_Hash_Map_Iterator<ACE_CString, TAO_Notify_Tests_Periodic_Supplier*, ACE_SYNCH_NULL_MUTEX> TAO_Notify_Tests_PeriodicSupplier_Iterator;
  typedef ACE_Hash_Map_Iterator<ACE_CString, TAO_Notify_Tests_Periodic_Consumer*, ACE_SYNCH_NULL_MUTEX> TAO_Notify_Tests_PeriodicConsumer_Iterator;
  typedef ACE_Hash_Map_Entry<ACE_CString, TAO_Notify_Tests_Periodic_Supplier*> TAO_Notify_Tests_PeriodicSupplier_Entry;
  typedef ACE_Hash_Map_Entry<ACE_CString, TAO_Notify_Tests_Periodic_Consumer*> TAO_Notify_Tests_PeriodicConsumer_Entry;

public:
  /// Constuctor
  TAO_Notify_Tests_Activation_Manager (void);

  /// Destructor
  virtual ~TAO_Notify_Tests_Activation_Manager ();

  /// Interface impl.
  virtual void start (ACE_ENV_SINGLE_ARG_DECL)
    ACE_THROW_SPEC ((
                     CORBA::SystemException
                     ));

  /// Register Supplier
  void _register (TAO_Notify_Tests_Periodic_Supplier* supplier, const char* obj_name ACE_ENV_ARG_DECL);
  /// Register Consumer
  void _register (TAO_Notify_Tests_Periodic_Consumer* consumer, const char* obj_name ACE_ENV_ARG_DECL);

  /// Resolve Supplier
  void resolve (TAO_Notify_Tests_Periodic_Supplier*& supplier, const char* obj_name ACE_ENV_ARG_DECL);

  /// Resolve Consumer
  void resolve (TAO_Notify_Tests_Periodic_Consumer*& consumer, const char* obj_name ACE_ENV_ARG_DECL);

  // Activate the tasks for each supplier.
  int activate_suppliers (void);

  // Supplier Count
  int supplier_count (void);

  // Consumer Count
  int consumer_count (void);

  /// Wait till active suppliers and consumers are done.
  void wait_for_completion (void);

  /// TAO_Notify_Tests_Task_Callback methods
  virtual void done (TAO_Notify_Tests_Periodic_Supplier* supplier);
  virtual void done (TAO_Notify_Tests_Periodic_Consumer* consumer);

  // Dump stats gathered during exec..
  void dump_stats (int dump_samples);

  // Returns 0 if the file could be opened for write.
  int ior_output_file (const ACE_TCHAR *file_name);

  // Returns 1 if the file could be opened for read.
  int ior_input_file (const ACE_TCHAR *file_name);

  void write_ior (ACE_ENV_SINGLE_ARG_DECL);
  void wait_for_start_signal (ACE_ENV_SINGLE_ARG_DECL);
  void signal_peer (ACE_ENV_SINGLE_ARG_DECL);

protected:
  /// Lock to serialize internal state.
  TAO_SYNCH_MUTEX lock_;

  /// The barrier to synch all supplier on so that everyone starts at the same instance.
  ACE_Barrier* barrier_;

  /// Number of Active suppliers (still running a ACE_Task and sending events)
  int active_suppliers_;

  /// Number of Active consumers (still receiving events)
  int active_consumers_;

  // Condition that all active suppliers and consumers are done.
  TAO_SYNCH_CONDITION active_done_;

  // Map that stores suppliers.
  TAO_Notify_Tests_PeriodicSupplier_Map supplier_map_;

  // Map that stores consumers.
  TAO_Notify_Tests_PeriodicConsumer_Map consumer_map_;

  /// The file for output
  FILE *ior_output_file_;

  /// The file for input
  ACE_CString ior_input_file_;

  /// Set when the start method is called.
  CORBA::Boolean started_;

  // Condition that the start method has been called.
  TAO_SYNCH_CONDITION started_condition_;
};

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