1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.allanbank.mongodb.client;
21
22 import java.io.Closeable;
23
24 import com.allanbank.mongodb.Durability;
25 import com.allanbank.mongodb.MongoClientConfiguration;
26 import com.allanbank.mongodb.MongoCursorControl;
27 import com.allanbank.mongodb.MongoDbException;
28 import com.allanbank.mongodb.MongoIterator;
29 import com.allanbank.mongodb.ReadPreference;
30 import com.allanbank.mongodb.StreamCallback;
31 import com.allanbank.mongodb.bson.Document;
32 import com.allanbank.mongodb.bson.DocumentAssignable;
33 import com.allanbank.mongodb.client.connection.Connection;
34
35
36
37
38
39
40
41
42
43 public class SerialClientImpl extends AbstractClient {
44
45
46 protected static final boolean ASSERTIONS_ENABLED;
47 static {
48 ASSERTIONS_ENABLED = SerialClientImpl.class.desiredAssertionStatus();
49 }
50
51
52 private Connection myConnection;
53
54
55 private final ClientImpl myDelegate;
56
57
58
59
60
61
62
63 public SerialClientImpl(final ClientImpl client) {
64 myDelegate = client;
65 }
66
67
68
69
70
71
72
73
74
75 @Override
76 public void close() {
77 super.close();
78
79
80 myConnection = null;
81 }
82
83
84
85
86
87
88
89 @Override
90 public ClusterStats getClusterStats() {
91 return myDelegate.getClusterStats();
92 }
93
94
95
96
97
98
99
100
101 @Override
102 public ClusterType getClusterType() {
103 return myDelegate.getClusterType();
104 }
105
106
107
108
109
110
111
112
113 @Override
114 public MongoClientConfiguration getConfig() {
115 return myDelegate.getConfig();
116 }
117
118
119
120
121
122
123
124
125
126 @Override
127 public Durability getDefaultDurability() {
128 return myDelegate.getDefaultDurability();
129 }
130
131
132
133
134
135
136
137
138
139 @Override
140 public ReadPreference getDefaultReadPreference() {
141 return myDelegate.getDefaultReadPreference();
142 }
143
144
145
146
147
148
149
150
151
152 @Override
153 public MongoIterator<Document> restart(
154 final DocumentAssignable cursorDocument)
155 throws IllegalArgumentException {
156 return myDelegate.restart(cursorDocument);
157 }
158
159
160
161
162
163
164
165
166
167 @Override
168 public MongoCursorControl restart(final StreamCallback<Document> results,
169 final DocumentAssignable cursorDocument)
170 throws IllegalArgumentException {
171 return myDelegate.restart(results, cursorDocument);
172 }
173
174
175
176
177
178
179
180
181
182
183 @Override
184 protected Connection findConnection(final Message message1,
185 final Message message2) throws MongoDbException {
186 if ((myConnection == null) || !myConnection.isAvailable()) {
187 myConnection = myDelegate.findConnection(message1, message2);
188 }
189
190 return myConnection;
191 }
192 }