Skip to content

Commit 2882bd5

Browse files
handleded async callbacks and imports
1 parent 18b6714 commit 2882bd5

File tree

5 files changed

+19
-9
lines changed

5 files changed

+19
-9
lines changed

examples/src/main/java/examples/basic/BasicAsync.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.socketLabs.injectionApi.message.BasicMessage;
99
import com.socketLabs.injectionApi.message.EmailAddress;
1010
import examples.*;
11+
import okhttp3.Call;
1112

1213
import java.io.IOException;
1314

examples/src/main/java/examples/basic/BasicSendWithRetry.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
package examples.basic;
22

3+
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import com.fasterxml.jackson.databind.SerializationFeature;
35
import com.socketLabs.injectionApi.SendResponse;
46
import com.socketLabs.injectionApi.SocketLabsClient;
7+
import com.socketLabs.injectionApi.core.SendAsyncCallback;
58
import com.socketLabs.injectionApi.message.BasicMessage;
69
import com.socketLabs.injectionApi.message.EmailAddress;
710
import examples.Example;
811
import examples.ExampleConfig;
912

13+
import java.io.IOException;
1014
import java.net.InetSocketAddress;
1115
import java.net.Proxy;
1216

injectionApi/src/main/java/com/socketLabs/injectionApi/SocketLabsClient.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22

33
import com.socketLabs.injectionApi.core.*;
44
import com.socketLabs.injectionApi.core.serialization.InjectionRequestFactory;
5+
import com.socketLabs.injectionApi.core.serialization.InjectionResponseParser;
56
import com.socketLabs.injectionApi.message.*;
67

8+
import java.io.IOException;
79
import java.net.Proxy;
10+
import okhttp3.Call;
11+
import okhttp3.Callback;
12+
import okhttp3.Response;
813

914
/**
1015
* SocketLabsClient is a wrapper for the SocketLabs Injection API that makes it easy to send messages and parse responses.
@@ -133,11 +138,11 @@ public void sendAsync(BasicMessage message, final SendAsyncCallback callback) th
133138

134139
retryHandler.sendAsync(new Callback() {
135140
public void onResponse(Call call, Response response) throws IOException {
136-
callback.onResponse(call, parser.Parse(response));
141+
callback.onResponse(parser.Parse(response));
137142
}
138143

139144
public void onFailure(Call call, IOException ex) {
140-
callback.onFailure(call, ex);
145+
callback.onError(ex);
141146
}
142147
});
143148

@@ -166,11 +171,11 @@ public void sendAsync(BulkMessage message, final SendAsyncCallback callback) thr
166171

167172
retryHandler.sendAsync(new Callback() {
168173
public void onResponse(Call call, Response response) throws IOException {
169-
callback.onResponse(call, parser.Parse(response));
174+
callback.onResponse(parser.Parse(response));
170175
}
171176

172177
public void onFailure(Call call, IOException ex) {
173-
callback.onFailure(call, ex);
178+
callback.onError(ex);
174179
}
175180
});
176181

injectionApi/src/main/java/com/socketLabs/injectionApi/core/RetryHandler.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.socketLabs.injectionApi.core;
22

33
import com.socketLabs.injectionApi.RetrySettings;
4-
import com.socketLabs.injectionApi.SendResponse;
54

65
import com.socketLabs.injectionApi.core.serialization.InjectionResponseParser;
76
import okhttp3.Call;
@@ -42,7 +41,7 @@ public RetryHandler(HttpRequest request, String endpointUrl, RetrySettings setti
4241
retrySettings = settings;
4342
}
4443

45-
public SendResponse send() throws IOException, InterruptedException {
44+
public Response send() throws IOException, InterruptedException {
4645

4746
if (retrySettings.getMaximumNumberOfRetries() == 0) {
4847
Response response = httpRequest.SendRequest();
@@ -84,7 +83,7 @@ public SendResponse send() throws IOException, InterruptedException {
8483

8584
}
8685

87-
public void sendAsync (final SendAsyncCallback callback) throws IOException, InterruptedException{
86+
public void sendAsync (final Callback callback) throws IOException, InterruptedException{
8887

8988
InjectionResponseParser parser = new InjectionResponseParser();
9089
Duration waitInterval = retrySettings.getNextWaitInterval(attempts);
@@ -109,7 +108,7 @@ public void onResponse(Call call, Response response) throws IOException {
109108
}
110109

111110
else {
112-
callback.onResponse(response);
111+
callback.onResponse(call, response);
113112
}
114113

115114
}
@@ -137,7 +136,7 @@ public void onFailure(Call call, IOException exception) {
137136
}
138137
else {
139138
attempts = retrySettings.getMaximumNumberOfRetries() + 1;
140-
callback.onError(exception);
139+
callback.onFailure(call, exception);
141140
}
142141

143142
}

injectionApi/src/main/java/com/socketLabs/injectionApi/core/SendAsyncCallback.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.socketLabs.injectionApi.core;
22

33
import com.socketLabs.injectionApi.SendResponse;
4+
import okhttp3.Call;
45

56
import java.io.IOException;
67

0 commit comments

Comments
 (0)