Moving synchronized block out of callback
@@ -139,14 +139,23 @@ public class LongPollingTransport extends HttpClientTransport {
request.content(new StringContentProvider(generateJSON(messages)));
- customize(request, Promise.from(customizedRequest -> {
synchronized (this) {
if (_aborted) {
throw new IllegalStateException("Aborted");
}
- _requests.add(customizedRequest);
+ _requests.add(request);
}
+ customize(request, Promise.from(
+ customizedRequest -> sendAfterCustomize(listener, messages, uri, customizedRequest),
+ error -> listener.onFailure(error, messages)
+ ));
+ }
+
+ private void sendAfterCustomize(TransportListener listener,
+ List<Message.Mutable> messages,
+ URI uri,
+ Request customizedRequest) {
customizedRequest.listener(new Request.Listener.Adapter() {
@Override
public void onHeaders(Request request) {
@@ -250,11 +259,6 @@ public class LongPollingTransport extends HttpClientTransport {
}
}
});
- }, error -> {
- listener.onFailure(error, messages);
- }));
-
-
}
protected void customize(Request request) {
