Skip to content

Commit eef9a4c

Browse files
committed
Add close() and callback sections to readme
[skip ci]
1 parent bcb908d commit eef9a4c

File tree

1 file changed

+52
-27
lines changed

1 file changed

+52
-27
lines changed

README.md

Lines changed: 52 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public class Example {
101101
.put("auto-create", new JSONArray()
102102
.put("dimension")
103103
.put("column"));
104-
System.out.println(client.insert(insertData));
104+
System.out.println(client.insert(insertData).get().getResponseBody());
105105

106106
// Querying data
107107
JSONObject queryData = new JSONObject()
@@ -115,7 +115,7 @@ public class Example {
115115
new JSONArray()
116116
.put(20)
117117
.put(40)))));
118-
System.out.println(client.countEntity(queryData));
118+
System.out.println(client.countEntity(queryData).get().getResponseBody());
119119
}
120120
}
121121
```
@@ -155,8 +155,8 @@ import org.asynchttpclient.Response;
155155

156156
public class Example {
157157

158-
public static void main(String[] args) throws IOException {
159-
final SlicingDice slicingDice = new SlicingDice("MASTER_API_KEY", false);
158+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
159+
final SlicingDice slicingDice = new SlicingDice("MASTER_API_KEY");
160160
final Future<Response> result = slicingDice.getDatabase();
161161
System.out.println(result.get().getResponseBody());
162162

@@ -194,7 +194,7 @@ import org.asynchttpclient.Response;
194194

195195
public class Example {
196196

197-
public static void main(String[] args) throws IOException {
197+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
198198
final SlicingDice slicingDice = new SlicingDice("MASTER_API_KEY");
199199
final Future<Response> result = slicingDice.getColumns();
200200
System.out.println(result.get().getResponseBody());
@@ -246,7 +246,7 @@ import org.asynchttpclient.Response;
246246

247247
public class Example {
248248

249-
public static void main(String[] args) throws IOException {
249+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
250250
final SlicingDice slicingDice = new SlicingDice("MASTER_API_KEY");
251251
final JSONObject column = new JSONObject()
252252
.put("name", "Year")
@@ -288,7 +288,7 @@ import org.asynchttpclient.Response;
288288

289289
public class Example {
290290

291-
public static void main(String[] args) throws IOException {
291+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
292292
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_WRITE_API_KEY");
293293
final SONObject insertData = new JSONObject()
294294
.put("user1@slicingdice.com", new JSONObject()
@@ -353,7 +353,7 @@ import org.json.JSONObject;
353353

354354
public class Example {
355355

356-
public static void main(String[] args) throws IOException {
356+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
357357
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY");
358358
final JSONArray ids = new JSONArray()
359359
.put("user1@slicingdice.com")
@@ -397,8 +397,8 @@ import org.json.JSONObject;
397397

398398
public class Example {
399399

400-
public static void main(String[] args) throws IOException {
401-
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY", false);
400+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
401+
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY");
402402
final Future<Response> result = slicingDice.countEntityTotal();
403403
System.out.println(result.get().getResponseBody());
404404

@@ -434,7 +434,7 @@ import org.json.JSONObject;
434434

435435
public class Example {
436436

437-
public static void main(String[] args) throws IOException {
437+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
438438
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY");
439439
final Set<String> dimensions = Collections.singleton("default");
440440
final Future<Response> result = slicingDice.countEntityTotal(dimensions);
@@ -472,7 +472,7 @@ import org.asynchttpclient.Response;
472472

473473
public class Example {
474474

475-
public static void main(String[] args) throws IOException {
475+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
476476
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY");
477477
final JSONArray countEntityQuery = new JSONArray()
478478
.put(new JSONObject()
@@ -529,7 +529,7 @@ import org.asynchttpclient.Response;
529529

530530
public class Example {
531531

532-
public static void main(String[] args) throws IOException {
532+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
533533
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY");
534534
final JSONObject countEntityQuery = new JSONObject()
535535
.put("query-name", "corolla-or-fit")
@@ -577,8 +577,8 @@ import org.json.JSONObject;
577577

578578
public class Example {
579579

580-
public static void main(String[] args) throws IOException {
581-
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY", false);
580+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
581+
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY");
582582
final JSONArray countEventQuery = new JSONArray()
583583
.put(new JSONObject()
584584
.put("query-name", "test-drives-in-ny")
@@ -637,8 +637,8 @@ import org.json.JSONObject;
637637

638638
public class Example {
639639

640-
public static void main(String[] args) throws IOException {
641-
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY", false);
640+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
641+
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY");
642642
final JSONObject countEventQuery = new JSONObject()
643643
.put("query-name", "test-drives-in-ny")
644644
.put("query", new JSONArray()
@@ -684,7 +684,7 @@ import org.json.JSONObject;
684684

685685
public class Example {
686686

687-
public static void main(String[] args) throws IOException {
687+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
688688
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY");
689689
final JSONObject topValuesQuery = new JSONObject()
690690
.put("car-year", new JSONObject()
@@ -753,7 +753,7 @@ import org.json.JSONObject;
753753

754754
public class Example {
755755

756-
public static void main(String[] args) throws IOException {
756+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
757757
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY");
758758
final JSONObject aggregationQuery = new JSONObject()
759759
.put("query", new JSONArray()
@@ -812,7 +812,7 @@ import org.asynchttpclient.Response;
812812

813813
public class Example {
814814

815-
public static void main(String[] args) throws IOException {
815+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
816816
final SlicingDice slicingDice = new SlicingDice("MASTER_API_KEY");
817817
final Future<Response> result = slicingDice.getSavedQueries();
818818
System.out.println(result.get().getResponseBody());
@@ -877,7 +877,7 @@ import org.json.JSONObject;
877877

878878
public class Example {
879879

880-
public static void main(String[] args) throws IOException {
880+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
881881
final SlicingDice slicingDice = new SlicingDice("MASTER_API_KEY");
882882
final JSONObject savedQuery = new JSONObject()
883883
.put("name", "my-saved-query")
@@ -939,7 +939,7 @@ import org.json.JSONObject;
939939

940940
public class Example {
941941

942-
public static void main(String[] args) throws IOException {
942+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
943943
final SlicingDice slicingDice = new SlicingDice("MASTER_API_KEY");
944944
final JSONObject newSavedQuery = new JSONObject()
945945
.put("type", "count/entity")
@@ -997,7 +997,7 @@ import org.asynchttpclient.Response;
997997

998998
public class Example {
999999

1000-
public static void main(String[] args) throws IOException {
1000+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
10011001
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY");
10021002
final Future<Response> result = slicingDice.getSavedQuery("my-saved-query");
10031003
System.out.println(result.get().getResponseBody());
@@ -1046,7 +1046,7 @@ import org.asynchttpclient.Response;
10461046

10471047
public class Example {
10481048

1049-
public static void main(String[] args) throws IOException {
1049+
public static void main(String[] args) InterruptedException, ExecutionException, throws IOException {
10501050
final SlicingDice slicingDice = new SlicingDice("MASTER_API_KEY");
10511051
final Future<Response> result = slicingDice.deleteSavedQuery("my-saved-query");
10521052
System.out.println(result.get().getResponseBody());
@@ -1096,7 +1096,7 @@ import org.json.JSONObject;
10961096

10971097
public class Example {
10981098

1099-
public static void main(String[] args) throws IOException {
1099+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
11001100
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY");
11011101
final JSONObject resultQuery = new JSONObject()
11021102
.put("query", new JSONArray()
@@ -1155,7 +1155,7 @@ import org.json.JSONObject;
11551155

11561156
public class Example {
11571157

1158-
public static void main(String[] args) throws IOException {
1158+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
11591159
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY");
11601160
final JSONObject scoreQuery = new JSONObject()
11611161
.put("query", new JSONArray()
@@ -1212,7 +1212,7 @@ import org.asynchttpclient.Response;
12121212

12131213
public class Example {
12141214

1215-
public static void main(String[] args) throws IOException {
1215+
public static void main(String[] args) throws InterruptedException, ExecutionException, IOException {
12161216
final SlicingDice slicingDice = new SlicingDice("MASTER_OR_READ_API_KEY");
12171217
final Future<Response> result = slicingDice.sql("SELECT COUNT(*) FROM default WHERE age BETWEEN 0 AND 49");
12181218
System.out.println(result.get().getResponseBody());
@@ -1235,6 +1235,31 @@ public class Example {
12351235
}
12361236
```
12371237

1238+
## `close()`
1239+
Use this method when you're done with SlicingDice client, this method will properly close http threads.
1240+
1241+
## Using callback instead of Future
1242+
The programmer can define callbacks instead of using returned Futures, to create a callback you'll need to extend the class HandlerResponse and implement the methods `onError` and `onSuccess`. See the example below.
1243+
1244+
```java
1245+
public static class MyHandler extends HandlerResponse {
1246+
@Override
1247+
public void onSuccess(final JSONObject data) throws Exception {
1248+
System.out.println(data.toString());
1249+
}
1250+
1251+
@Override
1252+
public void onError(final JSONObject data) throws Exception {
1253+
System.out.println(data.toString());
1254+
}
1255+
}
1256+
```
1257+
1258+
And you can use the handler this way:
1259+
```java
1260+
slicingDice.sql("SELECT COUNT(*) FROM default WHERE age BETWEEN 0 AND 49", new MyHandler());
1261+
```
1262+
12381263
## License
12391264

12401265
[MIT](https://opensource.org/licenses/MIT)

0 commit comments

Comments
 (0)