6
6
import java .util .concurrent .ExecutorService ;
7
7
8
8
public class Amplitude {
9
- private static Map <String , Amplitude > instances = new HashMap <>();
9
+ private final static Map <String , Amplitude > instances = new HashMap <>();
10
10
private final String instanceName ;
11
11
private String apiKey ;
12
12
private String serverUrl ;
13
13
14
- private AmplitudeLog logger ;
14
+ private AmplitudeLog logger = new AmplitudeLog () ;
15
15
16
- private Queue <Event > eventsToSend ;
17
- private boolean aboutToStartFlushing ;
16
+ private final Queue <Event > eventsToSend = new ConcurrentLinkedQueue <>() ;
17
+ private boolean aboutToStartFlushing = false ;
18
18
19
19
private HttpCallMode httpCallMode ;
20
- private HttpCall httpCall ;
21
- private HttpTransport httpTransport ;
20
+ private final HttpTransport httpTransport ;
22
21
private int eventUploadThreshold = Constants .EVENT_BUF_COUNT ;
23
22
private int eventUploadPeriodMillis = Constants .EVENT_BUF_TIME_MILLIS ;
24
- private Object eventQueueLock = new Object ();
23
+ private final Object eventQueueLock = new Object ();
25
24
private Plan plan ;
26
25
private IngestionMetadata ingestionMetadata ;
27
- private long flushTimeout ;
28
- private ExecutorService retryThreadPool ;
29
- private ExecutorService sendThreadPool ;
30
26
31
27
/**
32
28
* A dictionary of key-value pairs that represent additional instructions for server save
@@ -46,10 +42,7 @@ public class Amplitude {
46
42
*/
47
43
private Amplitude (String name ) {
48
44
instanceName = name ;
49
- logger = new AmplitudeLog ();
50
- eventsToSend = new ConcurrentLinkedQueue <>();
51
- aboutToStartFlushing = false ;
52
- httpTransport = new HttpTransport (httpCall , null , logger , flushTimeout , sendThreadPool , retryThreadPool );
45
+ httpTransport = new HttpTransport (logger );
53
46
}
54
47
55
48
/**
@@ -204,7 +197,6 @@ public Amplitude setLogger(AmplitudeLog logger) {
204
197
* @param timeout the flush events threads timeout millis
205
198
*/
206
199
public Amplitude setFlushTimeout (long timeout ) {
207
- flushTimeout = timeout ;
208
200
this .httpTransport .setFlushTimeout (timeout );
209
201
return this ;
210
202
}
@@ -215,7 +207,6 @@ public Amplitude setFlushTimeout(long timeout) {
215
207
* @param sendThreadPool the thread pool for sending events
216
208
*/
217
209
public Amplitude setSendThreadPool (ExecutorService sendThreadPool ) {
218
- this .sendThreadPool = sendThreadPool ;
219
210
this .httpTransport .setSendThreadPool (sendThreadPool );
220
211
return this ;
221
212
}
@@ -226,7 +217,6 @@ public Amplitude setSendThreadPool(ExecutorService sendThreadPool) {
226
217
* @param retryThreadPool the thread pool for retrying events
227
218
*/
228
219
public Amplitude setRetryThreadPool (ExecutorService retryThreadPool ) {
229
- this .retryThreadPool = retryThreadPool ;
230
220
this .httpTransport .setRetryThreadPool (retryThreadPool );
231
221
return this ;
232
222
}
@@ -356,14 +346,13 @@ private void updateHttpCall(HttpCallMode updatedHttpCallMode) {
356
346
httpCallMode = updatedHttpCallMode ;
357
347
358
348
if (updatedHttpCallMode == HttpCallMode .BATCH ) {
359
- httpCall =
349
+ httpTransport . setHttpCall (
360
350
new HttpCall (
361
- apiKey , serverUrl != null ? serverUrl : Constants .BATCH_API_URL , options , proxy );
351
+ apiKey , serverUrl != null ? serverUrl : Constants .BATCH_API_URL , options , proxy )) ;
362
352
} else {
363
- httpCall =
364
- new HttpCall (apiKey , serverUrl != null ? serverUrl : Constants .API_URL , options , proxy );
353
+ httpTransport . setHttpCall (
354
+ new HttpCall (apiKey , serverUrl != null ? serverUrl : Constants .API_URL , options , proxy )) ;
365
355
}
366
- httpTransport .setHttpCall (httpCall );
367
356
}
368
357
369
358
private synchronized void scheduleFlushEvents () {
0 commit comments