blob: 032d18a1fd463e669bd3185d0e1b9d8ae350abf3 (
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
113
114
115
116
117
118
119
120
121
122
123
124
125
|
// **********************************************************************
//
// Copyright (c) 2002
// ZeroC, Inc.
// Billerica, MA, USA
//
// All Rights Reserved.
//
// Ice is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License version 2 as published by
// the Free Software Foundation.
//
// **********************************************************************
#include <Ice/Ice.h>
#include <IcePack/LocatorI.h>
using namespace std;
using namespace IcePack;
IcePack::LocatorI::LocatorI(const AdapterRegistryPtr& adapterRegistry,
const ObjectRegistryPtr& objectRegistry,
const Ice::LocatorRegistryPrx& locatorRegistry) :
_adapterRegistry(adapterRegistry),
_objectRegistry(objectRegistry),
_locatorRegistry(locatorRegistry)
{
}
//
// Find an object by identity. The object is searched in the object
// registry. If found and if the object was registered with an
// adapter, we get the adapter direct proxy and return a proxy created
// from the adapter direct proxy and the object identity. We could
// just return the registered proxy but this would be less efficient
// since the client would have to make a second call to find out the
// adapter direct proxy.
//
Ice::ObjectPrx
IcePack::LocatorI::findObjectById(const Ice::Identity& id, const Ice::Current& current) const
{
ObjectDescription obj;
try
{
obj = _objectRegistry->getObjectDescription(id);
}
catch(const ObjectNotExistException&)
{
throw Ice::ObjectNotFoundException();
}
if(!obj.adapterId.empty())
{
try
{
Ice::ObjectPrx directProxy = findAdapterById(obj.adapterId, current);
if(directProxy)
{
return directProxy->ice_newIdentity(id);
}
}
catch(Ice::AdapterNotFoundException&)
{
//
// Ignore.
//
}
}
return obj.proxy;
}
Ice::ObjectPrx
IcePack::LocatorI::findAdapterById(const string& id, const Ice::Current&) const
{
//
// TODO: I think will need to do something more sensible in cases
// where the adapter is found but the adapter proxy is null
// (possibly because the server activation failed or timed out) or
// if the adapter object isn't reachable (possibly because the
// IcePack node is down or unreachable). Right now the Ice client
// will always throw a NoEndpointException because we return a
// null proxy here...
//
try
{
return _adapterRegistry->findById(id)->getDirectProxy(true);
}
catch(const AdapterNotExistException&)
{
throw Ice::AdapterNotFoundException();
}
catch(const Ice::ObjectNotExistException&)
{
//
// Expected if the adapter is destroyed.
//
throw Ice::AdapterNotFoundException();
}
catch(const Ice::NoEndpointException&)
{
//
// This could be because we can't locate the IcePack node
// adapter (IcePack server adapter proxies are not direct
// proxies)
//
}
catch(const Ice::LocalException&)
{
//
// Expected if we couldn't contact the adapter object
// (possibly because the IcePack node is down).
//
}
return 0;
}
Ice::LocatorRegistryPrx
IcePack::LocatorI::getRegistry(const Ice::Current&) const
{
return _locatorRegistry;
}
|