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

com.huaweicloud.dis.http.AbstractCallbackAdapter Maven / Gradle / Ivy

The newest version!
package com.huaweicloud.dis.http;

import com.huaweicloud.dis.core.handler.AsyncHandler;

public abstract class AbstractCallbackAdapter implements AsyncHandler{
	private AsyncHandler innerAsyncHandler;
	
	protected AbstractFutureAdapter futureAdapter;
	
	public AbstractCallbackAdapter(AsyncHandler innerAsyncHandler) {
		this.innerAsyncHandler = innerAsyncHandler;
	}

	public AbstractCallbackAdapter(AsyncHandler innerAsyncHandler, AbstractFutureAdapter futureAdapter) {
		this.innerAsyncHandler = innerAsyncHandler;
		this.futureAdapter = futureAdapter;
	}
	
	@Override
	public void onError(Exception exception) throws Exception {
		innerAsyncHandler.onError(exception);
	}

	@Override
	public void onSuccess(InnerT result) throws Exception {
		T t = null;
		try {
			if(futureAdapter != null) {
				t = futureAdapter.getT(result);
			}else {
				t = toInnerT(result);
			}
		}catch(Exception e) {
			this.onError(e);
			return;
		}
		
		innerAsyncHandler.onSuccess(t);	
	}

	protected abstract T toInnerT(InnerT result);
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy