1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package com.allanbank.mongodb.client.connection.auth;
22
23 import java.io.IOException;
24
25 import com.allanbank.mongodb.MongoClientConfiguration;
26 import com.allanbank.mongodb.client.ClusterStats;
27 import com.allanbank.mongodb.client.ClusterType;
28 import com.allanbank.mongodb.client.connection.ConnectionFactory;
29 import com.allanbank.mongodb.client.connection.ReconnectStrategy;
30 import com.allanbank.mongodb.client.connection.proxy.ProxiedConnectionFactory;
31 import com.allanbank.mongodb.client.state.Server;
32 import com.allanbank.mongodb.util.IOUtils;
33
34
35
36
37
38
39
40
41
42 public class AuthenticationConnectionFactory implements
43 ProxiedConnectionFactory {
44
45
46 private final MongoClientConfiguration myConfig;
47
48
49 private final ProxiedConnectionFactory myProxiedConnectionFactory;
50
51
52
53
54
55
56
57
58
59
60 public AuthenticationConnectionFactory(
61 final ProxiedConnectionFactory factory,
62 final MongoClientConfiguration config) {
63 myProxiedConnectionFactory = factory;
64 myConfig = config;
65 }
66
67
68
69
70
71
72
73 @Override
74 public void close() {
75 IOUtils.close(myProxiedConnectionFactory);
76 }
77
78
79
80
81
82
83
84
85 @Override
86 public AuthenticatingConnection connect() throws IOException {
87 return new AuthenticatingConnection(
88 myProxiedConnectionFactory.connect(), myConfig);
89 }
90
91
92
93
94
95
96
97
98 @Override
99 public AuthenticatingConnection connect(final Server server,
100 final MongoClientConfiguration config) throws IOException {
101 return new AuthenticatingConnection(myProxiedConnectionFactory.connect(
102 server, config), config);
103 }
104
105
106
107
108
109
110
111
112 @Override
113 public ClusterStats getClusterStats() {
114 return myProxiedConnectionFactory.getClusterStats();
115 }
116
117
118
119
120
121
122
123
124 @Override
125 public ClusterType getClusterType() {
126 return myProxiedConnectionFactory.getClusterType();
127 }
128
129
130
131
132
133
134
135
136 @Override
137 public ReconnectStrategy getReconnectStrategy() {
138 final ReconnectStrategy delegates = myProxiedConnectionFactory
139 .getReconnectStrategy();
140
141 delegates.setConnectionFactory(this);
142
143 return delegates;
144 }
145 }