com.king.platform.net.http.netty.HttpCallbackInvoker Maven / Gradle / Ivy
package com.king.platform.net.http.netty;
import com.king.platform.net.http.HttpCallback;
import com.king.platform.net.http.HttpResponse;
import com.king.platform.net.http.netty.eventbus.Event1;
import com.king.platform.net.http.netty.eventbus.Event2;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
public class HttpCallbackInvoker {
private final AtomicBoolean firstExecute = new AtomicBoolean();
private final Executor callbackExecutor;
private final HttpCallback httpCallback;
public HttpCallbackInvoker(Executor callbackExecutor, HttpCallback httpCallback) {
this.callbackExecutor = callbackExecutor;
this.httpCallback = httpCallback;
}
public void onHttpResponseDone(HttpResponse httpResponse) {
if (firstExecute.compareAndSet(false, true)) {
callbackExecutor.execute(() -> httpCallback.onCompleted(httpResponse));
}
}
public void onError(HttpRequestContext httpRequestContext, Throwable throwable) {
if (firstExecute.compareAndSet(false, true)) {
callbackExecutor.execute(() -> httpCallback.onError(throwable));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy