blob: a9c8f81e1574321fabc9494e49e45960113ff182 (
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
// **********************************************************************
//
// Copyright (c) 2001
// Mutable Realms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************
package IceInternal;
public final class LocatorInfo
{
LocatorInfo(Ice.LocatorPrx locator, LocatorAdapterTable adapterTable)
{
_locator = locator;
_adapterTable = adapterTable;
}
synchronized public void
destroy()
{
_locator = null;
_locatorRegistry = null;
_adapterTable.clear();
}
public boolean
equals(java.lang.Object obj)
{
LocatorInfo rhs = null;
try
{
rhs = (LocatorInfo)obj;
}
catch (ClassCastException ex)
{
return false;
}
return _locator.equals(rhs._locator);
}
public Ice.LocatorPrx
getLocator()
{
//
// No synchronization necessary, _locator is immutable.
//
return _locator;
}
public synchronized Ice.LocatorRegistryPrx
getLocatorRegistry()
{
if(_locatorRegistry == null) // Lazy initialization
{
_locatorRegistry = _locator.getRegistry();
}
return _locatorRegistry;
}
public IceInternal.Endpoint[]
getEndpoints(Reference ref, Ice.BooleanHolder cached)
{
IceInternal.Endpoint[] endpoints = null;
if(ref.adapterId.length() > 0)
{
cached.value = true;
endpoints = _adapterTable.get(ref.adapterId);
if(endpoints == null)
{
cached.value = false;
//
// Search the adapter in the location service if we didn't
// find it in the cache.
//
try
{
Ice.ObjectPrx object = _locator.findAdapterByName(ref.adapterId);
if(object != null)
{
endpoints = ((Ice.ObjectPrxHelper)object).__reference().endpoints;
}
}
catch(Ice.LocalException ex)
{
//
// Just trace the failure. The proxy will most
// likely get empty endpoints and raise a
// NoEndpointException().
//
if(ref.instance.traceLevels().location >= 1)
{
StringBuffer s = new StringBuffer();
s.append("couldn't contact the locator to retrieve adapter endpoints\n");
s.append("adapter = " + ref.adapterId + "\n");
s.append("reason = " + ex);
ref.instance.logger().trace(ref.instance.traceLevels().locationCat, s.toString());
}
}
if(endpoints != null && endpoints.length > 0)
{
_adapterTable.add(ref.adapterId, endpoints);
}
}
if(endpoints != null && endpoints.length > 0)
{
if(ref.instance.traceLevels().location >= 1)
{
StringBuffer s = new StringBuffer();
if(cached.value)
s.append("found endpoints in locator table\n");
else
s.append("retrieved endpoints from locator, adding to locator table\n");
s.append("adapter = " + ref.adapterId + "\n");
s.append("endpoints = ");
final int sz = endpoints.length;
for(int i = 0; i < sz; i++)
{
s.append(endpoints[i].toString());
if(i + 1 < sz)
s.append(":");
}
ref.instance.logger().trace(ref.instance.traceLevels().locationCat, s.toString());
}
}
}
return endpoints == null ? new IceInternal.Endpoint[0] : endpoints;
}
public void
clearCache(Reference ref)
{
if(ref.adapterId.length() > 0)
{
IceInternal.Endpoint[] endpoints = _adapterTable.remove(ref.adapterId);
if(ref.instance.traceLevels().location >= 2)
{
StringBuffer s = new StringBuffer();
s.append("removed endpoints from locator table\n");
s.append("adapter = " + ref.adapterId + "\n");
s.append("endpoints = ");
final int sz = endpoints.length;
for(int i = 0; i < sz; i++)
{
s.append(endpoints[i].toString());
if(i + 1 < sz)
s.append(":");
}
ref.instance.logger().trace(ref.instance.traceLevels().locationCat, s.toString());
}
}
}
private Ice.LocatorPrx _locator; // Immutable.
private Ice.LocatorRegistryPrx _locatorRegistry;
private LocatorAdapterTable _adapterTable; // Immutable.
};
|