2 #include "AMH_Servant.h"
3 #include "Timer_Handler.h"
5 #include "ace/Reactor.h"
6 #include "ace/Get_Opt.h"
9 AMH_Servant::AMH_Servant (CORBA::ORB_ptr orb
)
12 // @@ Mayur, why do you obtain the reactor each time this method is
13 // called? Why not just cache it once in the constructor.
14 // Furthermore, you don't appear to need the ORB pseudo-reference
15 // anything other than to obtain the Reactor. Why not just
16 // remove the cached ORB pseudo-reference altogether?
18 // Mayur: Good point. Never crossed my mind :)
19 this->reactor_
= orb
->orb_core ()->reactor ();
22 AMH_Servant::~AMH_Servant (void)
27 AMH_Servant::parse_args (int &argc
, ACE_TCHAR
**argv
)
29 // *** To get correct behaviour, SET POSIXLY_CORECT=1 on Linux
31 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("s:"));
35 while ((c
= get_opts ()) != -1)
42 int time
= ACE_OS::atoi (get_opts
.opt_arg ());
44 this->sleep_time_
= time
;
46 // Remove the option '-s' from argv []
47 // to avoid any confusion that might result.
49 for (int i
= count_argv
; i
< argc
; i
++)
50 argv
[i
] = argv
[i
+2];
53 // Decrement the value of this->argc_ to reflect the removal
69 // Note: Only the following three methods will be called in the event
70 // loop. If we make sure these three methods are thread safe, the
71 // entire class is thread-safe.
74 AMH_Servant::test_method (Test::AMH_RoundtripResponseHandler_ptr _tao_rh
,
75 Test::Timestamp send_time
)
79 // @@ Mayur, the below Timer_Handler instance will leak if your
80 // schedule_timer() call below fails (which you do not check
81 // for). If the schedule_timer() call fails, then you should
82 // delete() the Timer_Handler instance.
86 // Handler will 'kill' itself when it is done.
87 Timer_Handler
*handler
= new Timer_Handler (_tao_rh
,
90 // We assume the schedule_timer method is thread-safe
91 long l
= this->reactor_
->schedule_timer (handler
,
93 ACE_Time_Value (0, this->sleep_time_
));
95 if (l
== -1) //schedule timer failed
100 // send a no-op to the client
101 _tao_rh
->test_method (static_cast<Test::Timestamp
> (0));
103 // just in case we add code later on after this if stmt
107 catch (const CORBA::Exception
& ex
)
109 ex
._tao_print_exception ("Exception in start_test\n");
112 // Footnote: This method is thread-safe:
113 // - We have no common state (and don't alter any).
114 // - We do things only through function calls which means we are using
115 // the thread-specific stack for that function call.
119 AMH_Servant::start_test (Test::AMH_RoundtripResponseHandler_ptr _tao_rh
)
123 _tao_rh
->start_test ();
125 catch (const CORBA::Exception
& ex
)
127 ex
._tao_print_exception ("Exception in start_test\n");
132 AMH_Servant::end_test (Test::AMH_RoundtripResponseHandler_ptr _tao_rh
)
136 _tao_rh
->end_test ();
138 catch (const CORBA::Exception
& ex
)
140 ex
._tao_print_exception ("Exception in end_test\n");
145 //Global Footnote: This whole class seems to be thread-safe (and look ma, no locks! :)