Search in sources :

Example 21 with Cache

use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.

the class DatafileRescheduler method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    if ((context != null && intent != null) && (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) || intent.getAction().equals(Intent.ACTION_MY_PACKAGE_REPLACED))) {
        logger.info("Received intent with action {}", intent.getAction());
        BackgroundWatchersCache backgroundWatchersCache = new BackgroundWatchersCache(new Cache(context, LoggerFactory.getLogger(Cache.class)), LoggerFactory.getLogger(BackgroundWatchersCache.class));
        Dispatcher dispatcher = new Dispatcher(context, backgroundWatchersCache, LoggerFactory.getLogger(Dispatcher.class));
        dispatcher.dispatch();
    } else {
        logger.warn("Received invalid broadcast to data file rescheduler");
    }
}
Also used : Cache(com.optimizely.ab.android.shared.Cache)

Example 22 with Cache

use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.

the class DefaultDatafileHandler method enableBackgroundCache.

private void enableBackgroundCache(Context context, DatafileConfig datafileConfig) {
    BackgroundWatchersCache backgroundWatchersCache = new BackgroundWatchersCache(new Cache(context, LoggerFactory.getLogger(Cache.class)), LoggerFactory.getLogger(BackgroundWatchersCache.class));
    backgroundWatchersCache.setIsWatching(datafileConfig, true);
}
Also used : Cache(com.optimizely.ab.android.shared.Cache)

Example 23 with Cache

use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.

the class DefaultDatafileHandler method loadSavedDatafile.

/**
 * Load a cached datafile if it exists.
 *
 * @param context   application context
 * @param datafileConfig DatafileConfig for the datafile
 * @return the datafile cached or null if it was not available
 */
public String loadSavedDatafile(Context context, DatafileConfig datafileConfig) {
    DatafileCache datafileCache = new DatafileCache(datafileConfig.getKey(), new Cache(context, LoggerFactory.getLogger(Cache.class)), LoggerFactory.getLogger(DatafileCache.class));
    JSONObject datafile = datafileCache.load();
    if (datafile != null) {
        return datafile.toString();
    }
    return null;
}
Also used : JSONObject(org.json.JSONObject) Cache(com.optimizely.ab.android.shared.Cache)

Example 24 with Cache

use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.

the class DefaultDatafileHandler method clearBackgroundCache.

private void clearBackgroundCache(Context context, DatafileConfig projectId) {
    BackgroundWatchersCache backgroundWatchersCache = new BackgroundWatchersCache(new Cache(context, LoggerFactory.getLogger(Cache.class)), LoggerFactory.getLogger(BackgroundWatchersCache.class));
    backgroundWatchersCache.setIsWatching(projectId, false);
}
Also used : Cache(com.optimizely.ab.android.shared.Cache)

Example 25 with Cache

use of com.optimizely.ab.android.shared.Cache in project android-sdk by optimizely.

the class DefaultDatafileHandler method downloadDatafile.

/**
 * Asynchronous download data file.
 * <p>
 * We create a DatafileService intent, create a DataService connection, and bind it to the application context.
 * After we receive the datafile, we unbind the service and cleanup the service connection.
 * This gets the project file from the Optimizely CDN.
 *
 * @param context   application context
 * @param datafileConfig DatafileConfig for the datafile to get
 * @param listener  listener to call when datafile download complete
 */
public void downloadDatafile(final Context context, DatafileConfig datafileConfig, final DatafileLoadedListener listener) {
    DatafileClient datafileClient = new DatafileClient(new Client(new OptlyStorage(context.getApplicationContext()), LoggerFactory.getLogger(OptlyStorage.class)), LoggerFactory.getLogger(DatafileClient.class));
    DatafileCache datafileCache = new DatafileCache(datafileConfig.getKey(), new Cache(context, LoggerFactory.getLogger(Cache.class)), LoggerFactory.getLogger(DatafileCache.class));
    String datafileUrl = datafileConfig.getUrl();
    DatafileLoader datafileLoader = new DatafileLoader(context, datafileClient, datafileCache, LoggerFactory.getLogger(DatafileLoader.class));
    datafileLoader.getDatafile(datafileUrl, new DatafileLoadedListener() {

        @Override
        public void onDatafileLoaded(@Nullable String dataFile) {
            if (listener != null) {
                listener.onDatafileLoaded(dataFile);
            }
        }
    });
}
Also used : OptlyStorage(com.optimizely.ab.android.shared.OptlyStorage) Client(com.optimizely.ab.android.shared.Client) Cache(com.optimizely.ab.android.shared.Cache)

Aggregations

Cache (com.optimizely.ab.android.shared.Cache)28 Test (org.junit.Test)10 Logger (org.slf4j.Logger)9 Before (org.junit.Before)8 DatafileConfig (com.optimizely.ab.android.shared.DatafileConfig)6 Client (com.optimizely.ab.android.shared.Client)5 ExecutorService (java.util.concurrent.ExecutorService)5 Context (android.content.Context)3 OptlyStorage (com.optimizely.ab.android.shared.OptlyStorage)3 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 JSONObject (org.json.JSONObject)3 SdkSuppress (androidx.test.filters.SdkSuppress)2 JSONException (org.json.JSONException)2 Intent (android.content.Intent)1 FileObserver (android.os.FileObserver)1 IBinder (android.os.IBinder)1 NonNull (androidx.annotation.NonNull)1 ListenableWorker (androidx.work.ListenableWorker)1 File (java.io.File)1