vayacondios-server 0.2.11 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. data/.gitignore +3 -1
  2. data/.travis.yml +2 -0
  3. data/Gemfile +15 -9
  4. data/LICENSE.md +2 -6
  5. data/Procfile +1 -1
  6. data/README.md +656 -111
  7. data/Rakefile +89 -6
  8. data/bin/vcd +10 -0
  9. data/bin/vcd-server +8 -0
  10. data/config/database.yml +6 -0
  11. data/config/spec.example.yml +18 -0
  12. data/config/vayacondios.example.yml +15 -0
  13. data/config/vcd-server.rb +37 -0
  14. data/examples/configuration.rb +56 -0
  15. data/examples/event_stream.rb +19 -0
  16. data/examples/simple.rb +61 -0
  17. data/features/event.feature +319 -0
  18. data/features/events.feature +208 -0
  19. data/features/stash.feature +840 -0
  20. data/features/stashes.feature +492 -0
  21. data/features/step_definitions/stash_steps.rb +113 -0
  22. data/features/stream.feature +30 -0
  23. data/features/support/em.rb +14 -0
  24. data/features/support/env.rb +13 -0
  25. data/lib/vayacondios/configuration.rb +63 -0
  26. data/lib/vayacondios/server/api.rb +126 -0
  27. data/lib/vayacondios/server/api_options.rb +56 -0
  28. data/lib/vayacondios/server/configuration.rb +23 -0
  29. data/lib/vayacondios/server/driver.rb +71 -0
  30. data/lib/vayacondios/server/drivers/mongo.rb +126 -0
  31. data/lib/vayacondios/server/handlers/document_handler.rb +81 -0
  32. data/lib/vayacondios/server/handlers/event_handler.rb +31 -26
  33. data/lib/vayacondios/server/handlers/events_handler.rb +31 -0
  34. data/lib/vayacondios/server/handlers/stash_handler.rb +69 -0
  35. data/lib/vayacondios/server/handlers/stashes_handler.rb +49 -0
  36. data/lib/vayacondios/server/handlers/stream_handler.rb +39 -0
  37. data/lib/vayacondios/server/models/document.rb +87 -0
  38. data/lib/vayacondios/server/models/event.rb +198 -0
  39. data/lib/vayacondios/server/models/stash.rb +100 -0
  40. data/lib/vayacondios/server.rb +35 -0
  41. data/lib/vayacondios-server.rb +19 -13
  42. data/lib/vayacondios.rb +22 -0
  43. data/pom.xml +124 -4
  44. data/spec/configuration_spec.rb +41 -0
  45. data/spec/server/api_options_spec.rb +32 -0
  46. data/spec/server/api_spec.rb +279 -0
  47. data/spec/server/configuration_spec.rb +27 -0
  48. data/spec/server/drivers/mongo_spec.rb +107 -0
  49. data/spec/server/handlers/event_handler_spec.rb +62 -0
  50. data/spec/server/handlers/events_handler_spec.rb +51 -0
  51. data/spec/server/handlers/stash_handler_spec.rb +68 -0
  52. data/spec/server/handlers/stashes_handler_spec.rb +50 -0
  53. data/spec/server/handlers/stream_handler_spec.rb +5 -0
  54. data/spec/server/models/document_spec.rb +9 -0
  55. data/spec/server/models/event_spec.rb +185 -0
  56. data/spec/server/models/stash_spec.rb +95 -0
  57. data/spec/spec_helper.rb +23 -3
  58. data/spec/support/database_helper.rb +42 -0
  59. data/spec/support/log_helper.rb +19 -0
  60. data/spec/support/shared_context_for_events.rb +22 -0
  61. data/spec/support/shared_context_for_stashes.rb +24 -0
  62. data/spec/support/shared_examples_for_handlers.rb +32 -0
  63. data/src/main/java/com/infochimps/vayacondios/BaseClient.java +342 -0
  64. data/src/main/java/com/infochimps/vayacondios/HTTPClient.java +426 -0
  65. data/src/main/java/com/infochimps/vayacondios/VayacondiosClient.java +487 -65
  66. data/src/main/java/com/infochimps/vayacondios/test/IntegrationTest.java +3 -0
  67. data/src/test/java/com/infochimps/vayacondios/BaseClientTest.java +50 -0
  68. data/src/test/java/com/infochimps/vayacondios/HTTPClientIT.java +267 -0
  69. data/vayacondios-server.gemspec +9 -9
  70. metadata +127 -122
  71. checksums.yaml +0 -15
  72. data/.rspec +0 -2
  73. data/.yardopts +0 -10
  74. data/Guardfile +0 -41
  75. data/app/http_shim.rb +0 -71
  76. data/bin/vcd.sh +0 -27
  77. data/config/http_shim.rb +0 -43
  78. data/config/vayacondios.example.yaml +0 -7
  79. data/config/vayacondios.yaml +0 -7
  80. data/examples/java/ItemSetTest.java +0 -76
  81. data/lib/tasks/publish.rake +0 -23
  82. data/lib/tasks/spec.rake +0 -11
  83. data/lib/tasks/yard.rake +0 -2
  84. data/lib/vayacondios/client/config.rb +0 -7
  85. data/lib/vayacondios/client/configliere.rb +0 -38
  86. data/lib/vayacondios/client/cube_client.rb +0 -39
  87. data/lib/vayacondios/client/http_client.rb +0 -49
  88. data/lib/vayacondios/client/itemset.rb +0 -130
  89. data/lib/vayacondios/client/legacy_switch.rb +0 -43
  90. data/lib/vayacondios/client/notifier.rb +0 -123
  91. data/lib/vayacondios/client/zabbix_client.rb +0 -148
  92. data/lib/vayacondios/legacy_switch.rb +0 -43
  93. data/lib/vayacondios/server/errors/bad_request.rb +0 -6
  94. data/lib/vayacondios/server/errors/not_found.rb +0 -6
  95. data/lib/vayacondios/server/handlers/config_handler.rb +0 -32
  96. data/lib/vayacondios/server/handlers/itemset_handler.rb +0 -60
  97. data/lib/vayacondios/server/legacy_switch.rb +0 -43
  98. data/lib/vayacondios/server/model/config_document.rb +0 -89
  99. data/lib/vayacondios/server/model/document.rb +0 -25
  100. data/lib/vayacondios/server/model/event_document.rb +0 -94
  101. data/lib/vayacondios/server/model/itemset_document.rb +0 -126
  102. data/lib/vayacondios/server/rack/extract_methods.rb +0 -35
  103. data/lib/vayacondios/server/rack/jsonize.rb +0 -43
  104. data/lib/vayacondios/server/rack/params.rb +0 -50
  105. data/lib/vayacondios/server/rack/path.rb +0 -23
  106. data/lib/vayacondios/server/rack/path_validation.rb +0 -22
  107. data/lib/vayacondios/version.rb +0 -3
  108. data/lib/vayacondios-client.rb +0 -22
  109. data/scripts/hadoop_monitor/configurable.rb +0 -66
  110. data/scripts/hadoop_monitor/hadoop_attempt_scraper.rb +0 -45
  111. data/scripts/hadoop_monitor/hadoop_client.rb +0 -273
  112. data/scripts/hadoop_monitor/hadoop_monitor.rb +0 -101
  113. data/scripts/hadoop_monitor/hadoopable.rb +0 -65
  114. data/scripts/hadoop_monitor/machine_monitor.rb +0 -115
  115. data/scripts/s3_cataloger/buckets +0 -33
  116. data/scripts/s3_cataloger/foreach_bucket +0 -88
  117. data/scripts/s3_cataloger/parse_ls.py +0 -391
  118. data/spec/client/itemset_legacy_spec.rb +0 -55
  119. data/spec/client/itemset_spec.rb +0 -60
  120. data/spec/client/notifier_spec.rb +0 -120
  121. data/spec/server/config_spec.rb +0 -113
  122. data/spec/server/event_spec.rb +0 -103
  123. data/spec/server/itemset_legacy_spec.rb +0 -320
  124. data/spec/server/itemset_spec.rb +0 -317
  125. data/spec/server/rack/extract_methods_spec.rb +0 -60
  126. data/spec/server/rack/path_spec.rb +0 -36
  127. data/spec/server/rack/path_validation_spec.rb +0 -22
  128. data/spec/server/server_spec.rb +0 -20
  129. data/spec/support/mongo_cleaner.rb +0 -32
  130. data/src/main/java/ItemSetTest.java +0 -76
  131. data/src/main/java/com/infochimps/util/CurrentClass.java +0 -26
  132. data/src/main/java/com/infochimps/util/DebugUtil.java +0 -38
  133. data/src/main/java/com/infochimps/util/HttpHelper.java +0 -181
  134. data/src/main/java/com/infochimps/vayacondios/ItemSets.java +0 -373
  135. data/src/main/java/com/infochimps/vayacondios/LinkToVCD.java +0 -18
  136. data/src/main/java/com/infochimps/vayacondios/MemoryVCDShim.java +0 -84
  137. data/src/main/java/com/infochimps/vayacondios/Organization.java +0 -62
  138. data/src/main/java/com/infochimps/vayacondios/PathBuilder.java +0 -13
  139. data/src/main/java/com/infochimps/vayacondios/StandardVCDLink.java +0 -218
  140. data/src/main/java/com/infochimps/vayacondios/VCDIntegrationTest.java +0 -108
  141. data/src/test/java/com/infochimps/vayacondios/TestVayacondiosInMemory.java +0 -78
  142. data/vayacondios-client.gemspec +0 -25
@@ -0,0 +1,426 @@
1
+ package com.infochimps.vayacondios;
2
+
3
+ import java.util.Map;
4
+ import java.util.List;
5
+ import java.util.Arrays;
6
+ import java.util.ArrayList;
7
+ import java.io.IOException;
8
+ import java.io.UnsupportedEncodingException;
9
+ import java.net.URI;
10
+ import java.net.URISyntaxException;
11
+
12
+ import org.apache.commons.lang3.StringUtils;
13
+ import org.apache.commons.lang3.ArrayUtils;
14
+
15
+ import org.slf4j.Logger;
16
+ import org.slf4j.LoggerFactory;
17
+
18
+ import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
19
+ import org.apache.http.client.methods.HttpGet;
20
+ import org.apache.http.HttpResponse;
21
+ import org.apache.http.entity.StringEntity;
22
+ import org.apache.http.impl.client.DefaultHttpClient;
23
+ import org.apache.http.impl.client.BasicResponseHandler;
24
+
25
+ import com.ning.http.client.AsyncHttpClient;
26
+ import com.ning.http.client.AsyncCompletionHandler;
27
+ import com.ning.http.client.Response;
28
+ import java.util.concurrent.Future;
29
+
30
+ import com.google.gson.Gson;
31
+ import com.google.gson.GsonBuilder;
32
+ import com.google.gson.JsonParseException;
33
+
34
+ /** A Vayacondios client which communicates with the Vayacondios
35
+ * server via HTTP requests.
36
+ *
37
+ * Requests which write data to the Vayacondios server are implemented
38
+ * via asynchronous (non-blocking) calls which with return type
39
+ * <code>void</code>.These include:
40
+ *
41
+ * <ul>
42
+ * <li>announce</li>
43
+ * <li>set</li>
44
+ * <li>merge</li>
45
+ * <li>delete</li>
46
+ * </ul>
47
+ *
48
+ * Requests which read data from the Vayacondios server are
49
+ * implemented via synchronous (blocking) calls which return an
50
+ * expected Java type. These include:
51
+ *
52
+ * <ul>
53
+ * <li>events</li>
54
+ * <li>stashes</li>
55
+ * <li>get, getMap, getList, getString, getDouble</li>
56
+ * </ul>
57
+ *
58
+ * Each Vayacondios HTTPClient instance exposes two HTTP client objects:
59
+ *
60
+ * <ul>
61
+ * <li>{@link #asynchronousClient()} which returns an AsyncHttpClient from the <a href="https://github.com/AsyncHttpClient/async-http-client">AsyncHttpClient</a></li> library
62
+ * <li>{@link #synchronousClient()} which returns a <code>Defaulthttpclient</code> from the <a href="http://hc.apache.org/httpclient-3.x/">Apache commons HttpClient</a> library
63
+ * </ul>
64
+ *
65
+ * You can use these objects directly to do make raw HTTP requests
66
+ * against the Vayacondios server in whichever mode you prefer.
67
+ *
68
+ */
69
+ public class HTTPClient extends BaseClient {
70
+
71
+ private class HttpGetWithBody extends HttpEntityEnclosingRequestBase {
72
+
73
+ public final static String METHOD_NAME = "GET";
74
+
75
+ HttpGetWithBody(String uri, String body) throws URISyntaxException, UnsupportedEncodingException {
76
+ setURI(new URI(uri));
77
+ setEntity(new StringEntity(body));
78
+ }
79
+
80
+ @Override
81
+ public String getMethod() {
82
+ return METHOD_NAME;
83
+ }
84
+ }
85
+
86
+ private class AsyncResponseHandler extends AsyncCompletionHandler {
87
+ @Override
88
+ public Response onCompleted(Response response) throws Exception {
89
+ return response;
90
+ }
91
+ }
92
+
93
+ //----------------------------------------------------------------------------
94
+ // Initialization & Properties
95
+ //----------------------------------------------------------------------------
96
+
97
+ private static Logger LOG = LoggerFactory.getLogger(HTTPClient.class);
98
+
99
+ /** Default Vayacondios server host. */
100
+ public static String DEFAULT_HOST = "localhost";
101
+
102
+ /** Default Vayacondios server port. */
103
+ public static Integer DEFAULT_PORT = 9000;
104
+
105
+ private String _host;
106
+ private Integer _port;
107
+
108
+ private DefaultHttpClient sync;
109
+ private AsyncHttpClient async;
110
+ private Gson serializer;
111
+
112
+ /**
113
+ * Create a new HTTPClient specifying all options.
114
+ *
115
+ * Set the host and port for the Vayacondios server as well as the
116
+ * organization for the client and whether the client should be in
117
+ * "dry-run" mode.
118
+ *
119
+ * <blockquote><pre>{@code
120
+ * VayacondiosClient client = new HTTPClient("example.com", 1234, "website", true);
121
+ * }</pre></blockquote>
122
+ *
123
+ * @param host host of Vayacondios server
124
+ * @param port port of Vayacondios server
125
+ * @param organization name of the organization to read/write data for
126
+ * @param shouldDryRun whether or not to be in "dry-run" mode
127
+ */
128
+ public HTTPClient(String host, Integer port, String organization, Boolean shouldDryRun) {
129
+ super(organization, shouldDryRun);
130
+ this._host = host;
131
+ this._port = port;
132
+ this.sync = new DefaultHttpClient();
133
+ this.async = new AsyncHttpClient();
134
+ this.serializer = new GsonBuilder()
135
+ .disableHtmlEscaping()
136
+ .serializeNulls()
137
+ .create();
138
+ }
139
+
140
+ /**
141
+ * Create a new HTTPClient with the given options.
142
+ *
143
+ * Set the host and port for the Vayacondios server as well as the
144
+ * organization for the client.
145
+ *
146
+ * <blockquote><pre>{@code
147
+ * VayacondiosClient client = new HTTPClient("example.com", 1234, "website");
148
+ * }</pre></blockquote>
149
+ *
150
+ * @param host host of Vayacondios server
151
+ * @param port port of Vayacondios server
152
+ * @param organization name of the organization to read/write data for
153
+ */
154
+ public HTTPClient(String host, Integer port, String organization) {
155
+ this(host, DEFAULT_PORT, organization, false);
156
+ }
157
+
158
+ /**
159
+ * Create a new HTTPClient on the default port with the given
160
+ * options.
161
+ *
162
+ * Set the host for the Vayacondios server as well as the
163
+ * organization for the client.
164
+ *
165
+ * <blockquote><pre>{@code
166
+ * VayacondiosClient client = new HTTPClient("example.com", "website");
167
+ * }</pre></blockquote>
168
+ *
169
+ * @param host host of Vayacondios server
170
+ * @param organization name of the organization to read/write data for
171
+ */
172
+ public HTTPClient(String host, String organization) {
173
+ this(host, DEFAULT_PORT, organization, false);
174
+ }
175
+
176
+ /**
177
+ * Create a new HTTPClient for a local Vayacondios server for the
178
+ * given organization.
179
+ *
180
+ * This is most useful when developing or testing with
181
+ * Vayacondios.
182
+ *
183
+ * <blockquote><pre>{@code
184
+ * VayacondiosClient client = new HTTPClient("website");
185
+ * }</pre></blockquote>
186
+ *
187
+ * @param organization name of the organization to read/write data for
188
+ */
189
+ public HTTPClient(String organization) {
190
+ this(DEFAULT_HOST, DEFAULT_PORT, organization, false);
191
+ }
192
+
193
+ /**
194
+ * Host of the Vayacondios server this client will send requests
195
+ * to.
196
+ *
197
+ * @return the hostname
198
+ */
199
+ public String host() { return _host; }
200
+
201
+ /**
202
+ * Port of the Vayacondios server this client will send requests
203
+ * to.
204
+ *
205
+ * @return the port number
206
+ */
207
+ public Integer port() { return _port; }
208
+
209
+ /**
210
+ * The HTTP client used for making synchronous HTTP requests.
211
+ * <p>
212
+ * Requests made with this client will block until a response
213
+ * comes back from the server.
214
+ * <p>
215
+ * Here's an example of how to retrieve an event with a a given ID
216
+ * (something that's not wrapped with a method in the {@link
217
+ * VayacondiosClient} class):
218
+ *
219
+ * <blockquote><pre>{@code
220
+ * HttpGet getRequest = new HttpGet(client.url("event", "transactions", "39487"));
221
+ * HttpResponse response = client.synchronousClient().execute(getRequest)
222
+ * // Parse response body as JSON text, do stuff...
223
+ * }</pre></blockquote>
224
+ *
225
+ * See the <a href="http://hc.apache.org/httpclient-3.x/">Apache
226
+ * commons HttpClient</a> library for more details.
227
+ *
228
+ * @return the client
229
+ */
230
+ public DefaultHttpClient synchronousClient() { return sync; }
231
+
232
+ /**
233
+ * The HTTP client used for making asynchronous HTTP requests.
234
+ * <p>
235
+ * Requests made with this client are non-blocking.
236
+ * <p>
237
+ * Here's an example of how to retrieve an event with a a given ID
238
+ * (something that's not wrapped with a method in the {@link
239
+ * VayacondiosClient} class):
240
+ *
241
+ * <blockquote><pre>{@code
242
+ * AsyncHttpClient asyncHttpClient = client.asynchronousClient();
243
+ * Future<Response> future = asyncHttpClient.prepareGet(client.url("event", "transactions", "39487")).execute();
244
+ * Response response = future.get();
245
+ * // Parse response body as JSON text, do stuff...
246
+ * }</pre></blockquote>
247
+ *
248
+ * See the <a
249
+ * href="https://github.com/AsyncHttpClient/async-http-client">AsyncHttpClient</a>
250
+ * library for more details.
251
+ *
252
+ * @return the client
253
+ */
254
+ public AsyncHttpClient asynchronousClient() { return async; }
255
+
256
+ /** Close any open connections to the Vayacondios server.
257
+ *
258
+ * Take caution calling this method immediately after asynchronous
259
+ * calls by the client. The following code would cause an error
260
+ * and is <b>not</b> the preferred way to use a
261
+ * <code>VayacondiosClient</code> instance:
262
+ *
263
+ * <blockquote><pre>{@code
264
+ * // Do NOT do this
265
+ * private void incrementTotal(Integer n) {
266
+ * VayacondiosClient client = new HttpClient("my_organization");
267
+ * client.set("project", "counter", n);
268
+ * client.close();
269
+ * }
270
+ * }</pre></blockquote>
271
+ *
272
+ * because the call to <code>client.close()</code> will occur
273
+ * before the HTTP request started by the call to
274
+ * <code>client.set</code> finishes.
275
+ *
276
+ * The proper way to use a <code>VayacondiosClient</code> is to
277
+ * set up the client during initialization of your appilcation and
278
+ * only close it at the end -- when you can afford to throw in a
279
+ * call to {@link Thread#sleep(long millis)} if you need to.
280
+ *
281
+ * */
282
+ @Override
283
+ public void close() {
284
+ async.close();
285
+ };
286
+
287
+ /**
288
+ * The URL this client will use to make a query to the given path
289
+ * segments. This method is not required during "normal" usage of
290
+ * the client (though it is called internally when making
291
+ * requests) but comes in handy when debugging or when using this
292
+ * Vayacondios client's own synchronous and/or asynchronous HTTP
293
+ * clients.
294
+ *
295
+ * <blockquote><pre>{@code
296
+ * client.url("event", "transactions", "9783") // URL for retrieving and event by ID
297
+ * client.url("foo", "bar", "baz", "boof") // garbage URL...
298
+ * }</pre></blockquote>
299
+ *
300
+ * @param pathSegments each path segment
301
+ * @return the URL for the given path segments, including domain, version, and organization
302
+ */
303
+ public String url(String... pathSegments) {
304
+ ArrayList urlSegments = new ArrayList();
305
+ urlSegments.add("http://" + _host + ":" + _port);
306
+ urlSegments.add(BaseClient.VERSION);
307
+ urlSegments.add(organization());
308
+ urlSegments.addAll(Arrays.asList(pathSegments));
309
+ return StringUtils.join(urlSegments, "/");
310
+ }
311
+
312
+ //----------------------------------------------------------------------------
313
+ // BaseClient Private API Implementation
314
+ //----------------------------------------------------------------------------
315
+
316
+ @Override
317
+ protected void performAnnounce(String topic, Map<String,Object> event, String id) throws IOException {
318
+ async.preparePost(url("event", topic, id)).setBody(toJson(event)).execute(asyncResponseHandler());
319
+ }
320
+ @Override
321
+ protected void performAnnounce(String topic, Map<String,Object> event) throws IOException {
322
+ async.preparePost(url("event", topic)).setBody(toJson(event)).execute(asyncResponseHandler());
323
+ }
324
+
325
+ @Override
326
+ protected List<Map<String,Object>> performEvents(String topic, Map<String,Object> query) throws IOException {
327
+ try {
328
+ return parseList(sync.execute(new HttpGetWithBody(url("events", topic), toJson(query)), syncResponseHandler()));
329
+ } catch (URISyntaxException e) {
330
+ LOG.error("Failed to search events <" + topic + ">", e);
331
+ return new ArrayList();
332
+ }
333
+ }
334
+
335
+ @Override
336
+ protected Map<String,Object> performGet(String topic) throws IOException {
337
+ return parseMap(sync.execute(new HttpGet(url("stash", topic)), syncResponseHandler()));
338
+ }
339
+
340
+ @Override
341
+ protected Map<String,Object> performGetMap(String topic, String id) throws IOException {
342
+ return parseMap(sync.execute(new HttpGet(url("stash", topic, id)), syncResponseHandler()));
343
+ }
344
+ @Override
345
+ protected List<Object> performGetList(String topic, String id) throws IOException {
346
+ return parseList(sync.execute(new HttpGet(url("stash", topic, id)), syncResponseHandler()));
347
+ }
348
+ @Override
349
+ protected String performGetString(String topic, String id) throws IOException {
350
+ return parseString(sync.execute(new HttpGet(url("stash", topic, id)), syncResponseHandler()));
351
+ }
352
+ @Override
353
+ protected Double performGetDouble(String topic, String id) throws IOException {
354
+ return parseDouble(sync.execute(new HttpGet(url("stash", topic, id)), syncResponseHandler()));
355
+ }
356
+
357
+ @Override
358
+ protected List<Map<String,Object>> performStashes(Map<String,Object> query) throws IOException {
359
+ try {
360
+ return parseList(sync.execute(new HttpGetWithBody(url("stashes"), toJson(query)), syncResponseHandler()));
361
+ } catch (URISyntaxException e) {
362
+ LOG.error("Failed to search stashes", e);
363
+ return new ArrayList();
364
+ }
365
+ }
366
+
367
+ @Override
368
+ protected void performMerge(String topic, String id, Object value) throws IOException {
369
+ async.preparePut(url("stash", topic, id)).setBody(toJson(value)).execute(asyncResponseHandler());
370
+ }
371
+ @Override
372
+ protected void performMerge(String topic, Map<String,Object> value) throws IOException {
373
+ async.preparePut(url("stash", topic)).setBody(toJson(value)).execute(asyncResponseHandler());
374
+ }
375
+
376
+ @Override
377
+ protected void performSet(String topic, String id, Object value) throws IOException {
378
+ async.preparePost(url("stash", topic, id)).setBody(toJson(value)).execute(asyncResponseHandler());
379
+ }
380
+ @Override
381
+ protected void performSet(String topic, Map<String,Object> value) throws IOException {
382
+ async.preparePost(url("stash", topic)).setBody(toJson(value)).execute(asyncResponseHandler());
383
+ }
384
+
385
+ @Override
386
+ protected void performDelete(String topic, String id) throws IOException {
387
+ async.prepareDelete(url("stash", topic, id)).execute(asyncResponseHandler());
388
+ }
389
+ @Override
390
+ protected void performDelete(String topic) throws IOException {
391
+ async.prepareDelete(url("stash", topic)).execute(asyncResponseHandler());
392
+ }
393
+
394
+ //----------------------------------------------------------------------------
395
+ // Private Methods
396
+ //----------------------------------------------------------------------------
397
+
398
+ private String toJson(Object object) {
399
+ return serializer.toJson(object);
400
+ }
401
+
402
+ private BasicResponseHandler syncResponseHandler() {
403
+ return new BasicResponseHandler();
404
+ }
405
+
406
+ private AsyncResponseHandler asyncResponseHandler() {
407
+ return new AsyncResponseHandler();
408
+ }
409
+
410
+ private Map<String,Object> parseMap(String json) throws JsonParseException {
411
+ return serializer.fromJson(json, Map.class);
412
+ }
413
+
414
+ private List parseList(String json) throws JsonParseException {
415
+ return serializer.fromJson(json, List.class);
416
+ }
417
+
418
+ private String parseString(String json) throws JsonParseException {
419
+ return serializer.fromJson(json, String.class);
420
+ }
421
+
422
+ private Double parseDouble(String json) throws JsonParseException {
423
+ return serializer.fromJson(json, Double.class);
424
+ }
425
+
426
+ }