blob: 6b669857b62a535ccbceb95879dbee4837b4cacc (
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
// **********************************************************************
//
// Copyright (c) 2003-2005 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.
//
// **********************************************************************
package IceInternal;
public final class ProxyFactory
{
public Ice.ObjectPrx
stringToProxy(String str)
{
Reference ref = _instance.referenceFactory().create(str);
return referenceToProxy(ref);
}
public String
proxyToString(Ice.ObjectPrx proxy)
{
if(proxy != null)
{
Ice.ObjectPrxHelperBase h = (Ice.ObjectPrxHelperBase)proxy;
return h.__reference().toString();
}
else
{
return "";
}
}
public Ice.ObjectPrx
streamToProxy(BasicStream s)
{
Ice.Identity ident = new Ice.Identity();
ident.__read(s);
Reference ref = _instance.referenceFactory().create(ident, s);
return referenceToProxy(ref);
}
public Ice.ObjectPrx
referenceToProxy(Reference ref)
{
if(ref != null)
{
Ice.ObjectPrxHelperBase proxy = new Ice.ObjectPrxHelperBase();
proxy.setup(ref);
return proxy;
}
else
{
return null;
}
}
public void
proxyToStream(Ice.ObjectPrx proxy, BasicStream s)
{
if(proxy != null)
{
Ice.ObjectPrxHelperBase h = (Ice.ObjectPrxHelperBase)proxy;
Reference ref = h.__reference();
ref.getIdentity().__write(s);
ref.streamWrite(s);
}
else
{
Ice.Identity ident = new Ice.Identity();
ident.name = "";
ident.category = "";
ident.__write(s);
}
}
public int
checkRetryAfterException(Ice.LocalException ex, int cnt)
{
//
// We don't retry *NotExistException, which are all derived from
// RequestFailedException.
//
if(ex instanceof Ice.RequestFailedException)
{
throw ex;
}
++cnt;
TraceLevels traceLevels = _instance.traceLevels();
Ice.Logger logger = _instance.logger();
//
// Instance components may be null if Communicator has been destroyed.
//
if(traceLevels != null && logger != null)
{
if(cnt > _retryIntervals.length)
{
if(traceLevels.retry >= 1)
{
String s = "cannot retry operation call because retry limit has been exceeded\n" + ex.toString();
logger.trace(traceLevels.retryCat, s);
}
throw ex;
}
if(traceLevels.retry >= 1)
{
String s = "re-trying operation call";
if(cnt > 0 && _retryIntervals[cnt - 1] > 0)
{
s += " in " + _retryIntervals[cnt - 1] + "ms";
}
s += " because of exception\n" + ex;
logger.trace(traceLevels.retryCat, s);
}
if(cnt > 0)
{
//
// Sleep before retrying.
//
try
{
Thread.currentThread().sleep(_retryIntervals[cnt - 1]);
}
catch(InterruptedException ex1)
{
}
}
return cnt;
}
else
{
//
// Impossible to retry after Communicator has been destroyed.
//
throw ex;
}
}
//
// Only for use by Instance.
//
ProxyFactory(Instance instance)
{
_instance = instance;
String str = _instance.properties().getPropertyWithDefault("Ice.RetryIntervals", "0");
String[] arr = str.trim().split("[ \t\n\r]+");
if(arr.length > 0)
{
_retryIntervals = new int[arr.length];
for(int i = 0; i < arr.length; i++)
{
int v;
try
{
v = Integer.parseInt(arr[i]);
}
catch(NumberFormatException ex)
{
v = 0;
}
//
// If -1 is the first value, no retry and wait intervals.
//
if(i == 0 && v == -1)
{
_retryIntervals = new int[0];
break;
}
_retryIntervals[i] = v > 0 ? v : 0;
}
}
else
{
_retryIntervals = new int[1];
_retryIntervals[0] = 0;
}
}
private Instance _instance;
private int[] _retryIntervals;
}
|