Search in sources :

Example 1 with AndroidCapabilities

use of io.realm.internal.android.AndroidCapabilities in project realm-java by realm.

the class RealmCache method doCreateRealmOrGetFromCacheAsync.

private synchronized <T extends BaseRealm> RealmAsyncTask doCreateRealmOrGetFromCacheAsync(RealmConfiguration configuration, BaseRealm.InstanceCallback<T> callback, Class<T> realmClass) {
    Capabilities capabilities = new AndroidCapabilities();
    capabilities.checkCanDeliverNotification(ASYNC_NOT_ALLOWED_MSG);
    // noinspection ConstantConditions
    if (callback == null) {
        throw new IllegalArgumentException(ASYNC_CALLBACK_NULL_MSG);
    }
    // If there is no Realm file it means that we need to sync the initial remote data in the worker thread.
    if (configuration.isSyncConfiguration() && !configuration.realmExists()) {
        pendingRealmFileCreation.add(configuration.getPath());
    }
    // Always create a Realm instance in the background thread even when there are instances existing on current
    // thread. This to ensure that onSuccess will always be called in the following event loop but not current one.
    CreateRealmRunnable<T> createRealmRunnable = new CreateRealmRunnable<T>(new AndroidRealmNotifier(null, capabilities), configuration, callback, realmClass);
    Future<?> future = BaseRealm.asyncTaskExecutor.submitTransaction(createRealmRunnable);
    createRealmRunnable.setFuture(future);
    // For Realms using Async Open on the server, we need to create the session right away
    // in order to interact with it in a imperative way, e.g. by attaching download progress
    // listeners
    ObjectServerFacade.getSyncFacadeIfPossible().createNativeSyncSession(configuration);
    return new RealmAsyncTaskImpl(future, BaseRealm.asyncTaskExecutor);
}
Also used : RealmAsyncTaskImpl(io.realm.internal.async.RealmAsyncTaskImpl) AndroidCapabilities(io.realm.internal.android.AndroidCapabilities) Capabilities(io.realm.internal.Capabilities) AndroidRealmNotifier(io.realm.internal.android.AndroidRealmNotifier) AndroidCapabilities(io.realm.internal.android.AndroidCapabilities)

Example 2 with AndroidCapabilities

use of io.realm.internal.android.AndroidCapabilities in project realm-java by realm.

the class RealmResultTaskImpl method getAsync.

@Override
public void getAsync(App.Callback<T> callback) {
    Util.checkNull(callback, "callback");
    Util.checkLooperThread("RealmResultTaskImpl can only run on looper threads.");
    RealmNotifier handler = new AndroidRealmNotifier(null, new AndroidCapabilities());
    pendingTask = service.submit(new Runnable() {

        @Override
        public void run() {
            try {
                postSuccess(handler, executor.run(), callback);
            } catch (AppException e) {
                postError(handler, e, callback);
            } catch (Throwable e) {
                postError(handler, new AppException(ErrorCode.UNKNOWN, "Unexpected error", e), callback);
            }
        }
    });
}
Also used : AppException(io.realm.mongodb.AppException) AndroidRealmNotifier(io.realm.internal.android.AndroidRealmNotifier) RealmNotifier(io.realm.internal.RealmNotifier) AndroidRealmNotifier(io.realm.internal.android.AndroidRealmNotifier) AndroidCapabilities(io.realm.internal.android.AndroidCapabilities)

Example 3 with AndroidCapabilities

use of io.realm.internal.android.AndroidCapabilities in project realm-java by realm.

the class Util method checkLooperThread.

public static void checkLooperThread(String errorMessage) {
    AndroidCapabilities capabilities = new AndroidCapabilities();
    capabilities.checkCanDeliverNotification(errorMessage);
}
Also used : AndroidCapabilities(io.realm.internal.android.AndroidCapabilities)

Aggregations

AndroidCapabilities (io.realm.internal.android.AndroidCapabilities)3 AndroidRealmNotifier (io.realm.internal.android.AndroidRealmNotifier)2 Capabilities (io.realm.internal.Capabilities)1 RealmNotifier (io.realm.internal.RealmNotifier)1 RealmAsyncTaskImpl (io.realm.internal.async.RealmAsyncTaskImpl)1 AppException (io.realm.mongodb.AppException)1