@@ -34,7 +34,7 @@ public final class DefaultEventSender implements EventSender {
34
34
* Default value for {@code retryDelayMillis} parameter.
35
35
*/
36
36
public static final long DEFAULT_RETRY_DELAY_MILLIS = 1000 ;
37
-
37
+
38
38
/**
39
39
* Default value for {@code analyticsRequestPath} parameter, for the server-side SDK.
40
40
* The Android SDK should modify this value.
@@ -46,7 +46,7 @@ public final class DefaultEventSender implements EventSender {
46
46
* The Android SDK should modify this value.
47
47
*/
48
48
public static final String DEFAULT_DIAGNOSTIC_REQUEST_PATH = "/diagnostic" ;
49
-
49
+
50
50
private static final String EVENT_SCHEMA_HEADER = "X-LaunchDarkly-Event-Schema" ;
51
51
private static final String EVENT_SCHEMA_VERSION = "4" ;
52
52
private static final String EVENT_PAYLOAD_ID_HEADER = "X-LaunchDarkly-Payload-ID" ;
@@ -65,7 +65,7 @@ public final class DefaultEventSender implements EventSender {
65
65
66
66
/**
67
67
* Creates an instance.
68
- *
68
+ *
69
69
* @param httpProperties the HTTP configuration
70
70
* @param analyticsRequestPath the request path for posting analytics events
71
71
* @param diagnosticRequestPath the request path for posting diagnostic events
@@ -91,20 +91,20 @@ public DefaultEventSender(
91
91
this .baseHeaders = httpProperties .toHeadersBuilder ()
92
92
.add ("Content-Type" , "application/json" )
93
93
.build ();
94
-
94
+
95
95
this .analyticsRequestPath = analyticsRequestPath == null ? DEFAULT_ANALYTICS_REQUEST_PATH : analyticsRequestPath ;
96
96
this .diagnosticRequestPath = diagnosticRequestPath == null ? DEFAULT_DIAGNOSTIC_REQUEST_PATH : diagnosticRequestPath ;
97
-
97
+
98
98
this .retryDelayMillis = retryDelayMillis <= 0 ? DEFAULT_RETRY_DELAY_MILLIS : retryDelayMillis ;
99
99
}
100
-
100
+
101
101
@ Override
102
102
public void close () throws IOException {
103
103
if (shouldCloseHttpClient ) {
104
104
HttpProperties .shutdownHttpClient (httpClient );
105
105
}
106
106
}
107
-
107
+
108
108
@ Override
109
109
public Result sendAnalyticsEvents (byte [] data , int eventCount , URI eventsBaseUri ) {
110
110
return sendEventData (false , data , eventCount , eventsBaseUri );
@@ -114,33 +114,33 @@ public Result sendAnalyticsEvents(byte[] data, int eventCount, URI eventsBaseUri
114
114
public Result sendDiagnosticEvent (byte [] data , URI eventsBaseUri ) {
115
115
return sendEventData (true , data , 1 , eventsBaseUri );
116
116
}
117
-
117
+
118
118
private Result sendEventData (boolean isDiagnostic , byte [] data , int eventCount , URI eventsBaseUri ) {
119
119
if (data == null || data .length == 0 ) {
120
120
// DefaultEventProcessor won't normally pass us an empty payload, but if it does, don't bother sending
121
121
return new Result (true , false , null );
122
122
}
123
-
123
+
124
124
Headers .Builder headersBuilder = baseHeaders .newBuilder ();
125
125
String path ;
126
126
String description ;
127
-
127
+
128
128
if (isDiagnostic ) {
129
129
path = diagnosticRequestPath ;
130
- description = "diagnostic event" ;
130
+ description = "diagnostic event" ;
131
131
} else {
132
132
path = analyticsRequestPath ;
133
133
String eventPayloadId = UUID .randomUUID ().toString ();
134
134
headersBuilder .add (EVENT_PAYLOAD_ID_HEADER , eventPayloadId );
135
135
headersBuilder .add (EVENT_SCHEMA_HEADER , EVENT_SCHEMA_VERSION );
136
136
description = String .format ("%d event(s)" , eventCount );
137
137
}
138
-
138
+
139
139
URI uri = HttpHelpers .concatenateUriPath (eventsBaseUri , path );
140
140
Headers headers = headersBuilder .build ();
141
141
RequestBody body = RequestBody .create (data , JSON_CONTENT_TYPE );
142
142
boolean mustShutDown = false ;
143
-
143
+
144
144
logger .debug ("Posting {} to {} with payload: {}" , description , uri ,
145
145
LogValues .defer (new LazilyPrintedUtf8Data (data )));
146
146
@@ -162,15 +162,15 @@ private Result sendEventData(boolean isDiagnostic, byte[] data, int eventCount,
162
162
long startTime = System .currentTimeMillis ();
163
163
String nextActionMessage = attempt == 0 ? "will retry" : "some events were dropped" ;
164
164
String errorContext = "posting " + description ;
165
-
165
+
166
166
try (Response response = httpClient .newCall (request ).execute ()) {
167
167
long endTime = System .currentTimeMillis ();
168
168
logger .debug ("{} delivery took {} ms, response status {}" , description , endTime - startTime , response .code ());
169
-
169
+
170
170
if (response .isSuccessful ()) {
171
171
return new Result (true , false , parseResponseDate (response ));
172
172
}
173
-
173
+
174
174
String errorDesc = httpErrorDescription (response .code ());
175
175
boolean recoverable = checkIfErrorIsRecoverableAndLog (
176
176
logger ,
@@ -187,10 +187,10 @@ private Result sendEventData(boolean isDiagnostic, byte[] data, int eventCount,
187
187
checkIfErrorIsRecoverableAndLog (logger , e .toString (), errorContext , 0 , nextActionMessage );
188
188
}
189
189
}
190
-
190
+
191
191
return new Result (false , mustShutDown , null );
192
192
}
193
-
193
+
194
194
private final Date parseResponseDate (Response response ) {
195
195
String dateStr = response .header ("Date" );
196
196
if (dateStr != null ) {
@@ -205,10 +205,10 @@ private final Date parseResponseDate(Response response) {
205
205
}
206
206
return null ;
207
207
}
208
-
208
+
209
209
private final class LazilyPrintedUtf8Data implements LogValues .StringProvider {
210
210
private final byte [] data ;
211
-
211
+
212
212
LazilyPrintedUtf8Data (byte [] data ) {
213
213
this .data = data ;
214
214
}
0 commit comments