2 #include "ServerRequest_Interceptor2.h"
3 #include "orbsvcs/FT_CORBA_ORBC.h"
5 #include "tao/ORB_Constants.h"
6 #include "tao/AnyTypeCode/DynamicC.h"
7 #include "tao/AnyTypeCode/TypeCode.h"
9 #include "ace/Log_Msg.h"
10 #include "ace/OS_NS_string.h"
11 #include "ace/OS_NS_stdio.h"
12 #include "ace/OS_NS_unistd.h"
14 #include "ace/OS_NS_sys_time.h"
16 TAO249_ServerRequest_Interceptor2::TAO249_ServerRequest_Interceptor2 ()
22 TAO249_ServerRequest_Interceptor2::~TAO249_ServerRequest_Interceptor2 ()
28 TAO249_ServerRequest_Interceptor2::name ()
30 return CORBA::string_dup ("TAO_TAO249_ServerRequest_Interceptor2");
34 TAO249_ServerRequest_Interceptor2::destroy ()
39 TAO249_ServerRequest_Interceptor2::receive_request_service_contexts (
40 PortableInterceptor::ServerRequestInfo_ptr
)
45 TAO249_ServerRequest_Interceptor2::receive_request (
46 PortableInterceptor::ServerRequestInfo_ptr ri
)
48 CORBA::String_var op
= ri
->operation ();
50 if (ACE_OS::strcmp (op
.in (), "drop_down_dead"))
52 // bail if not the op we are interested in -
53 // avoid excess spurious error clutter when client calls ::shutdown
59 IOP::ServiceContext_var sc
=
60 ri
->get_request_service_context (IOP::FT_REQUEST
);
62 TAO_InputCDR
cdr (reinterpret_cast <const char*>
63 (sc
->context_data
.get_buffer ()
65 sc
->context_data
.length ());
67 CORBA::Boolean byte_order
;
69 if ((cdr
>> ACE_InputCDR::to_boolean (byte_order
)) == 0)
71 throw CORBA::BAD_PARAM (CORBA::OMGVMCID
| 28, CORBA::COMPLETED_NO
);
74 cdr
.reset_byte_order (static_cast <int>(byte_order
));
76 FT::FTRequestServiceContext ftrsc
;
78 if ((cdr
>> ftrsc
) == 0)
79 throw CORBA::BAD_PARAM (CORBA::OMGVMCID
| 28, CORBA::COMPLETED_NO
);
81 FILE* last_exp_time_file
= ACE_OS::fopen ("last_expiration_time", "r+");
82 TimeBase::TimeT last_exp_time
= 0;
84 if (!last_exp_time_file
)
86 // file does not exist ... we're the first server
87 // create new file for the expiration time
88 last_exp_time_file
= ACE_OS::fopen ("last_expiration_time", "w+");
89 last_exp_time
= ftrsc
.expiration_time
;
93 // We're a subsequent server... read in the previous server's expiration time
94 ACE_OS::fread (&last_exp_time
,
96 sizeof (TimeBase::TimeT
),
101 if (last_exp_time
!= ftrsc
.expiration_time
)
103 ACE_DEBUG ((LM_DEBUG
, "Test Failed - REGRESSION !!! Different expiration times used on consecutive retries of the same op!!\n"));
104 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT("Previous expiration: %Q\n"), last_exp_time
));
105 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT("Current expiration : %Q\n"), ftrsc
.expiration_time
));
110 // This is the offset from UTC to posix - a value less than than this will
111 // indicate posix is (mistakenly) being used
112 TimeBase::TimeT the_seventies
= ACE_UINT64_LITERAL (0x1B21DD213814000);
114 // @warning - this test is fragile. It will break in 2358 A.D. :-)
115 if (last_exp_time
<= the_seventies
)
117 ACE_DEBUG ((LM_ERROR
, "Test Failed - REGRESSION !!! Expiration time is in wrong format - it is before 1970 A.D. !!\n"));
118 ACE_DEBUG ((LM_DEBUG
, "Expiration time: %Q\n", last_exp_time
));
119 ACE_DEBUG ((LM_DEBUG
, "1970 A.D. : %Q\n", the_seventies
));
122 else if ( last_exp_time
> (the_seventies
* 2))
124 ACE_DEBUG ((LM_ERROR
, "Test Failed - REGRESSION !!! Expiration time is garbage - it is after 2358 A.D. !!\n"));
125 ACE_DEBUG ((LM_DEBUG
, "Expiration time: %Q\n", last_exp_time
));
126 ACE_DEBUG ((LM_DEBUG
, "2358 A.D. : %Q\n", (the_seventies
* 2)));
130 TimeBase::TimeT now
= get_now ();
132 if (now
> last_exp_time
)
134 // We have passed the exp time... there should be no more retries received after this point...
135 FILE* no_more_retries
= ACE_OS::fopen ("no_more_retries", "r+");
138 TimeBase::TimeT last_expired_attempt
= 0;
139 ACE_OS::fread (&last_expired_attempt
, 1, sizeof (TimeBase::TimeT
), no_more_retries
);
140 ACE_OS::fclose (no_more_retries
);
142 // There has already been an attempt after the last server passed the expiration time
143 ACE_DEBUG ((LM_ERROR
, "Test Failed - REGRESSION !!! Client ORB is still retrying after the expiration time!!\n"));
144 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT("Expiration time : %Q\n"), last_exp_time
));
145 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT("Previous attempt : %Q\n"), last_expired_attempt
));
146 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT("Time now : %Q\n"), now
));
151 // Tell the next server we've passed the point of no return
152 no_more_retries
= ACE_OS::fopen ("no_more_retries", "w+");
153 ACE_OS::fwrite (&now
, 1, sizeof (TimeBase::TimeT
), no_more_retries
);
154 ACE_OS::fflush (no_more_retries
);
155 ACE_OS::fclose (no_more_retries
);
159 // Everthing is fine so far. Write out the expiration time for the next server to check
160 ACE_OS::fwrite (&ftrsc
.expiration_time
, 1, sizeof (TimeBase::TimeT
), last_exp_time_file
);
161 ACE_OS::fflush (last_exp_time_file
);
162 ACE_OS::fclose (last_exp_time_file
);
164 // Goodbye cruel world !!
167 catch (const CORBA::Exception
& ex
)
169 ACE_DEBUG ((LM_ERROR
, "Unexpected (non regression problem) error - test failed\n"));
170 ex
._tao_print_exception (
171 "Exception in TAO249_ServerRequest_Interceptor2::receive_request\n");
178 TAO249_ServerRequest_Interceptor2::get_now ()
181 const TimeBase::TimeT timeOffset
= ACE_UINT64_LITERAL (0x1B21DD213814000);
184 ACE_Time_Value time_value
= ACE_OS::gettimeofday ();
186 TimeBase::TimeT sec_part
= time_value
.sec ();
187 sec_part
= sec_part
* 10000000;
188 TimeBase::TimeT usec_part
= time_value
.usec ();
189 usec_part
= usec_part
* 10;
190 return (sec_part
+ usec_part
+ timeOffset
);
194 TAO249_ServerRequest_Interceptor2::send_reply (
195 PortableInterceptor::ServerRequestInfo_ptr
)
200 TAO249_ServerRequest_Interceptor2::send_exception (
201 PortableInterceptor::ServerRequestInfo_ptr
)
206 TAO249_ServerRequest_Interceptor2::send_other (
207 PortableInterceptor::ServerRequestInfo_ptr
)