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
|
// **********************************************************************
//
// Copyright (c) 2003-2007 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 <IceUtil/UUID.h>
#include <Ice/LocalException.h>
#include <Ice/ObjectAdapter.h>
#include <IceGrid/SessionServantLocatorI.h>
using namespace std;
using namespace IceGrid;
SessionServantLocatorI::SessionServantLocatorI(const Ice::ObjectAdapterPtr& adapter, const string& instanceName) :
_adapter(adapter),
_instanceName(instanceName)
{
}
Ice::ObjectPtr
SessionServantLocatorI::locate(const Ice::Current& current, Ice::LocalObjectPtr&)
{
Lock sync(*this);
map<Ice::Identity, SessionServant>::const_iterator p = _servants.find(current.id);
if(p == _servants.end() || p->second.connection != current.con)
{
return 0;
}
return p->second.servant;
}
void
SessionServantLocatorI::finished(const Ice::Current&, const Ice::ObjectPtr&, const Ice::LocalObjectPtr&)
{
}
void
SessionServantLocatorI::deactivate(const std::string&)
{
Lock sync(*this);
_servants.clear();
}
Ice::ObjectPrx
SessionServantLocatorI::add(const Ice::ObjectPtr& servant, const Ice::ConnectionPtr& con)
{
Lock sync(*this);
Ice::Identity id;
id.name = IceUtil::generateUUID();
id.category = _instanceName;
if(!_servants.insert(make_pair(id, SessionServant(servant, con))).second)
{
throw Ice::AlreadyRegisteredException(__FILE__, __LINE__, "servant", id.name);
}
return _adapter->createProxy(id);
}
void
SessionServantLocatorI::remove(const Ice::Identity& id)
{
Lock sync(*this);
_servants.erase(id);
}
|