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

com.netflix.astyanax.cql.util.AsyncOperationResult Maven / Gradle / Ivy

package com.netflix.astyanax.cql.util;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.ResultSetFuture;
import com.google.common.util.concurrent.ListenableFuture;
import com.netflix.astyanax.connectionpool.OperationResult;

/**
 * Impl for istenableFuture> that wraps the {@link ResultSetFuture} from java driver for async operations. 
 * 
 * @author poberai
 *
 * @param 
 */
public abstract class AsyncOperationResult implements ListenableFuture> {

	private ResultSetFuture rsFuture; 

	public AsyncOperationResult(ResultSetFuture rsFuture) {
		this.rsFuture = rsFuture;
	}

	@Override
	public boolean cancel(boolean mayInterruptIfRunning) {
		return rsFuture.cancel(mayInterruptIfRunning);
	}

	@Override
	public boolean isCancelled() {
		return rsFuture.isCancelled();
	}

	@Override
	public boolean isDone() {
		return rsFuture.isDone();
	}

	@Override
	public OperationResult get() throws InterruptedException, ExecutionException {
		return getOperationResult(rsFuture.get());
	}

	public OperationResult getUninterruptably() throws InterruptedException, ExecutionException {
		return getOperationResult(rsFuture.getUninterruptibly());
	}

	@Override
	public OperationResult get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
		return getOperationResult(rsFuture.get(timeout, unit));
	}

	@Override
	public void addListener(Runnable listener, Executor executor) {
		rsFuture.addListener(listener, executor);
	}

	public abstract OperationResult getOperationResult(ResultSet rs);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy