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

com.citrix.sharefile.api.async.SFAsyncHelper Maven / Gradle / Ivy

package com.citrix.sharefile.api.async;


import com.citrix.sharefile.api.SFSdk;
import com.citrix.sharefile.api.exceptions.SFSDKException;
import com.citrix.sharefile.api.interfaces.ISFApiClient;
import com.citrix.sharefile.api.interfaces.ISFApiExecuteQuery;
import com.citrix.sharefile.api.interfaces.ISFApiResultCallback;
import com.citrix.sharefile.api.interfaces.ISFAsyncHelper;
import com.citrix.sharefile.api.interfaces.ISFQuery;


public class SFAsyncHelper implements ISFAsyncHelper
{
    private final ISFApiClient mApiClient;
    private final ISFQuery mQuery;
    private final ISFApiResultCallback mApiResultCallback;
    private ISFApiExecuteQuery mApiExecutor;
    private T mResult;
    private SFSDKException mException;

    public SFAsyncHelper(ISFApiClient apiClient, ISFQuery query, ISFApiResultCallback apiResultCallback)
    {
        this.mApiClient = apiClient;
        this.mQuery = query;
        this.mApiResultCallback = apiResultCallback;
    }

    @Override
    public T execute()
    {
        try
        {
            mApiExecutor = mApiClient.getExecutor(mQuery, mApiResultCallback, SFSdk.getReAuthHandler());
            mResult = mApiExecutor.executeBlockingQuery();
        }
        catch (SFSDKException e)
        {
            mException = e;
        }

        return mResult;
    }

    @Override
    public void onPostExecute()
    {
        if(mException !=null)
        {
            mApiResultCallback.onError(mException,mQuery);
            return;
        }

        mApiResultCallback.onSuccess(mResult);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy