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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
// **********************************************************************
//
// Copyright (c) 2003-2004 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/RoutingTable.h>
#include <Glacier/RouterI.h>
#include <Glacier/Session.h>
#include <Glacier/SessionManager.h>
#include <iostream>
using namespace std;
using namespace Ice;
using namespace Glacier;
Glacier::RouterI::RouterI(const ObjectAdapterPtr& clientAdapter,
const ObjectAdapterPtr& serverAdapter,
const ::IceInternal::RoutingTablePtr& routingTable,
const SessionManagerPrx& sessionManager,
const string& userId) :
_clientAdapter(clientAdapter),
_serverAdapter(serverAdapter),
_logger(_clientAdapter->getCommunicator()->getLogger()),
_routingTable(routingTable),
_sessionManager(sessionManager),
_userId(userId)
{
PropertiesPtr properties = _clientAdapter->getCommunicator()->getProperties();
_routingTableTraceLevel = properties->getPropertyAsInt("Glacier.Router.Trace.RoutingTable");
}
Glacier::RouterI::~RouterI()
{
assert(!_clientAdapter);
assert(_sessions.empty());
}
void
Glacier::RouterI::destroy()
{
//
// No mutex protection necessary, destroy is only called after all
// object adapters have shut down.
//
_clientAdapter = 0;
_serverAdapter = 0;
_logger = 0;
_routingTable = 0;
for(vector<SessionPrx>::const_iterator p = _sessions.begin(); p != _sessions.end(); ++p)
{
try
{
(*p)->destroy();
}
catch(...)
{
// Ignore all exceptions.
}
}
_sessions.clear();
}
ObjectPrx
Glacier::RouterI::getClientProxy(const Current&) const
{
assert(_clientAdapter); // Destroyed?
return _clientAdapter->createProxy(stringToIdentity("dummy"));
}
ObjectPrx
Glacier::RouterI::getServerProxy(const Current&) const
{
assert(_clientAdapter); // Destroyed?
if(_serverAdapter)
{
return _serverAdapter->createProxy(stringToIdentity("dummy"));
}
else
{
return 0;
}
}
void
Glacier::RouterI::addProxy(const ObjectPrx& proxy, const Current&)
{
assert(_clientAdapter); // Destroyed?
if(_routingTableTraceLevel)
{
Trace out(_logger, "Glacier");
out << "adding proxy to routing table:\n" << _clientAdapter->getCommunicator()->proxyToString(proxy);
}
_routingTable->add(proxy);
}
void
Glacier::RouterI::shutdown(const Current&)
{
assert(_clientAdapter); // Destroyed?
assert(_routingTable);
_clientAdapter->getCommunicator()->shutdown();
}
SessionPrx
Glacier::RouterI::createSession(const Current&)
{
assert(_clientAdapter); // Destroyed?
IceUtil::Mutex::Lock lock(_sessionMutex);
if(!_sessionManager)
{
throw NoSessionManagerException();
}
SessionPrx session = _sessionManager->create(_userId);
_sessions.push_back(session);
return session;
}
|