Skip to content

Commit 4d01cf8

Browse files
committed
Getting Java Tracker ready for release
1 parent f8ef01e commit 4d01cf8

20 files changed

Lines changed: 48 additions & 44 deletions

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ apply plugin: 'propdeps-idea'
3131

3232
group = 'com.snowplowanalytics'
3333
version = '0.8.0'
34-
sourceCompatibility = '1.6'
35-
targetCompatibility = '1.6'
34+
sourceCompatibility = '1.7'
35+
targetCompatibility = '1.7'
3636

3737
repositories {
3838
// Use 'maven central' for resolving our dependencies

src/main/java/com/snowplowanalytics/snowplow/tracker/Subject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*/
2525
public class Subject {
2626

27-
private HashMap<String, String> standardPairs = new HashMap<String, String>();
27+
private HashMap<String, String> standardPairs = new HashMap<>();
2828

2929
/**
3030
* Creates a Subject which will add extra data to each event.

src/main/java/com/snowplowanalytics/snowplow/tracker/Tracker.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ private void addTrackerPayload(TrackerPayload payload, List<SelfDescribingJson>
306306

307307
// Add subject if available
308308
if (eventSubject != null) {
309-
payload.addMap(new HashMap<String, String>(eventSubject.getSubject()));
309+
payload.addMap(new HashMap<>(eventSubject.getSubject()));
310310
} else if (this.subject != null) {
311-
payload.addMap(new HashMap<String, String>(this.subject.getSubject()));
311+
payload.addMap(new HashMap<>(this.subject.getSubject()));
312312
}
313313

314314
// Send the event!
@@ -323,7 +323,7 @@ private void addTrackerPayload(TrackerPayload payload, List<SelfDescribingJson>
323323
* many contexts inside
324324
*/
325325
private SelfDescribingJson getFinalContext(List<SelfDescribingJson> contexts) {
326-
List<Map> contextMaps = new LinkedList<Map>();
326+
List<Map> contextMaps = new LinkedList<>();
327327
for (SelfDescribingJson selfDescribingJson : contexts) {
328328
contextMaps.add(selfDescribingJson.getMap());
329329
}

src/main/java/com/snowplowanalytics/snowplow/tracker/emitter/AbstractEmitter.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public abstract class AbstractEmitter implements Emitter {
3434
protected HttpClientAdapter httpClientAdapter;
3535
protected RequestCallback requestCallback;
3636
protected ExecutorService executor;
37-
protected List<TrackerPayload> buffer = new ArrayList<TrackerPayload>();
37+
protected List<TrackerPayload> buffer = new ArrayList<>();
3838
protected int bufferSize = 1;
3939

4040
public static abstract class Builder<T extends Builder<T>> {
@@ -124,6 +124,13 @@ public void setBufferSize(int bufferSize) {
124124
this.bufferSize = bufferSize;
125125
}
126126

127+
/**
128+
* When the buffer limit is reached sending of the buffer is
129+
* initiated.
130+
*/
131+
@Override
132+
public abstract void flushBuffer();
133+
127134
/**
128135
* Gets the Emitter Buffer Size
129136
* - Will always be 1 for SimpleEmitter

src/main/java/com/snowplowanalytics/snowplow/tracker/emitter/BatchEmitter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ public synchronized void emit(TrackerPayload payload) {
9494
* When the buffer limit is reached sending of the buffer is
9595
* initiated.
9696
*/
97-
void flushBuffer() {
97+
public void flushBuffer() {
9898
execute(getRequestRunnable(buffer));
99-
buffer = new ArrayList<TrackerPayload>();
99+
buffer = new ArrayList<>();
100100
}
101101

102102
/**
@@ -146,7 +146,7 @@ public void run() {
146146
* @return the constructed POST payload
147147
*/
148148
private SelfDescribingJson getFinalPost(List<TrackerPayload> buffer) {
149-
List<Map> toSendPayloads = new ArrayList<Map>();
149+
List<Map> toSendPayloads = new ArrayList<>();
150150
for (TrackerPayload payload : buffer) {
151151
toSendPayloads.add(payload.getMap());
152152
}

src/main/java/com/snowplowanalytics/snowplow/tracker/emitter/Emitter.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public interface Emitter {
4040
*/
4141
void setBufferSize(int bufferSize);
4242

43+
/**
44+
* When the buffer limit is reached sending of the buffer is
45+
* initiated.
46+
*
47+
* This can be used to manually start sending.
48+
*/
49+
void flushBuffer();
50+
4351
/**
4452
* Gets the Emitter Buffer Size
4553
* - Will always be 1 for SimpleEmitter

src/main/java/com/snowplowanalytics/snowplow/tracker/emitter/SimpleEmitter.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ public void emit(TrackerPayload payload) {
6262
execute(getRequestRunnable(payload));
6363
}
6464

65+
/**
66+
* When the buffer limit is reached sending of the buffer is
67+
* initiated.
68+
*/
69+
public void flushBuffer() {
70+
// Do nothing!
71+
}
72+
6573
/**
6674
* Returns a Runnable GET Request operation
6775
*
@@ -88,7 +96,7 @@ public void run() {
8896
// Send the callback if available
8997
if (requestCallback != null) {
9098
if (failure != 0) {
91-
List<TrackerPayload> buffer = new ArrayList<TrackerPayload>();
99+
List<TrackerPayload> buffer = new ArrayList<>();
92100
buffer.add(payload);
93101
requestCallback.onFailure(success, buffer);
94102
} else {

src/main/java/com/snowplowanalytics/snowplow/tracker/events/AbstractEvent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public abstract class AbstractEvent implements Event {
4545

4646
public static abstract class Builder<T extends Builder<T>> {
4747

48-
private List<SelfDescribingJson> context = new LinkedList<SelfDescribingJson>();
48+
private List<SelfDescribingJson> context = new LinkedList<>();
4949
private long timestamp = System.currentTimeMillis();
5050
private String eventId = Utils.getEventId();
5151
private Subject subject = null;
@@ -127,7 +127,7 @@ protected AbstractEvent(Builder<?> builder) {
127127
*/
128128
@Override
129129
public List<SelfDescribingJson> getContext() {
130-
return new ArrayList<SelfDescribingJson>(this.context);
130+
return new ArrayList<>(this.context);
131131
}
132132

133133
/**

src/main/java/com/snowplowanalytics/snowplow/tracker/events/EcommerceTransaction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public T items(List<EcommerceTransactionItem> items) {
146146
* @return itself
147147
*/
148148
public T items(EcommerceTransactionItem... itemArgs) {
149-
List<EcommerceTransactionItem> items = new ArrayList<EcommerceTransactionItem>();
149+
List<EcommerceTransactionItem> items = new ArrayList<>();
150150
Collections.addAll(items, itemArgs);
151151
this.items = items;
152152
return self();

src/main/java/com/snowplowanalytics/snowplow/tracker/http/AbstractHttpClientAdapter.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,6 @@
1414

1515
// Java
1616
import java.util.Map;
17-
import java.util.Objects;
18-
19-
// SquareUp
20-
import com.squareup.okhttp.OkHttpClient;
21-
22-
// Apache
23-
import org.apache.http.impl.client.CloseableHttpClient;
2417

2518
// Google
2619
import com.google.common.base.Preconditions;

0 commit comments

Comments
 (0)