summaryrefslogtreecommitdiff
path: root/TAO/tests/LongWrites/Coordinator.cpp
blob: 8520ae199630bd2a0174e2357b749552c73afe21 (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
//
// $Id$
//
#include "Coordinator.h"

ACE_RCSID(LongWrites, Coordinator, "$Id$")

Coordinator::Coordinator (void)
  : shutdown_called_ (0)
  , pairs_count_ (0)
  , pairs_length_ (16)
{
  ACE_NEW (this->pairs_, Pair[this->pairs_length_]);
}

Coordinator::~Coordinator (void)
{
  delete[] this->pairs_;
}

void
Coordinator::add_pair (Test::Receiver_ptr receiver,
                       Test::Sender_ptr sender,
                       CORBA::Environment &)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  ACE_DEBUG ((LM_DEBUG, " new pair "));
  if (this->pairs_length_ == this->pairs_count_)
    {
      Pair *tmp;
      this->pairs_length_ *= 2;
      ACE_NEW (tmp, Pair[this->pairs_length_]);
      for (size_t i = 0; i != this->pairs_count_; ++i)
        tmp[i] = this->pairs_[i];
      delete[] this->pairs_;
      this->pairs_ = tmp;
    }
  this->pairs_[this->pairs_count_].receiver =
    Test::Receiver::_duplicate (receiver);
  this->pairs_[this->pairs_count_].sender =
    Test::Sender::_duplicate (sender);
  this->pairs_count_++;
}

void
Coordinator::start (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  for (size_t i = 0; i != this->pairs_count_; ++i)
    {
      Test::Sender_ptr sender = this->pairs_[i].sender.in ();
      for (size_t j = 0; j != this->pairs_count_; ++j)
        {
          if (i == j)
            continue;
          sender->add_receiver (this->pairs_[j].receiver.in (),
                                ACE_TRY_ENV);
          ACE_CHECK;
        }
    }

  CORBA::ULong event_size = 256 * 1024;
  ACE_DEBUG ((LM_DEBUG, "Running with payload = %d\n",
              event_size));
  for (size_t j = 0; j != this->pairs_count_; ++j)
    {
      this->pairs_[j].sender->send_events (100, event_size,
                                           ACE_TRY_ENV);
      ACE_CHECK;
    }
}

void
Coordinator::shutdown (CORBA::Environment &ACE_TRY_ENV)
  ACE_THROW_SPEC ((CORBA::SystemException))
{
  {
    ACE_GUARD (ACE_SYNCH_MUTEX, ace_mon, this->mutex_);
    this->shutdown_called_ = 1;
  }
  for (size_t i = 0; i != this->pairs_count_; ++i)
    {
      this->pairs_[i].sender->shutdown (ACE_TRY_ENV);
      ACE_CHECK;
    }
}