entries) throws UnsupportedEnc
*
* @throws StitchException if Stitch rejected or was unable to
* process the message
- * @throws IOException if there was an error communicating with
- * Stitch
+ * @throws IOException if there was an error communicating with
+ * Stitch
*/
public void flush() throws IOException {
while (true) {
@@ -317,8 +331,8 @@ public void flush() throws IOException {
*
* @throws StitchException if Stitch rejected or was unable to
* process the message
- * @throws IOException if there was an error communicating with
- * Stitch
+ * @throws IOException if there was an error communicating with
+ * Stitch
*/
public void close() throws IOException {
flush();
diff --git a/src/main/java/com/stitchdata/client/StitchClientBuilder.java b/src/main/java/de/spendit/stitchdata/client/StitchClientBuilder.java
similarity index 86%
rename from src/main/java/com/stitchdata/client/StitchClientBuilder.java
rename to src/main/java/de/spendit/stitchdata/client/StitchClientBuilder.java
index 46c030b..49e837b 100644
--- a/src/main/java/com/stitchdata/client/StitchClientBuilder.java
+++ b/src/main/java/de/spendit/stitchdata/client/StitchClientBuilder.java
@@ -1,41 +1,17 @@
-package com.stitchdata.client;
+package de.spendit.stitchdata.client;
+
+import com.cognitect.transit.WriteHandler;
-import java.io.ByteArrayOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.UnsupportedEncodingException;
-import java.io.BufferedReader;
-import java.io.Closeable;
-import java.io.InputStreamReader;
-import java.io.IOException;
-import java.util.Collection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
-import java.util.HashMap;
-import java.util.concurrent.ArrayBlockingQueue;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.CountDownLatch;
-import com.cognitect.transit.Writer;
-import com.cognitect.transit.WriteHandler;
-import com.cognitect.transit.TransitFactory;
-import com.cognitect.transit.Reader;
-import org.apache.http.client.fluent.Request;
-import org.apache.http.client.fluent.Response;
-import org.apache.http.client.ClientProtocolException;
-import org.apache.http.entity.ContentType;
-import org.apache.http.StatusLine;
-import org.apache.http.HttpResponse;
-import org.apache.http.HttpEntity;
-
-import javax.json.Json;
-import javax.json.JsonReader;
/**
* Use this to build instances of StitchClient.
*
* Basic usage
- *
+ *
* Every client must have a client id, access token, and
* namespace. You should have gotten these parameters when you set up
* the integration at http://stitchdata.com. You must set them with
@@ -53,7 +29,7 @@
*
*
*
Optionally set message defaults
- *
+ *
* If your application will send messages into only one table, you can
* set the table name and key names here with {@link
* #withTableName(String)} and {@link #withKeyNames(List)}, {@link
@@ -75,7 +51,7 @@
*
*
*
Optionally tune batch parameters
- *
+ *
* A StitchClient takes records (instances of {@link StitchMessage})
* and submits them to Stitch in batches. A call to {@link
* StitchClient#push(StitchMessage)} adds a record to the current
@@ -133,7 +109,8 @@ public class StitchClientBuilder {
private int batchDelayMillis = DEFAULT_BATCH_DELAY_MILLIS;
private FlushHandler flushHandler = null;
private String pushUrl = StitchClient.PUSH_URL;
- private Map> writeHandlers = null;
+ private Map> writeHandlers = null;
+
/**
* Specify your Stitch client id. This is a required setting.
*
@@ -219,7 +196,7 @@ public StitchClientBuilder withKeyNames(String... keyNames) {
* key name here. Otherwise, you can set it individually on each
* message with {@link StitchMessage#withKeyNames}.
*
- * @param keyName key names
+ * @param keyName key names
* @return this object
*/
public StitchClientBuilder withKeyName(String keyName) {
@@ -277,7 +254,7 @@ public StitchClientBuilder withPushUrl(String pushUrl) {
* @param writeHandlers the write handlers
* @return this object
*/
- public StitchClientBuilder withWriteHandlers(Map> writeHandlers) {
+ public StitchClientBuilder withWriteHandlers(Map> writeHandlers) {
this.writeHandlers = writeHandlers;
return this;
}
@@ -289,11 +266,11 @@ public StitchClientBuilder withWriteHandlers(Map> writeH
*/
public StitchClient build() {
return new StitchClient(
- pushUrl, clientId, token, namespace,
- tableName, keyNames,
- batchSizeBytes,
- batchDelayMillis,
- flushHandler,
- writeHandlers);
+ pushUrl, clientId, token, namespace,
+ tableName, keyNames,
+ batchSizeBytes,
+ batchDelayMillis,
+ flushHandler,
+ writeHandlers);
}
}
diff --git a/src/main/java/com/stitchdata/client/StitchException.java b/src/main/java/de/spendit/stitchdata/client/StitchException.java
similarity index 94%
rename from src/main/java/com/stitchdata/client/StitchException.java
rename to src/main/java/de/spendit/stitchdata/client/StitchException.java
index 471041b..538f7dc 100644
--- a/src/main/java/com/stitchdata/client/StitchException.java
+++ b/src/main/java/de/spendit/stitchdata/client/StitchException.java
@@ -1,4 +1,4 @@
-package com.stitchdata.client;
+package de.spendit.stitchdata.client;
import java.io.IOException;
diff --git a/src/main/java/com/stitchdata/client/StitchMessage.java b/src/main/java/de/spendit/stitchdata/client/StitchMessage.java
similarity index 99%
rename from src/main/java/com/stitchdata/client/StitchMessage.java
rename to src/main/java/de/spendit/stitchdata/client/StitchMessage.java
index de1d488..a5084a8 100644
--- a/src/main/java/com/stitchdata/client/StitchMessage.java
+++ b/src/main/java/de/spendit/stitchdata/client/StitchMessage.java
@@ -1,4 +1,4 @@
-package com.stitchdata.client;
+package de.spendit.stitchdata.client;
import java.util.Arrays;
import java.util.List;
diff --git a/src/main/java/com/stitchdata/client/StitchResponse.java b/src/main/java/de/spendit/stitchdata/client/StitchResponse.java
similarity index 91%
rename from src/main/java/com/stitchdata/client/StitchResponse.java
rename to src/main/java/de/spendit/stitchdata/client/StitchResponse.java
index 0d287c7..654cacd 100644
--- a/src/main/java/com/stitchdata/client/StitchResponse.java
+++ b/src/main/java/de/spendit/stitchdata/client/StitchResponse.java
@@ -1,7 +1,7 @@
-package com.stitchdata.client;
-import javax.json.JsonReader;
-import javax.json.Json;
-import javax.json.JsonObject;
+package de.spendit.stitchdata.client;
+
+
+import jakarta.json.JsonObject;
/**
* Encapsulates a response received from Stitch.
diff --git a/src/test/java/com/stitchdata/client/BufferTest.java b/src/test/java/de/spendit/stitchdata/client/BufferTest.java
similarity index 89%
rename from src/test/java/com/stitchdata/client/BufferTest.java
rename to src/test/java/de/spendit/stitchdata/client/BufferTest.java
index 84f81c2..7451597 100644
--- a/src/test/java/com/stitchdata/client/BufferTest.java
+++ b/src/test/java/de/spendit/stitchdata/client/BufferTest.java
@@ -1,20 +1,22 @@
-package com.stitchdata.client;
+package de.spendit.stitchdata.client;
+import com.cognitect.transit.TransitFactory;
+import com.cognitect.transit.Writer;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
-import java.io.ByteArrayOutputStream;
-import com.cognitect.transit.Writer;
-import com.cognitect.transit.WriteHandler;
-import com.cognitect.transit.TransitFactory;
-import com.cognitect.transit.Reader;
import java.util.Arrays;
-import java.util.List;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
-import org.junit.*;
+
import static org.junit.Assert.*;
-public class BufferTest {
+public class BufferTest {
static final Map tinyRecord = new HashMap();
static final Map bigRecord = new HashMap();
@@ -50,7 +52,7 @@ public void putMessage(Map record) {
}
public String takeBatchBody(int batchSizeBytes, int batchDelayMillis)
- throws UnsupportedEncodingException {
+ throws UnsupportedEncodingException {
List entries = buffer.take(batchSizeBytes, batchDelayMillis);
return entries == null ? null : StitchClient.serializeEntries(entries);
}
@@ -69,8 +71,8 @@ public void testWithholdUntilBytesAvailable() throws IOException {
assertNull(takeBatchBody(36, Integer.MAX_VALUE));
putMessage(tinyRecord);
assertEquals(
- "[" + tinyResult + "," + tinyResult + "," + tinyResult + "]",
- takeBatchBody(36, Integer.MAX_VALUE));
+ "[" + tinyResult + "," + tinyResult + "," + tinyResult + "]",
+ takeBatchBody(36, Integer.MAX_VALUE));
}
@Test
@@ -99,7 +101,7 @@ public void testDoesNotExceedMaxBatchSize() throws IOException {
assertNull(batch3);
}
- @Test(expected=IllegalArgumentException.class)
+ @Test(expected = IllegalArgumentException.class)
public void assertCantPutRecordLargerThanMaxMessageSize() {
putMessage(hugeRecord);
}
diff --git a/src/test/java/de/spendit/stitchdata/client/CallbackExampleTest.java b/src/test/java/de/spendit/stitchdata/client/CallbackExampleTest.java
new file mode 100644
index 0000000..9e5cf46
--- /dev/null
+++ b/src/test/java/de/spendit/stitchdata/client/CallbackExampleTest.java
@@ -0,0 +1,87 @@
+package de.spendit.stitchdata.client;
+
+import com.cognitect.transit.Reader;
+import com.cognitect.transit.TransitFactory;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.*;
+
+import static org.junit.Assert.assertEquals;
+
+public class CallbackExampleTest {
+
+ private static Map makePerson(int id, String name) {
+ Map result = new HashMap();
+ result.put("id", id);
+ result.put("name", name);
+ return result;
+ }
+
+ private static class CollectingFlushHandler implements FlushHandler {
+ final List names = new ArrayList();
+
+ public void onFlush(List arg) {
+ names.addAll(arg);
+ }
+ }
+
+ private static class DummyStitchClient extends StitchClient {
+ final List