summaryrefslogtreecommitdiff
path: root/CIAO/performance-tests/Benchmark/Multi_Threaded/client.cpp
blob: 7eba85955274cd4aef32108d5a9f931e48a6821f (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
//
// $Id$
//

//==============================================================
/**
 * @file client.cpp
 *
 * This is a client program that also acts as an Event Trigger. Four client tasks simultaneously
 * send out trigger to the ClientRoundTrip component to start the latency measurements in
 * parallel. This test is used to test scalability as the number of client components increase
 *
 * @author Arvind S. Krishna <arvindk@dre.vanderbilt.edu>
 */
//===============================================================

#include "Client_Task.h"
#include "tao/Strategies/advanced_resource.h"

//IOR of the components
const char *ior1 = "file://comp1.ior";
const char *ior2 = "file://comp2.ior";
const char *ior3 = "file://comp3.ior";
const char *ior4 = "file://comp4.ior";


int
main (int argc, char *argv[])
{
  ACE_TRY_NEW_ENV
    {

      // Initialize orb
      CORBA::ORB_var orb = CORBA::ORB_init (argc,
                                            argv,
                                            ""
                                            ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      // Resolve HomeFinder interface
      CORBA::Object_var obj1
        = orb->string_to_object (ior1 ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      CORBA::Object_var obj2
        = orb->string_to_object (ior2 ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      CORBA::Object_var obj3
        = orb->string_to_object (ior3 ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      CORBA::Object_var obj4
        = orb->string_to_object (ior4 ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      if (CORBA::is_nil (obj1.in ()) ||
          CORBA::is_nil (obj2.in ()) ||
          CORBA::is_nil (obj3.in ()) ||
          CORBA::is_nil (obj4.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Nil Benchmark::RoundtripClient reference \n"),
                            1);
        }

      //Narrow to appropriate interfaces
      Benchmark::RoundTripClient_var client1=
        Benchmark::RoundTripClient::_narrow (obj1.in());
      ACE_TRY_CHECK;

      Benchmark::RoundTripClient_var client2=
        Benchmark::RoundTripClient::_narrow (obj1.in());
      ACE_TRY_CHECK;

      Benchmark::RoundTripClient_var client3=
        Benchmark::RoundTripClient::_narrow (obj1.in());
      ACE_TRY_CHECK;

      Benchmark::RoundTripClient_var client4=
        Benchmark::RoundTripClient::_narrow (obj1.in());
      ACE_TRY_CHECK;

      //Create Tasks
      Client_Task task1(client1.in());
      Client_Task task2(client2.in());
      Client_Task task3(client3.in());
      Client_Task task4(client4.in());

      task1.activate(THR_NEW_LWP | THR_JOINABLE);
      task2.activate(THR_NEW_LWP | THR_JOINABLE);
      task3.activate(THR_NEW_LWP | THR_JOINABLE);
      task4.activate(THR_NEW_LWP | THR_JOINABLE);

      task1.thr_mgr()->wait();
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception Caught:");
      return 1;
    }
  ACE_ENDTRY;
  return 0;
}