All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.king.platform.net.http.netty.HttpCallbackInvoker Maven / Gradle / Ivy

There is a newer version: 3.0.26
Show newest version
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 onCompleted(HttpRequestContext httpRequestContext) {
		if (firstExecute.compareAndSet(false, true)) {
			callbackExecutor.execute(() -> httpCallback.onCompleted(httpRequestContext.getHttpResponse()));
		}
	}

	public void onError(HttpRequestContext httpRequestContext, Throwable throwable) {
		if (firstExecute.compareAndSet(false, true)) {
			callbackExecutor.execute(() -> httpCallback.onError(throwable));
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy