blob: 785a650f7f00f377d9745514af32c3f345ccd308 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
// **********************************************************************
//
// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
#include <Ice/RetryQueue.h>
#include <Ice/OutgoingAsync.h>
#include <Ice/LocalException.h>
#include <Ice/Instance.h>
using namespace std;
using namespace Ice;
using namespace IceInternal;
IceUtil::Shared* IceInternal::upCast(RetryQueue* p) { return p; }
IceInternal::RetryTask::RetryTask(const RetryQueuePtr& queue, const OutgoingAsyncMessageCallbackPtr& outAsync) :
_queue(queue), _outAsync(outAsync)
{
}
void
IceInternal::RetryTask::runTimerTask()
{
if(_queue->remove(this))
{
_outAsync->__processRetry(false);
}
}
void
IceInternal::RetryTask::destroy()
{
_outAsync->__processRetry(true);
}
bool
IceInternal::RetryTask::operator<(const RetryTask& rhs) const
{
return this < &rhs;
}
IceInternal::RetryQueue::RetryQueue(const InstancePtr& instance) : _instance(instance)
{
}
void
IceInternal::RetryQueue::add(const OutgoingAsyncMessageCallbackPtr& out, int interval)
{
Lock sync(*this);
if(!_instance)
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
RetryTaskPtr task = new RetryTask(this, out);
try
{
_instance->timer()->schedule(task, IceUtil::Time::milliSeconds(interval));
}
catch(const IceUtil::IllegalArgumentException&) // Expected if the communicator destroyed the timer.
{
throw CommunicatorDestroyedException(__FILE__, __LINE__);
}
_requests.insert(task);
}
void
IceInternal::RetryQueue::destroy()
{
Lock sync(*this);
_instance = 0;
for(set<RetryTaskPtr>::const_iterator p = _requests.begin(); p != _requests.end(); ++p)
{
_instance->timer()->cancel(*p);
(*p)->destroy();
}
_requests.clear();
}
bool
IceInternal::RetryQueue::remove(const RetryTaskPtr& task)
{
Lock sync(*this);
return _requests.erase(task) > 0;
}
|