Android Open Source - task4java Task Completion Source






From Project

Back to project page task4java.

License

The source code is released under:

Apache License

If you think the Android project task4java listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 *  Copyright (c) 2014 Andree Hagelstein, Maik Schulze, Deutsche Telekom AG. All Rights Reserved.
 *  /*from w  w  w  .  j  ava  2s.  c o m*/
 *  Filename: TaskCompletionSource.java
 */
package com.task4java.util.concurrent;

/**
 * The {@code TaskCompletionSource} represents the producer side of a {@link Task}.
 *
 * @param <V> the value type
 */
public class TaskCompletionSource<V> {

    /** The _set callback. */
    private CallableValue<Void, V> _setCallback;
    
    /** The _exception callback. */
    private CallableValue<Void, Throwable> _exceptionCallback;
    
    /** The result value. */
    private V resultValue;
    
    /** The result throwable. */
    private Throwable resultThrowable;

    /**
     * Sets the result value of the attached {@link Task.}
     *
     * @param result the result
     */
    public void set(V result) {

        if (_setCallback != null)
        {
          _setCallback.call(result);
        }
        else
        {
          resultValue = result;
        }
    }

    /**
     * Sets the result of the attached {@link Task.}
     *
     * @param t the new exception
     */
    public void setException(Throwable t) {

        if (_exceptionCallback != null)
        {
          _exceptionCallback.call(t);
        }
        else
        {
          resultThrowable = t;
        }
    }

    /**
     * Sets the set callback.
     *
     * @param callback the callback
     */
    void setSetCallback(CallableValue<Void, V> callback)
    {
        _setCallback = callback;
        
        if (resultValue != null)
        {
          _setCallback.call(resultValue);
        }
    }

    /**
     * Sets the exception callback.
     *
     * @param callback the callback
     */
    void setExceptionCallback(CallableValue<Void, Throwable> callback)
    {
        _exceptionCallback = callback;
        
        if (resultThrowable != null)
        {
          _exceptionCallback.call(resultThrowable);
        }
    }
}




Java Source Code List

com.task4java.IndexedList.java
com.task4java.KeyValuePair.java
com.task4java.Stopwatch.java
com.task4java.StringUtils.java
com.task4java.Tuple.java
com.task4java.android.activity.ActivityUtils.java
com.task4java.android.activity.BaseActivity.java
com.task4java.android.annotation.Annotations.java
com.task4java.android.examples.App.java
com.task4java.android.examples.activity.AboutActivity.java
com.task4java.android.examples.activity.ExpandableListAdapter.java
com.task4java.android.examples.activity.MainActivity.java
com.task4java.android.examples.activity.WelcomeActivity.java
com.task4java.android.examples.backend.AndroidServiceClient.java
com.task4java.android.util.concurrent.ActivityExecutor.java
com.task4java.android.util.concurrent.HandlerExecutor.java
com.task4java.data.backend.IServiceClient.java
com.task4java.data.backend.ServiceClient.java
com.task4java.data.backend.model.MainMenuAnnotation.java
com.task4java.data.frontend.ApplicationClient.java
com.task4java.data.frontend.model.MainMenuItemGroupList.java
com.task4java.data.frontend.model.MainMenuItemGroup.java
com.task4java.data.frontend.model.MainMenuItem.java
com.task4java.http.HttpHeaders.java
com.task4java.http.HttpMimeTypes.java
com.task4java.http.HttpRequestMethods.java
com.task4java.http.HttpStatusCodes.java
com.task4java.http.client.HttpContent.java
com.task4java.http.client.HttpStringContent.java
com.task4java.http.client.IImageClient.java
com.task4java.http.client.IRestClient.java
com.task4java.http.client.ImageClientGingerbread.java
com.task4java.http.client.ImageClient.java
com.task4java.http.client.ImageResponse.java
com.task4java.http.client.RestClientGingerbread.java
com.task4java.http.client.RestClient.java
com.task4java.http.client.RestResponse.java
com.task4java.lang.reflect.ReflectionCache.java
com.task4java.net.URLBuilder.java
com.task4java.util.concurrent.CallableTask.java
com.task4java.util.concurrent.CallableValue2.java
com.task4java.util.concurrent.CallableValue.java
com.task4java.util.concurrent.ITaskStart.java
com.task4java.util.concurrent.ITask.java
com.task4java.util.concurrent.TaskCompletionSource.java
com.task4java.util.concurrent.TaskContinuationOptions.java
com.task4java.util.concurrent.TaskException.java
com.task4java.util.concurrent.TaskFactory.java
com.task4java.util.concurrent.TaskResultException.java
com.task4java.util.concurrent.TaskStartException.java
com.task4java.util.concurrent.Task.java
com.task4java.util.log.ConsoleLogger.java
com.task4java.util.log.ILog.java
com.task4java.util.log.Logger.java