1 #include "ace/OS_NS_unistd.h"
2 #include "ace/OS_NS_stdio.h"
4 #include "ace/streams.h"
5 #include "ace/CORBA_macros.h"
7 #include "ace/Monitor_Control/Monitor_Control.h"
9 #include "tao/Monitor/Monitor.h"
13 #if defined (TAO_HAS_MONITOR_FRAMEWORK) && (TAO_HAS_MONITOR_FRAMEWORK == 1)
15 using namespace ACE_VERSIONED_NAMESPACE_NAME::ACE::Monitor_Control
;
17 const ACE_TCHAR
*ior_input_file
= ACE_TEXT("file://test.ior");
18 const ACE_TCHAR
*monitor_output_file
= ACE_TEXT("monitor.ior");
20 /// Runs the ORB in a separate thread so we can listen
21 /// for calls on our MC interface without blocking.
22 class ORB_Runner
: public ACE_Task_Base
28 ORB_Runner (CORBA::ORB_ptr orb
)
39 #endif /* TAO_HAS_MONITOR_FRAMEWORK==1 */
42 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
44 #if defined (TAO_HAS_MONITOR_FRAMEWORK) && (TAO_HAS_MONITOR_FRAMEWORK == 1)
48 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
50 Monitor_Base
*bytes_sent_monitor
=
51 create_os_monitor
<BYTES_SENT_MONITOR
> (0, ACE_Time_Value (1));
52 Monitor_Base
*cpu_load_monitor
=
53 create_os_monitor
<CPU_LOAD_MONITOR
> (0, ACE_Time_Value (1));
54 Monitor_Base
*memory_usage_monitor
=
55 create_os_monitor
<MEMORY_USAGE_MONITOR
> (0, ACE_Time_Value (1));
56 Monitor_Base
*num_threads_monitor
=
57 create_os_monitor
<NUM_THREADS_MONITOR
> (0, ACE_Time_Value (1));
59 START_PERIODIC_MONITORS
;
61 /// Here we take on aspects of a server role, exposing the
62 /// Monitor interface of our ORB so the monitoring client
63 /// can access it remotely. No need to activate the POA
64 /// manager etc here - it is done in the Object_Loader code
65 /// in the Monitor lib.
66 CORBA::Object_var obj
=
67 orb
->resolve_initial_references ("Monitor");
68 Monitor::MC_var monitor
= Monitor::MC::_narrow (obj
.in ());
70 CORBA::String_var ior
= orb
->object_to_string (monitor
.in ());
72 FILE *output_file
= ACE_OS::fopen (monitor_output_file
, "w");
76 ACE_ERROR_RETURN ((LM_ERROR
,
77 "Can't open output file for writing IOR: %s",
82 ACE_OS::fprintf (output_file
,
85 ACE_OS::fclose (output_file
);
87 /// Call orb->run() in a separate thread so the MC interface can
89 ORB_Runner
orb_runner (orb
.in ());
90 orb_runner
.activate ();
92 obj
= orb
->string_to_object (ior_input_file
);
94 if (CORBA::is_nil (obj
.in ()))
96 ACE_ERROR_RETURN ((LM_ERROR
,
97 "string_to_object failed.\n"),
101 test_var target
= test::_narrow (obj
.in ());
103 /// Let the monitor client query a time or two.
106 /// Create 1k, 2k and 3k strings to marshal, to force resizing of
107 /// the CDR stream buffer.
108 for (int i
= 1; i
< 4; ++i
)
110 char *tmp
= new char[1024 * i
+ 1];
111 ACE_OS::memset (tmp
, 'a', 1024 * i
);
112 tmp
[1024 * i
] = '\0';
113 CORBA::String_var result
= target
->test_op (tmp
);
114 cout
<< "reply to client = " << ACE_OS::strlen (result
.in ())
121 /// Make sure the monitor client is done before we destroy the ORB
122 /// and make the MC objref invalid.
125 STOP_PERIODIC_MONITORS
;
127 bytes_sent_monitor
->remove_ref ();
128 cpu_load_monitor
->remove_ref ();
129 memory_usage_monitor
->remove_ref ();
130 num_threads_monitor
->remove_ref ();
134 catch (const CORBA::Exception
&ex
)
136 ex
._tao_print_exception ("Client: exception caught:");
139 #else /* ACE_HAS_MONITOR_FRAMEWORK==1 */
140 ACE_UNUSED_ARG (argc
);
141 ACE_UNUSED_ARG (argv
);
142 #endif /* TAO_HAS_MONITOR_FRAMEWORK==1 */