|
7 | 7 |
|
8 | 8 | import java.io.IOException;
|
9 | 9 | import java.util.ArrayList;
|
10 |
| -import java.util.Arrays; |
11 | 10 | import java.util.Collections;
|
12 | 11 | import java.util.List;
|
13 | 12 | import java.util.concurrent.TimeoutException;
|
14 | 13 |
|
15 | 14 | public class RecoveryAwareAMQConnectionFactory {
|
16 |
| - private final ConnectionParams params; |
17 |
| - private final FrameHandlerFactory factory; |
18 |
| - private final List<Address> addrs; |
19 |
| - |
20 |
| - public RecoveryAwareAMQConnectionFactory(ConnectionParams params, FrameHandlerFactory factory, Address[] addrs) { |
21 |
| - this.params = params; |
22 |
| - this.factory = factory; |
23 |
| - this.addrs = Arrays.asList(addrs); |
24 |
| - } |
25 |
| - |
26 |
| - public RecoveryAwareAMQConnectionFactory(ConnectionParams params, FrameHandlerFactory factory, List<Address> addrs){ |
27 |
| - this.params = params; |
28 |
| - this.factory = factory; |
29 |
| - this.addrs = addrs; |
30 |
| - } |
31 |
| - /** |
32 |
| - * @return an interface to the connection |
33 |
| - * @throws java.io.IOException if it encounters a problem |
34 |
| - */ |
35 |
| - RecoveryAwareAMQConnection newConnection() throws IOException, TimeoutException { |
36 |
| - IOException lastException = null; |
37 |
| - List<Address> shuffled = shuffle(addrs); |
38 |
| - |
39 |
| - for (Address addr : shuffled) { |
40 |
| - try { |
41 |
| - FrameHandler frameHandler = factory.create(addr); |
42 |
| - RecoveryAwareAMQConnection conn = new RecoveryAwareAMQConnection(params, frameHandler); |
43 |
| - conn.start(); |
44 |
| - return conn; |
45 |
| - } catch (IOException e) { |
46 |
| - lastException = e; |
47 |
| - } |
| 15 | + private final ConnectionParams params; |
| 16 | + private final FrameHandlerFactory factory; |
| 17 | + private final List<Address> addrs; |
| 18 | + |
| 19 | + public RecoveryAwareAMQConnectionFactory(ConnectionParams params, FrameHandlerFactory factory, List<Address> addrs) { |
| 20 | + this.params = params; |
| 21 | + this.factory = factory; |
| 22 | + this.addrs = addrs; |
48 | 23 | }
|
49 | 24 |
|
50 |
| - throw (lastException != null) ? lastException : new IOException("failed to connect"); |
51 |
| - } |
| 25 | + /** |
| 26 | + * @return an interface to the connection |
| 27 | + * @throws java.io.IOException if it encounters a problem |
| 28 | + */ |
| 29 | + RecoveryAwareAMQConnection newConnection() throws IOException, TimeoutException { |
| 30 | + IOException lastException = null; |
| 31 | + List<Address> shuffled = shuffle(addrs); |
| 32 | + |
| 33 | + for (Address addr : shuffled) { |
| 34 | + try { |
| 35 | + FrameHandler frameHandler = factory.create(addr); |
| 36 | + RecoveryAwareAMQConnection conn = new RecoveryAwareAMQConnection(params, frameHandler); |
| 37 | + conn.start(); |
| 38 | + return conn; |
| 39 | + } catch (IOException e) { |
| 40 | + lastException = e; |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + throw (lastException != null) ? lastException : new IOException("failed to connect"); |
| 45 | + } |
52 | 46 |
|
53 |
| - private List<Address> shuffle(List<Address> addrs) { |
54 |
| - List<Address> list = new ArrayList<Address>(addrs); |
55 |
| - Collections.shuffle(list); |
56 |
| - return list; |
57 |
| - } |
| 47 | + private List<Address> shuffle(List<Address> addrs) { |
| 48 | + List<Address> list = new ArrayList<Address>(addrs); |
| 49 | + Collections.shuffle(list); |
| 50 | + return list; |
| 51 | + } |
58 | 52 | }
|
0 commit comments