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

pl.chilldev.commons.concurrent.FutureResponder Maven / Gradle / Ivy

The newest version!
/**
 * This file is part of the ChillDev-Commons.
 *
 * @license http://mit-license.org/ The MIT license
 * @author Rafał Wrzeszcz 
 * @copyright 2014 © by Rafał Wrzeszcz - Wrzasq.pl.
 * @version 0.0.1
 * @since 0.0.1
 * @category ChillDev-Commons
 * @subcategory Concurrent
 */

package pl.chilldev.commons.concurrent;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

/**
 * Generic future objects wrapper.
 *
 * @param  Any type that is expected to be return for your listener.
 * @version 0.0.1
 * @since 0.0.1
 */
public class FutureResponder implements Callable
{
    /**
     * Bound future.
     */
    protected FutureTask future;

    /**
     * Response to return.
     */
    protected ResponseType response;

    /**
     * Sets future to notify.
     *
     * @param future Target future.
     * @return Self instance.
     * @since 0.0.1
     */
    public FutureResponder setFuture(FutureTask future)
    {
        this.future = future;

        return this;
    }

    /**
     * Assigns response.
     *
     * @param response Response to return.
     * @return Self instance.
     * @since 0.0.1
     */
    public FutureResponder setResponse(ResponseType response)
    {
        this.response = response;
        this.future.run();

        return this;
    }

    /**
     * Returns previously-sasigned response.
     *
     * @return Pre-defined response.
     * @since 0.0.1
     */
    public ResponseType call()
    {
        return this.response;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy