@@ -203,118 +203,36 @@ public String Uri
203
203
///their respective defaults.</summary>
204
204
public ConnectionFactory ( ) { }
205
205
206
- protected virtual IConnection FollowRedirectChain
207
- ( int maxRedirects ,
208
- IDictionary < AmqpTcpEndpoint , int > connectionAttempts ,
209
- IDictionary < AmqpTcpEndpoint , Exception > connectionErrors ,
210
- ref AmqpTcpEndpoint [ ] mostRecentKnownHosts ,
211
- AmqpTcpEndpoint endpoint )
206
+ ///<summary>Create a connection to the specified endpoint
207
+ ///No broker-originated redirects are permitted.</summary>
208
+ public virtual IConnection CreateConnection ( )
212
209
{
213
- AmqpTcpEndpoint candidate = endpoint ;
214
- try {
215
- while ( true ) {
216
- int attemptCount =
217
- connectionAttempts . ContainsKey ( candidate )
218
- ? ( int ) connectionAttempts [ candidate ]
219
- : 0 ;
220
- connectionAttempts [ candidate ] = attemptCount + 1 ;
221
- bool insist = attemptCount >= maxRedirects ;
222
-
223
- IProtocol p = Protocol ;
224
- IFrameHandler fh = p . CreateFrameHandler ( candidate ,
225
- SocketFactory ,
226
- RequestedConnectionTimeout ) ;
227
-
228
- // At this point, we may be able to create
229
- // and fully open a successful connection,
230
- // in which case we're done, and the
231
- // connection should be returned.
232
- return p . CreateConnection ( this , insist , fh ) ;
233
- }
234
- } catch ( Exception e ) {
235
- connectionErrors [ candidate ] = e ;
236
- return null ;
237
- }
238
- }
210
+ IDictionary < AmqpTcpEndpoint , int > attempts = new Dictionary < AmqpTcpEndpoint , int > ( ) ;
211
+ Dictionary < AmqpTcpEndpoint , Exception > errors = new Dictionary < AmqpTcpEndpoint , Exception > ( ) ;
239
212
240
- protected virtual IConnection CreateConnection ( int maxRedirects ,
241
- IDictionary < AmqpTcpEndpoint , int > connectionAttempts ,
242
- IDictionary < AmqpTcpEndpoint , Exception > connectionErrors ,
243
- params AmqpTcpEndpoint [ ] endpoints )
244
- {
245
- foreach ( AmqpTcpEndpoint endpoint in endpoints )
213
+ IConnection conn = null ;
214
+ try
215
+ {
216
+ IProtocol p = Protocols . DefaultProtocol ;
217
+ IFrameHandler fh = p . CreateFrameHandler ( Endpoint ,
218
+ SocketFactory ,
219
+ RequestedConnectionTimeout ) ;
220
+ conn = p . CreateConnection ( this , false , fh ) ;
221
+ attempts [ Endpoint ] = 1 ;
222
+ } catch ( Exception e )
246
223
{
247
- AmqpTcpEndpoint [ ] mostRecentKnownHosts = new AmqpTcpEndpoint [ 0 ] ;
248
- // ^^ holds a list of known-hosts that came back with
249
- // a connection.redirect. If, once we reach the end of
250
- // a chain of redirects, we still haven't managed to
251
- // get a usable connection, we recurse on
252
- // mostRecentKnownHosts, trying each of those in
253
- // turn. Finally, if neither the initial
254
- // chain-of-redirects for the current endpoint, nor
255
- // the chains-of-redirects for each of the
256
- // mostRecentKnownHosts gives us a usable connection,
257
- // we give up on this particular endpoint, and
258
- // continue with the foreach loop, trying the
259
- // remainder of the array we were given.
260
- IConnection conn = FollowRedirectChain ( maxRedirects ,
261
- connectionAttempts ,
262
- connectionErrors ,
263
- ref mostRecentKnownHosts ,
264
- endpoint ) ;
265
- if ( conn != null ) {
266
- return conn ;
267
- }
268
224
269
- // Connection to this endpoint failed at some point
270
- // down the redirection chain - either the first
271
- // entry, or one of the re.Host values from subsequent
272
- // RedirectExceptions. We recurse into
273
- // mostRecentKnownHosts, to see if one of those is
274
- // suitable.
275
- if ( mostRecentKnownHosts . Length > 0 ) {
276
- // Only bother recursing if we know of some
277
- // hosts. If we were to recurse with no endpoints
278
- // in the array, we'd stomp on
279
- // mostRecentException, which makes debugging
280
- // connectivity problems needlessly more
281
- // difficult.
282
- conn = CreateConnection ( maxRedirects ,
283
- connectionAttempts ,
284
- connectionErrors ,
285
- mostRecentKnownHosts ) ;
286
- if ( conn != null ) {
287
- return conn ;
288
- }
289
- }
225
+ errors [ Endpoint ] = e ;
290
226
}
291
- return null ;
292
- }
293
227
294
- ///<summary>Create a connection to the first available
295
- ///endpoint in the list provided. Up to a maximum of
296
- ///maxRedirects broker-originated redirects are permitted for
297
- ///each endpoint tried.</summary>
298
- public virtual IConnection CreateConnection ( int maxRedirects )
299
- {
300
- IDictionary < AmqpTcpEndpoint , int > connectionAttempts = new Dictionary < AmqpTcpEndpoint , int > ( ) ;
301
- Dictionary < AmqpTcpEndpoint , Exception > connectionErrors = new Dictionary < AmqpTcpEndpoint , Exception > ( ) ;
302
- IConnection conn = CreateConnection ( maxRedirects ,
303
- connectionAttempts ,
304
- connectionErrors ,
305
- new AmqpTcpEndpoint [ ] { Endpoint } ) ;
306
- if ( conn != null ) {
228
+ if ( conn != null )
229
+ {
307
230
return conn ;
231
+ } else
232
+ {
233
+ Exception cause = errors [ Endpoint ] as Exception ;
234
+ throw new BrokerUnreachableException ( attempts , errors , cause ) ;
308
235
}
309
- Exception Inner = connectionErrors [ Endpoint ] as Exception ;
310
- throw new BrokerUnreachableException ( connectionAttempts , connectionErrors , Inner ) ;
311
- }
312
-
313
- ///<summary>Create a connection to the specified endpoint
314
- ///No broker-originated redirects are permitted.</summary>
315
- public virtual IConnection CreateConnection ( )
316
- {
317
- return CreateConnection ( 0 ) ;
318
236
}
319
237
320
238
///<summary>Given a list of mechanism names supported by the
0 commit comments