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);
}
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);
}
}
});
}
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);
}
Aggregations