stalkr.http.ListenableRequestBuilder Maven / Gradle / Ivy
package stalkr.http;
import java.io.IOException;
import lombok.val;
import com.ning.http.client.AsyncHandler;
import com.ning.http.client.RequestBuilderBase;
import com.ning.http.client.Response;
public class ListenableRequestBuilder extends RequestBuilderBase {
final ContextualRequests requests;
public ListenableRequestBuilder( final ContextualRequests requests ) {
super( ListenableRequestBuilder.class, "GET", false );
this.requests = requests;
}
public ListenableRequestBuilder execute( final CompletionListener listener ) throws IOException {
return execute( new AsyncCompletionHandlerBase( listener ), listener );
}
public ListenableRequestBuilder execute( final AsyncHandler handler, final CompletionListener listener ) throws IOException {
val responseWrapper = new ResponseHolderAsyncHandlerWrapper( handler, requests.storedContext() );
val future = requests.client().executeRequest( build(), responseWrapper );
val completionListenerWrapper = new CompletionListenerWrapper( listener, future, requests );
future.addListener( completionListenerWrapper, requests.executor() );
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy