EvictorBase.h
1.15 KB
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
#ifndef EVICTORBASE_H
#define EVICTORBASE_H
#include <Ice/Ice.h>
#include <map>
#include <list>
#include <mutex>
class EvictorBase : public Ice::ServantLocator
{
public:
EvictorBase(int size = 1000);
virtual std::shared_ptr<Ice::Object> locate(const Ice::Current&, std::shared_ptr<void>&) override;
virtual void finished(const Ice::Current&, const std::shared_ptr<Ice::Object>&, const std::shared_ptr<void>&) override;
virtual void deactivate(const std::string&) override;
protected:
virtual std::shared_ptr<Ice::Object> add(const Ice::Current&, std::shared_ptr<void>&) = 0;
virtual void evict(const std::shared_ptr<Ice::Object>&, const std::shared_ptr<void>&) = 0;
private:
struct EvictorEntry;
using EvictorMap = std::map<Ice::Identity, std::shared_ptr<EvictorEntry>>;
using EvictorQueue = std::list<EvictorMap::iterator>;
struct EvictorEntry
{
std::shared_ptr<Ice::Object> servant;
std::shared_ptr<void> userCookie;
EvictorQueue::iterator queuePos;
int useCount;
};
EvictorMap _map;
EvictorQueue _queue;
int _size;
std::mutex _mutex;
void evictServants();
};
#endif