Browse files

Allow user to pass "PaginationOptions" object with "limit" and "marker"

attribute to every "list" method.
  • Loading branch information...
1 parent c9c7829 commit 53b851afa1c66ded43f041c111b8baddd0da628b @Kami Kami committed Feb 24, 2013
View
19 src/main/java/com/rackspacecloud/client/service_registry/PaginationOptions.java
@@ -0,0 +1,19 @@
+package com.rackspacecloud.client.service_registry;
+
+public class PaginationOptions {
+ private Integer limit;
+ private String marker;
+
+ public PaginationOptions(Integer limit, String marker) {
+ this.limit = limit;
+ this.marker = marker;
+ }
+
+ public Integer getLimit() {
+ return limit;
+ }
+
+ public String getMarker() {
+ return marker;
+ }
+}
View
20 src/main/java/com/rackspacecloud/client/service_registry/clients/BaseClient.java
@@ -31,6 +31,7 @@
import com.google.gson.GsonBuilder;
import com.rackspacecloud.client.service_registry.Client;
import com.rackspacecloud.client.service_registry.ClientResponse;
+import com.rackspacecloud.client.service_registry.PaginationOptions;
import com.rackspacecloud.client.service_registry.events.client.ClientEvent;
import com.rackspacecloud.client.service_registry.events.client.ClientEventListener;
import com.rackspacecloud.client.service_registry.events.client.ClientEventThread;
@@ -48,6 +49,7 @@
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.slf4j.Logger;
@@ -117,6 +119,24 @@ public void run() {
}
}
}
+
+ protected ClientResponse performListRequest(PaginationOptions paginationOptions, String path, List<NameValuePair> params, HttpRequestBase method, boolean parseAsJson, Type responseType) throws Exception {
+ if (params == null) {
+ params = new ArrayList<NameValuePair>();
+ }
+
+ if (paginationOptions != null) {
+ if (paginationOptions.getLimit() != null) {
+ params.add(new BasicNameValuePair("limit", paginationOptions.getLimit().toString()));
+ }
+
+ if (paginationOptions.getMarker() != null) {
+ params.add(new BasicNameValuePair("marker", paginationOptions.getMarker()));
+ }
+ }
+
+ return performRequest(path, params, method, parseAsJson, responseType, false, 0);
+ }
protected ClientResponse performRequest(String path, List<NameValuePair> params, HttpRequestBase method) throws Exception {
return performRequest(path, params, method, false, null, false, 0);
View
10 src/main/java/com/rackspacecloud/client/service_registry/clients/ConfigurationClient.java
@@ -19,6 +19,7 @@
import com.google.gson.reflect.TypeToken;
import com.rackspacecloud.client.service_registry.ClientResponse;
+import com.rackspacecloud.client.service_registry.PaginationOptions;
import com.rackspacecloud.client.service_registry.containers.ConfigurationValuesContainer;
import com.rackspacecloud.client.service_registry.objects.ConfigurationValue;
import org.apache.http.NameValuePair;
@@ -35,15 +36,14 @@ public ConfigurationClient(AuthClient authClient) {
super(authClient);
}
- public List<ConfigurationValue> list(Map<String, String> options) throws Exception {
- return list(options, null);
+ public List<ConfigurationValue> list(PaginationOptions paginationOptions) throws Exception {
+ return list(paginationOptions, null);
}
- public List<ConfigurationValue> list(Map<String, String> options, String namespace) throws Exception {
+ public List<ConfigurationValue> list(PaginationOptions paginationOptions, String namespace) throws Exception {
String url = "/configuration";
Type type = new TypeToken<ConfigurationValuesContainer>() {}.getType();
- List<NameValuePair> params = new ArrayList<NameValuePair>();
if (namespace != null) {
// Make sure leading and trailing forward slashes are present
@@ -59,7 +59,7 @@ public ConfigurationClient(AuthClient authClient) {
}
}
- ClientResponse response = this.performRequest(url, params, new HttpGet(), true, type);
+ ClientResponse response = this.performListRequest(paginationOptions, url, null, new HttpGet(), true, type);
ConfigurationValuesContainer container = (ConfigurationValuesContainer)response.getBody();
return container.getValues();
View
5 src/main/java/com/rackspacecloud/client/service_registry/clients/EventsClient.java
@@ -18,6 +18,7 @@
package com.rackspacecloud.client.service_registry.clients;
import com.google.gson.reflect.TypeToken;
+import com.rackspacecloud.client.service_registry.PaginationOptions;
import com.rackspacecloud.client.service_registry.events.server.*;
import com.rackspacecloud.client.service_registry.objects.*;
import org.apache.http.client.methods.HttpGet;
@@ -41,10 +42,10 @@ public EventsClient(AuthClient authClient) {
super(authClient);
}
- public List<BaseEvent> list(Map<String, String> options) throws Exception {
+ public List<BaseEvent> list(PaginationOptions paginationOptions) throws Exception {
String url = "/events";
Type type = new TypeToken<EventsContainer>() {}.getType();
- ClientResponse response = this.performRequest(url, null, new HttpGet(), true, type);
+ ClientResponse response = this.performListRequest(paginationOptions, url, null, new HttpGet(), true, type);
EventsContainer container = (EventsContainer)response.getBody();
List<BaseEvent> events = this.parseEvents(container.getValues());
View
9 src/main/java/com/rackspacecloud/client/service_registry/clients/ServicesClient.java
@@ -19,6 +19,7 @@
import com.google.gson.reflect.TypeToken;
import com.rackspacecloud.client.service_registry.ClientResponse;
+import com.rackspacecloud.client.service_registry.PaginationOptions;
import com.rackspacecloud.client.service_registry.containers.ServicesContainer;
import com.rackspacecloud.client.service_registry.objects.Service;
import com.rackspacecloud.client.service_registry.objects.Session;
@@ -39,19 +40,19 @@ public ServicesClient(AuthClient authClient) {
super(authClient);
}
- public List<Service> list(Map<String, String> options) throws Exception {
- return list(options, null);
+ public List<Service> list(PaginationOptions paginationOptions) throws Exception {
+ return list(paginationOptions, null);
}
- public List<Service> list(Map<String, String> options, String tag) throws Exception {
+ public List<Service> list(PaginationOptions paginationOptions, String tag) throws Exception {
Type type = new TypeToken<ServicesContainer>() {}.getType();
List<NameValuePair> params = new ArrayList<NameValuePair>();
if (tag != null) {
params.add(new BasicNameValuePair("tag", tag));
}
- ClientResponse response = this.performRequest("/services", params, new HttpGet(), true, type);
+ ClientResponse response = this.performListRequest(paginationOptions, "/services", params, new HttpGet(), true, type);
ServicesContainer container = (ServicesContainer)response.getBody();
return container.getValues();
View
9 src/main/java/com/rackspacecloud/client/service_registry/clients/SessionsClient.java
@@ -18,10 +18,7 @@
package com.rackspacecloud.client.service_registry.clients;
import com.google.gson.reflect.TypeToken;
-import com.rackspacecloud.client.service_registry.ClientResponse;
-import com.rackspacecloud.client.service_registry.HeartBeater;
-import com.rackspacecloud.client.service_registry.SessionCreateResponse;
-import com.rackspacecloud.client.service_registry.Utils;
+import com.rackspacecloud.client.service_registry.*;
import com.rackspacecloud.client.service_registry.containers.SessionsContainer;
import com.rackspacecloud.client.service_registry.objects.HeartbeatToken;
import com.rackspacecloud.client.service_registry.objects.Session;
@@ -41,9 +38,9 @@ public SessionsClient(AuthClient authClient) {
this.authClient = authClient;
}
- public List<Session> list(Map<String, String> options) throws Exception {
+ public List<Session> list(PaginationOptions paginationOptions) throws Exception {
Type type = new TypeToken<SessionsContainer>() {}.getType();
- ClientResponse response = this.performRequest("/sessions", null, new HttpGet(), true, type);
+ ClientResponse response = this.performListRequest(paginationOptions, "/sessions", null, new HttpGet(), true, type);
SessionsContainer container = (SessionsContainer)response.getBody();
return container.getValues();
View
5 src/main/java/com/rackspacecloud/client/service_registry/clients/ViewsClient.java
@@ -19,6 +19,7 @@
import com.google.gson.reflect.TypeToken;
import com.rackspacecloud.client.service_registry.ClientResponse;
+import com.rackspacecloud.client.service_registry.PaginationOptions;
import com.rackspacecloud.client.service_registry.containers.OverviewContainer;
import com.rackspacecloud.client.service_registry.objects.Overview;
import org.apache.http.client.methods.HttpGet;
@@ -32,9 +33,9 @@ public ViewsClient(AuthClient authClient) {
super(authClient);
}
- public List<Overview> getOverview(Map<String, String> options) throws Exception {
+ public List<Overview> getOverview(PaginationOptions paginationOptions) throws Exception {
Type type = new TypeToken<OverviewContainer>() {}.getType();
- ClientResponse response = this.performRequest("/views/overview", null, new HttpGet(), true, type);
+ ClientResponse response = this.performListRequest(paginationOptions, "/views/overview", null, new HttpGet(), true, type);
OverviewContainer container = (OverviewContainer)response.getBody();
return container.getValues();

0 comments on commit 53b851a

Please sign in to comment.