Skip to content

Commit dd0fb95

Browse files
committed
Merge pull request #4 from shipunyc/master
Import changes from TFS.
2 parents fccb88f + ae3dabd commit dd0fb95

File tree

4 files changed

+137
-113
lines changed

4 files changed

+137
-113
lines changed

src/com/microsoft/azure/documentdb/ConnectionPolicy.java

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@
1010
public final class ConnectionPolicy {
1111

1212
private static final int DEFAULT_MAX_CONNECTIONS = 20;
13-
private static final int DEFAULT_MAX_CONCURRENT_CALLS_PER_CONNECTION = 50;
1413
private static final int DEFAULT_REQUEST_TIMEOUT = 60;
1514
// defaultMediaRequestTimeout is based upon the blob client timeout and the retry policy.
1615
private static final int DEFAULT_MEDIA_REQUEST_TIMEOUT = 300;
17-
private static final int DEFAULT_MAX_CONCURRENT_FANOUT_REQUESTS = 32;
1816
private static final int DEFAULT_MAX_POOL_SIZE = 100;
1917
private static final int DEFAULT_IDLE_CONNECTION_TIMEOUT = 60;
2018

@@ -28,8 +26,6 @@ public ConnectionPolicy() {
2826
this.requestTimeout = ConnectionPolicy.DEFAULT_REQUEST_TIMEOUT;
2927
this.mediaRequestTimeout = ConnectionPolicy.DEFAULT_MEDIA_REQUEST_TIMEOUT;
3028
this.connectionMode = ConnectionMode.Gateway;
31-
this.maxCallsPerConnection = ConnectionPolicy.DEFAULT_MAX_CONCURRENT_CALLS_PER_CONNECTION;
32-
this.maxConcurrentFanoutRequests = DEFAULT_MAX_CONCURRENT_FANOUT_REQUESTS;
3329
this.mediaReadMode = MediaReadMode.Buffered;
3430
this.maxPoolSize = DEFAULT_MAX_POOL_SIZE;
3531
this.idleConnectionTimeout = DEFAULT_IDLE_CONNECTION_TIMEOUT;
@@ -57,48 +53,6 @@ public void setMaxConnections(int maxConnections) {
5753
this.maxConnections = maxConnections;
5854
}
5955

60-
private int maxCallsPerConnection;
61-
62-
/**
63-
* Gets the number of maximum simultaneous calls permitted on a single data connection. Currently used only for
64-
* Protocol.Tcp.
65-
*
66-
* @return the max calls per connection.
67-
*/
68-
public int getMaxCallsPerConnection() {
69-
return this.maxCallsPerConnection;
70-
}
71-
72-
/**
73-
* Sets the number of maximum simultaneous calls permitted on a single data connection. Currently used only for
74-
* Protocol.Tcp.
75-
*
76-
* @param maxCallsPerConnection the max calls per connection.
77-
*/
78-
public void setMaxCallsPerConnection(int maxCallsPerConnection) {
79-
this.maxCallsPerConnection = maxCallsPerConnection;
80-
}
81-
82-
private int maxConcurrentFanoutRequests;
83-
84-
/**
85-
* Gets the maximum number of concurrent fanout requests.
86-
*
87-
* @return the maximum number of concurrent fanout requests.
88-
*/
89-
public int getMaxConcurrentFanoutRequest() {
90-
return this.maxConcurrentFanoutRequests;
91-
}
92-
93-
/**
94-
* Sets the maximum number of concurrent fanout requests.
95-
*
96-
* @param maxConcurrentFanoutRequests the max concurrent fanout requests.
97-
*/
98-
public void setMaxConcurrentFanoutRequest(int maxConcurrentFanoutRequests) {
99-
this.maxConcurrentFanoutRequests = maxConcurrentFanoutRequests;
100-
}
101-
10256
private int requestTimeout;
10357

10458
/**
@@ -179,26 +133,6 @@ public void setMediaReadMode(MediaReadMode mediaReadMode) {
179133
this.mediaReadMode = mediaReadMode;
180134
}
181135

182-
private String connectBindingConfigName;
183-
184-
/**
185-
* Gets the connection bindign config name. Ignored if ConnectionMode is Gateway or ConnectionProtocol is not TCP.
186-
*
187-
* @return the connect binding config name.
188-
*/
189-
public String getConnectBindingConfigName() {
190-
return this.connectBindingConfigName;
191-
}
192-
193-
/**
194-
* Sets the connection binding config name. Ignored if ConnectionMode is Gateway or ConnectionProtocol is not TCP.
195-
*
196-
* @param connectBindingConfigName the connect binding config name.
197-
*/
198-
public void setConnectBindingConfigName(String connectBindingConfigName) {
199-
this.connectBindingConfigName = connectBindingConfigName;
200-
}
201-
202136
private int maxPoolSize;
203137

204138
/**

src/com/microsoft/azure/documentdb/FeedResponse.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
public final class FeedResponse<T extends Resource> {
1616

1717
private QueryIterable<T> inner;
18-
private Map<String, String> responseHeaders;
1918
private Map<String, Long> usageHeaders;
2019
private Map<String, Long> quotaHeaders;
2120

@@ -167,7 +166,6 @@ public long getUserDefinedFunctionsUsage() {
167166

168167
FeedResponse(QueryIterable<T> result) {
169168
this.inner = result;
170-
this.responseHeaders = result.getResponseHeaders();
171169
this.usageHeaders = new HashMap<String, Long>();
172170
this.quotaHeaders = new HashMap<String, Long>();
173171
}
@@ -179,7 +177,8 @@ public long getUserDefinedFunctionsUsage() {
179177
* @return the max resource quota.
180178
*/
181179
public String getMaxResourceQuota() {
182-
return FeedResponse.getValueOrNull(this.inner.getResponseHeaders(), HttpConstants.HttpHeaders.MAX_RESOURCE_QUOTA);
180+
return FeedResponse.getValueOrNull(this.inner.getResponseHeaders(),
181+
HttpConstants.HttpHeaders.MAX_RESOURCE_QUOTA);
183182
}
184183

185184
/**
@@ -188,7 +187,8 @@ public String getMaxResourceQuota() {
188187
* @return the current resource quota usage.
189188
*/
190189
public String getCurrentResourceQuotaUsage() {
191-
return FeedResponse.getValueOrNull(this.inner.getResponseHeaders(), HttpConstants.HttpHeaders.CURRENT_RESOURCE_QUOTA_USAGE);
190+
return FeedResponse.getValueOrNull(this.inner.getResponseHeaders(),
191+
HttpConstants.HttpHeaders.CURRENT_RESOURCE_QUOTA_USAGE);
192192
}
193193

194194
/**
@@ -197,7 +197,8 @@ public String getCurrentResourceQuotaUsage() {
197197
* @return the request charge.
198198
*/
199199
public double getRequestCharge() {
200-
String value = this.responseHeaders.get(HttpConstants.HttpHeaders.REQUEST_CHARGE);
200+
String value = FeedResponse.getValueOrNull(this.inner.getResponseHeaders(),
201+
HttpConstants.HttpHeaders.REQUEST_CHARGE);
201202
if (StringUtils.isEmpty(value)) {
202203
return 0;
203204
}
@@ -237,7 +238,7 @@ public String getSessionToken() {
237238
* @return the response headers.
238239
*/
239240
public Map<String, String> getResponseHeaders() {
240-
return this.responseHeaders;
241+
return this.inner.getResponseHeaders();
241242
}
242243

243244
/**
@@ -323,7 +324,7 @@ private void populateQuotaHeader(String headerMaxQuota,
323324

324325
private static String getValueOrNull(Map<String, String> map, String key) {
325326
if (map != null) {
326-
return map.get(key);
327+
return map.get(key);
327328
}
328329
return null;
329330
}

src/com/microsoft/azure/documentdb/QueryIterable.java

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ public class QueryIterable<T extends Resource> implements Iterable<T> {
2525
private boolean hasStarted = false;
2626
private List<T> items = new ArrayList<T>();
2727
private Map<String, String> responseHeaders;
28+
private int currentIndex = 0;
29+
private boolean hasNext = true;
2830

2931
QueryIterable(DocumentClient client,
30-
DocumentServiceRequest request,
31-
ReadType readType,
32-
Class<T> classT) {
32+
DocumentServiceRequest request,
33+
ReadType readType,
34+
Class<T> classT) {
3335
this.client = client;
3436
this.retryPolicy = new ResourceThrottleRetryPolicy(
3537
client.getRetryPolicy().getMaxRetryAttemptsOnQuery());
@@ -39,15 +41,6 @@ public class QueryIterable<T extends Resource> implements Iterable<T> {
3941
this.reset();
4042
}
4143

42-
private void reset() {
43-
if (this.request != null && this.request.getHeaders() != null) {
44-
String continuationToken = this.request.getHeaders().get(HttpConstants.HttpHeaders.CONTINUATION);
45-
if (!StringUtils.isBlank(continuationToken)) {
46-
this.continuation = continuationToken;
47-
}
48-
}
49-
}
50-
5144
/**
5245
* Gets the response headers.
5346
*
@@ -75,14 +68,12 @@ String getContinuation() {
7568
public Iterator<T> iterator() {
7669
Iterator<T> it = new Iterator<T>() {
7770

78-
private int currentIndex = 0;
79-
private boolean hasNext = true;
80-
8171
private BackoffRetryUtilityDelegate delegate = new BackoffRetryUtilityDelegate() {
8272

8373
@Override
8474
public void apply() throws Exception {
85-
if (fetchNextBlock() <= 0) {
75+
List<T> results = fetchNextBlock();
76+
if (results == null || results.size() <= 0) {
8677
hasNext = false;
8778
}
8879
}
@@ -95,11 +86,11 @@ public void apply() throws Exception {
9586
*/
9687
@Override
9788
public boolean hasNext() {
98-
if (this.currentIndex >= items.size() && this.hasNext) {
89+
if (currentIndex >= items.size() && hasNext) {
9990
BackoffRetryUtility.execute(this.delegate, retryPolicy);
10091
}
10192

102-
return this.hasNext;
93+
return hasNext;
10394
}
10495

10596
/**
@@ -109,12 +100,12 @@ public boolean hasNext() {
109100
*/
110101
@Override
111102
public T next() {
112-
if (this.currentIndex >= items.size() && this.hasNext) {
103+
if (currentIndex >= items.size() && hasNext) {
113104
BackoffRetryUtility.execute(this.delegate, retryPolicy);
114105
}
115106

116-
if (!this.hasNext) return null;
117-
return items.get(this.currentIndex++);
107+
if (!hasNext) return null;
108+
return items.get(currentIndex++);
118109
}
119110

120111
/**
@@ -123,8 +114,8 @@ public T next() {
123114
@Override
124115
public void remove() {
125116
if (!hasNext()) throw new NoSuchElementException();
126-
if (this.currentIndex < items.size() - 1) {
127-
items.remove(this.currentIndex);
117+
if (currentIndex < items.size()) {
118+
items.remove(currentIndex);
128119
}
129120
}
130121

@@ -145,16 +136,39 @@ public List<T> toList() {
145136
return list;
146137
}
147138

148-
private int fetchNextBlock()
139+
/**
140+
* Resets the iterable.
141+
*/
142+
public void reset() {
143+
this.hasStarted = false;
144+
this.continuation = null;
145+
this.items = new ArrayList<T>();
146+
this.currentIndex = 0;
147+
this.hasNext = true;
148+
if (this.request != null && this.request.getHeaders() != null) {
149+
String continuationToken = this.request.getHeaders().get(HttpConstants.HttpHeaders.CONTINUATION);
150+
if (!StringUtils.isBlank(continuationToken)) {
151+
this.continuation = continuationToken;
152+
}
153+
}
154+
}
155+
156+
/**
157+
* Fetch the next block of query results.
158+
*
159+
* @return the list of fetched resources.
160+
* @throws DocumentClientException
161+
*/
162+
public List<T> fetchNextBlock()
149163
throws DocumentClientException {
150164
DocumentServiceResponse response = null;
151165
List<T> fetchedItems = null;
152166

153-
while (!this.isNullEmptyOrFalse(this.continuation) ||
154-
!this.hasStarted) {
167+
while (!this.isNullEmptyOrFalse(this.continuation) || !this.hasStarted) {
155168
if (!this.isNullEmptyOrFalse(this.continuation)) {
156-
request.getHeaders().put(HttpConstants.HttpHeaders.CONTINUATION,
157-
this.continuation);
169+
request.getHeaders().put(HttpConstants.HttpHeaders.CONTINUATION, this.continuation);
170+
} else {
171+
request.getHeaders().remove(HttpConstants.HttpHeaders.CONTINUATION);
158172
}
159173

160174
if (this.readType == ReadType.Feed) {
@@ -181,11 +195,10 @@ private int fetchNextBlock()
181195
}
182196
}
183197

184-
return fetchedItems != null ? fetchedItems.size() : 0;
198+
return fetchedItems;
185199
}
186200

187201
private boolean isNullEmptyOrFalse(String s) {
188202
return s == null || s.isEmpty() || s == "false" || s == "False";
189203
}
190-
191204
}

0 commit comments

Comments
 (0)