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

org.xnio.FinishedIoFuture Maven / Gradle / Ivy

There is a newer version: 62
Show newest version

package org.xnio;

import java.io.IOException;
import java.util.concurrent.CancellationException;
import java.util.concurrent.TimeUnit;

import static org.xnio.IoFuture.Status.DONE;

/**
 * An implementation of {@link IoFuture} that represents an immediately-successful operation.
 *
 * @param  the type of result that this operation produces
 */
public class FinishedIoFuture implements IoFuture {

    private final T result;

    /**
     * Create an instance.
     *
     * @param result the operation result
     */
    public FinishedIoFuture(T result) {
        this.result = result;
    }

    /**
     * Cancel the operation.  Since this operation is always complete, this is a no-op.
     *
     * @return this instance
     */
    public IoFuture cancel() {
        return this;
    }

    @Override
    public Status getStatus() {
        return DONE;
    }

    @Override
    public Status await() {
        return DONE;
    }

    @Override
    public Status await(final long time, final TimeUnit timeUnit) {
        return DONE;
    }

    @Override
    public Status awaitInterruptibly() throws InterruptedException {
        return DONE;
    }

    @Override
    public Status awaitInterruptibly(final long time, final TimeUnit timeUnit) throws InterruptedException {
        return DONE;
    }

    @Override
    public T get() throws IOException, CancellationException {
        return result;
    }

    @Override
    public T getInterruptibly() throws IOException, InterruptedException, CancellationException {
        return result;
    }

    @Override
    public IOException getException() throws IllegalStateException {
        throw new IllegalStateException();
    }

    @Override
    public  IoFuture addNotifier(final Notifier notifier, final A attachment) {
        notifier.notify(this, attachment);
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy