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
|
// **********************************************************************
//
// Copyright (c) 2003-2017 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 <Glacier2/SessionRouterI.h>
#include <Glacier2/Instance.h>
#include <Glacier2/InstrumentationI.h>
#include <Ice/InstrumentationI.h>
using namespace std;
using namespace Glacier2;
namespace
{
const string serverSleepTime = "Glacier2.Server.SleepTime";
const string clientSleepTime = "Glacier2.Client.SleepTime";
const string serverBuffered = "Glacier2.Server.Buffered";
const string clientBuffered = "Glacier2.Client.Buffered";
}
Glacier2::Instance::Instance(const Ice::CommunicatorPtr& communicator, const Ice::ObjectAdapterPtr& clientAdapter,
const Ice::ObjectAdapterPtr& serverAdapter) :
_communicator(communicator),
_properties(communicator->getProperties()),
_logger(communicator->getLogger()),
_clientAdapter(clientAdapter),
_serverAdapter(serverAdapter)
{
if(_properties->getPropertyAsIntWithDefault(serverBuffered, 1) > 0)
{
IceUtil::Time sleepTime = IceUtil::Time::milliSeconds(_properties->getPropertyAsInt(serverSleepTime));
const_cast<RequestQueueThreadPtr&>(_serverRequestQueueThread) = new RequestQueueThread(sleepTime);
try
{
_serverRequestQueueThread->start();
}
catch(const IceUtil::Exception&)
{
_serverRequestQueueThread->destroy();
throw;
}
}
if(_properties->getPropertyAsIntWithDefault(clientBuffered, 1) > 0)
{
IceUtil::Time sleepTime = IceUtil::Time::milliSeconds(_properties->getPropertyAsInt(clientSleepTime));
const_cast<RequestQueueThreadPtr&>(_clientRequestQueueThread) = new RequestQueueThread(sleepTime);
try
{
_clientRequestQueueThread->start();
}
catch(const IceUtil::Exception&)
{
_clientRequestQueueThread->destroy();
throw;
}
}
const_cast<ProxyVerifierPtr&>(_proxyVerifier) = new ProxyVerifier(communicator);
//
// If an Ice metrics observer is setup on the communicator, also
// enable metrics for IceStorm.
//
IceInternal::CommunicatorObserverIPtr o =
IceInternal::CommunicatorObserverIPtr::dynamicCast(communicator->getObserver());
if(o)
{
const_cast<Glacier2::Instrumentation::RouterObserverPtr&>(_observer) =
new RouterObserverI(o->getFacet(),
_properties->getPropertyWithDefault("Glacier2.InstanceName", "Glacier2"));
}
}
Glacier2::Instance::~Instance()
{
}
void
Glacier2::Instance::destroy()
{
if(_clientRequestQueueThread)
{
_clientRequestQueueThread->destroy();
}
if(_serverRequestQueueThread)
{
_serverRequestQueueThread->destroy();
}
const_cast<SessionRouterIPtr&>(_sessionRouter) = 0;
}
void
Glacier2::Instance::setSessionRouter(const SessionRouterIPtr& sessionRouter)
{
const_cast<SessionRouterIPtr&>(_sessionRouter) = sessionRouter;
}
|