Search in sources :

Example 1 with SyncQueriesStartedEvent

use of com.amplifyframework.datastore.events.SyncQueriesStartedEvent in project amplify-android by aws-amplify.

the class SyncProcessor method hydrate.

/**
 * The task of hydrating the DataStore either succeeds (with no return value),
 * or it fails, with an explanation.
 * @return An Rx {@link Completable} which can be used to perform the operation.
 */
Completable hydrate() {
    final List<Completable> hydrationTasks = new ArrayList<>();
    List<ModelSchema> modelSchemas = new ArrayList<>(modelProvider.modelSchemas().values());
    // And sort them all, according to their model's topological order,
    // So that when we save them, the references will exist.
    TopologicalOrdering ordering = TopologicalOrdering.forRegisteredModels(schemaRegistry, modelProvider);
    Collections.sort(modelSchemas, ordering::compare);
    for (ModelSchema schema : modelSchemas) {
        hydrationTasks.add(createHydrationTask(schema));
    }
    return Completable.concat(hydrationTasks).doOnSubscribe(ignore -> {
        // This is where we trigger the syncQueriesStarted event since
        // doOnSubscribe means that all upstream hydration tasks
        // have started.
        Amplify.Hub.publish(HubChannel.DATASTORE, HubEvent.create(DataStoreChannelEventName.SYNC_QUERIES_STARTED, new SyncQueriesStartedEvent(modelNames)));
    }).doOnComplete(() -> {
        // When the Completable completes, then emit syncQueriesReady.
        Amplify.Hub.publish(HubChannel.DATASTORE, HubEvent.create(DataStoreChannelEventName.SYNC_QUERIES_READY));
    });
}
Also used : DataStoreConfigurationProvider(com.amplifyframework.datastore.DataStoreConfigurationProvider) Single(io.reactivex.rxjava3.core.Single) DataStoreErrorHandler(com.amplifyframework.datastore.DataStoreErrorHandler) BehaviorProcessor(io.reactivex.rxjava3.processors.BehaviorProcessor) NonNull(androidx.annotation.NonNull) ModelWithMetadata(com.amplifyframework.datastore.appsync.ModelWithMetadata) GraphQLRequest(com.amplifyframework.api.graphql.GraphQLRequest) ModelProvider(com.amplifyframework.core.model.ModelProvider) DataStoreChannelEventName(com.amplifyframework.datastore.DataStoreChannelEventName) AppSync(com.amplifyframework.datastore.appsync.AppSync) SyncQueriesStartedEvent(com.amplifyframework.datastore.events.SyncQueriesStartedEvent) AtomicReference(java.util.concurrent.atomic.AtomicReference) ApiException(com.amplifyframework.api.ApiException) ArrayList(java.util.ArrayList) SchemaRegistry(com.amplifyframework.core.model.SchemaRegistry) Time(com.amplifyframework.util.Time) Schedulers(io.reactivex.rxjava3.schedulers.Schedulers) Consumer(com.amplifyframework.core.Consumer) ModelSchema(com.amplifyframework.core.model.ModelSchema) PaginatedResult(com.amplifyframework.api.graphql.PaginatedResult) QueryPredicate(com.amplifyframework.core.model.query.predicate.QueryPredicate) HubEvent(com.amplifyframework.hub.HubEvent) Amplify(com.amplifyframework.core.Amplify) Flowable(io.reactivex.rxjava3.core.Flowable) HubChannel(com.amplifyframework.hub.HubChannel) SerializedModel(com.amplifyframework.core.model.SerializedModel) Model(com.amplifyframework.core.model.Model) Completable(io.reactivex.rxjava3.core.Completable) Logger(com.amplifyframework.logging.Logger) Objects(java.util.Objects) DataStoreException(com.amplifyframework.datastore.DataStoreException) List(java.util.List) Cancelable(com.amplifyframework.core.async.Cancelable) AmplifyDisposables(com.amplifyframework.datastore.AmplifyDisposables) ForEach(com.amplifyframework.util.ForEach) Collections(java.util.Collections) ModelSchema(com.amplifyframework.core.model.ModelSchema) Completable(io.reactivex.rxjava3.core.Completable) ArrayList(java.util.ArrayList) SyncQueriesStartedEvent(com.amplifyframework.datastore.events.SyncQueriesStartedEvent)

Example 2 with SyncQueriesStartedEvent

use of com.amplifyframework.datastore.events.SyncQueriesStartedEvent in project amplify-android by aws-amplify.

the class HubEventDataObjectsTest method verifySyncQueriesStartedEvent.

/**
 * Verify {@link SyncQueriesStartedEvent} behavior.
 */
@Test
public void verifySyncQueriesStartedEvent() {
    SyncQueriesStartedEvent status1 = new SyncQueriesStartedEvent(new String[] { "Blog", "Post" });
    SyncQueriesStartedEvent status2 = new SyncQueriesStartedEvent(new String[] { "Blog", "Post", "Car" });
    SyncQueriesStartedEvent status3 = new SyncQueriesStartedEvent(new String[] { "Blog", "Post" });
    EqualsToStringHashValidator.validate(status1, status2, status3);
}
Also used : SyncQueriesStartedEvent(com.amplifyframework.datastore.events.SyncQueriesStartedEvent) Test(org.junit.Test)

Aggregations

SyncQueriesStartedEvent (com.amplifyframework.datastore.events.SyncQueriesStartedEvent)2 NonNull (androidx.annotation.NonNull)1 ApiException (com.amplifyframework.api.ApiException)1 GraphQLRequest (com.amplifyframework.api.graphql.GraphQLRequest)1 PaginatedResult (com.amplifyframework.api.graphql.PaginatedResult)1 Amplify (com.amplifyframework.core.Amplify)1 Consumer (com.amplifyframework.core.Consumer)1 Cancelable (com.amplifyframework.core.async.Cancelable)1 Model (com.amplifyframework.core.model.Model)1 ModelProvider (com.amplifyframework.core.model.ModelProvider)1 ModelSchema (com.amplifyframework.core.model.ModelSchema)1 SchemaRegistry (com.amplifyframework.core.model.SchemaRegistry)1 SerializedModel (com.amplifyframework.core.model.SerializedModel)1 QueryPredicate (com.amplifyframework.core.model.query.predicate.QueryPredicate)1 AmplifyDisposables (com.amplifyframework.datastore.AmplifyDisposables)1 DataStoreChannelEventName (com.amplifyframework.datastore.DataStoreChannelEventName)1 DataStoreConfigurationProvider (com.amplifyframework.datastore.DataStoreConfigurationProvider)1 DataStoreErrorHandler (com.amplifyframework.datastore.DataStoreErrorHandler)1 DataStoreException (com.amplifyframework.datastore.DataStoreException)1 AppSync (com.amplifyframework.datastore.appsync.AppSync)1