1 // **********************************************************************
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
8 // **********************************************************************
10 #include <AMDInterceptorI.h>
12 #include <TestCommon.h>
14 AMDInterceptorI::AMDInterceptorI(const Ice::ObjectPtr
& servant
) :
15 InterceptorI(servant
),
16 _defaultCb(new DispatchInterceptorAsyncCallbackI(*this)),
17 _actualStatus(Ice::DispatchAsync
)
24 AMDInterceptorI::dispatch(Ice::Request
& request
)
26 class CallbackI
: public Ice::DispatchInterceptorAsyncCallback
30 CallbackI(AMDInterceptorI
& interceptor
) :
31 _interceptor(interceptor
)
35 virtual bool response(bool ok
)
41 virtual bool exception(const std::exception
& ex
)
43 test(dynamic_cast<const Test::RetryException
*>(&ex
) != 0);
47 virtual bool exception()
58 AMDInterceptorI
& _interceptor
;
62 Ice::Current
& current
= const_cast<Ice::Current
&>(request
.getCurrent());
63 _lastOperation
= current
.operation
;
65 Ice::DispatchInterceptorAsyncCallbackPtr cb
= new CallbackI(*this);
67 if(_lastOperation
== "amdAddWithRetry")
69 for(int i
= 0; i
< 10; ++i
)
71 _lastStatus
= _servant
->ice_dispatch(request
, cb
);
72 test(_lastStatus
== Ice::DispatchAsync
);
75 current
.ctx
["retry"] = "no";
78 _lastStatus
= _servant
->ice_dispatch(request
, _defaultCb
);
83 AMDInterceptorI::setActualStatus(Ice::DispatchStatus status
)
85 IceUtil::Mutex::Lock
lock(_mutex
);
86 _actualStatus
= status
;
90 AMDInterceptorI::setActualStatus(const IceUtil::Exception
& e
)
92 IceUtil::Mutex::Lock
lock(_mutex
);
93 _exception
.reset(e
.ice_clone());
94 _actualStatus
= Ice::DispatchAsync
;
98 AMDInterceptorI::getActualStatus() const
100 IceUtil::Mutex::Lock
lock(_mutex
);
101 return _actualStatus
;
105 AMDInterceptorI::getException() const
107 IceUtil::Mutex::Lock
lock(_mutex
);
108 return _exception
.get();
112 AMDInterceptorI::clear()
114 InterceptorI::clear();
115 IceUtil::Mutex::Lock
lock(_mutex
);
116 _actualStatus
= Ice::DispatchAsync
;
121 DispatchInterceptorAsyncCallbackI::DispatchInterceptorAsyncCallbackI(AMDInterceptorI
& interceptor
) :
122 _interceptor(interceptor
)
127 DispatchInterceptorAsyncCallbackI::response(bool ok
)
129 _interceptor
.setActualStatus(ok
? Ice::DispatchOK
: Ice::DispatchUserException
);
135 DispatchInterceptorAsyncCallbackI::exception(const std::exception
& ex
)
138 // Only Ice exceptions are raised by this test
140 const IceUtil::Exception
& ue
= dynamic_cast<const IceUtil::Exception
&>(ex
);
141 _interceptor
.setActualStatus(ue
);
147 DispatchInterceptorAsyncCallbackI::exception()