blob: 99284620a0378ccbd5122ba5d08e6f99ca45cf21 (
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
// **********************************************************************
//
// Copyright (c) 2003 - 2004
// ZeroC, Inc.
// North Palm Beach, FL, USA
//
// 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/Ice.h>
#include <IceUtil/UUID.h>
#include <Freeze/Evictor.h>
#include <Freeze/Initialize.h>
#include <IcePack/AdapterFactory.h>
#include <IcePack/AdapterI.h>
#include <IcePack/TraceLevels.h>
using namespace std;
using namespace IcePack;
IcePack::AdapterFactory::AdapterFactory(const Ice::ObjectAdapterPtr& adapter,
const TraceLevelsPtr& traceLevels,
const string& envName) :
_adapter(adapter),
_traceLevels(traceLevels)
{
//
// Create and install the freeze evictor for standalone adapter objects.
//
_evictor = Freeze::createEvictor(_adapter, envName, "adapter");
_evictor->setSize(1000);
//
// Install the server object factory.
//
_adapter->getCommunicator()->addObjectFactory(this, "::IcePack::StandaloneAdapter");
//
// Install the evictors.
//
_adapter->addServantLocator(_evictor, "IcePackStandaloneAdapter");
}
//
// Ice::ObjectFactory::create method implementation
//
Ice::ObjectPtr
IcePack::AdapterFactory::create(const string& type)
{
if(type == "::IcePack::StandaloneAdapter")
{
return new StandaloneAdapterI(this);
}
else
{
assert(false);
return 0; // Keep the compiler happy.
}
}
//
// Ice::ObjectFactory::destroy method implementation
//
void
IcePack::AdapterFactory::destroy()
{
_adapter = 0;
_evictor = 0;
_traceLevels = 0;
}
//
// Create a new adapter servant with the given name and add
// it the evictor database.
//
AdapterPrx
IcePack::AdapterFactory::createStandaloneAdapter(const string& name)
{
StandaloneAdapterPtr adapterI = new StandaloneAdapterI(this);
Ice::Identity id;
id.category = "IcePackStandaloneAdapter";
id.name = name + "-" + IceUtil::generateUUID();
_evictor->add(adapterI, id);
return AdapterPrx::uncheckedCast(_adapter->createProxy(id));
}
void
IcePack::AdapterFactory::destroy(const Ice::Identity& id)
{
try
{
_evictor->remove(id);
}
catch(const Freeze::DatabaseException& ex)
{
ostringstream os;
os << "couldn't destroy standalone adapter:\n" << ex;
_traceLevels->logger->warning(os.str());
}
catch(const Freeze::EvictorDeactivatedException&)
{
assert(false);
}
}
|