ICE 3.4.2
[php5-ice-freebsdport.git] / cpp / test / Ice / hold / TestI.cpp
blob607a51853028a325c611de8b92e7c11ced2be90f
1 // **********************************************************************
2 //
3 // Copyright (c) 2003-2011 ZeroC, Inc. All rights reserved.
4 //
5 // This copy of Ice is licensed to you under the terms described in the
6 // ICE_LICENSE file included in this distribution.
7 //
8 // **********************************************************************
10 #include <Ice/Ice.h>
11 #include <IceUtil/IceUtil.h>
12 #include <TestI.h>
13 #include <TestCommon.h>
15 HoldI::HoldI(const IceUtil::TimerPtr& timer, const Ice::ObjectAdapterPtr& adapter) :
16 _last(0), _timer(timer), _adapter(adapter)
20 void
21 HoldI::putOnHold(Ice::Int milliSeconds, const Ice::Current&)
23 if(milliSeconds < 0)
25 _adapter->hold();
27 else if(milliSeconds == 0)
29 _adapter->hold();
30 _adapter->activate();
32 else
34 try
36 _timer->schedule(this, IceUtil::Time::milliSeconds(milliSeconds));
38 catch(const IceUtil::IllegalArgumentException&)
44 void
45 HoldI::waitForHold(const Ice::Current& current)
47 class WaitForHold : public IceUtil::TimerTask
49 public:
51 WaitForHold(const Ice::ObjectAdapterPtr& adapter) : _adapter(adapter)
55 void
56 runTimerTask()
58 try
60 _adapter->waitForHold();
61 _adapter->activate();
63 catch(const Ice::ObjectAdapterDeactivatedException&)
66 // This shouldn't occur. The test ensures all the waitForHold timers are
67 // finished before shutting down the communicator.
69 test(false);
73 private:
75 const Ice::ObjectAdapterPtr _adapter;
78 try
80 _timer->schedule(new WaitForHold(current.adapter), IceUtil::Time());
82 catch(const IceUtil::IllegalArgumentException&)
87 Ice::Int
88 HoldI::set(Ice::Int value, Ice::Int delay, const Ice::Current&)
90 IceUtil::ThreadControl::sleep(IceUtil::Time::milliSeconds(delay));
92 Lock sync(*this);
93 Ice::Int tmp = _last;
94 _last = value;
95 return tmp;
98 void
99 HoldI::setOneway(Ice::Int value, Ice::Int expected, const Ice::Current&)
101 Lock sync(*this);
102 test(_last == expected);
103 _last = value;
106 void
107 HoldI::shutdown(const Ice::Current&)
109 _adapter->hold();
110 _adapter->getCommunicator()->shutdown();
113 void
114 HoldI::runTimerTask()
118 _adapter->hold();
119 _adapter->activate();
121 catch(const Ice::ObjectAdapterDeactivatedException&)