Search in sources :

Example 1 with HubEventFilter

use of com.amplifyframework.hub.HubEventFilter in project amplify-android by aws-amplify.

the class HubAccumulator method create.

/**
 * Creates a {@link HubAccumulator} that accumulates events arriving on a particular channel,
 * whose event name is the given enum value (as string). For example, the accumulator
 * created as below will match all events with name
 * {@link DataStoreChannelEventName#OUTBOX_MUTATION_PROCESSED}:
 *
 *   HubAccumulator.create(HubChannel.DATASTORE, DataStoreChannelEventName.PUBLISH_TO_CLOUD);
 *
 * @param channel Channel on which to listen for events
 * @param enumeratedEventName A enum value, the toString() of which is expected as the name of
 *                             a hub event. Only events with this name will be accumulated.
 * @param quantity Number of events to accumulate
 * @param <E> The type of enumeration
 * @return A HubAccumulator
 */
@NonNull
public static <E extends Enum<E>> HubAccumulator create(@NonNull HubChannel channel, @NonNull E enumeratedEventName, int quantity) {
    Objects.requireNonNull(channel);
    Objects.requireNonNull(enumeratedEventName);
    HubEventFilter filter = event -> enumeratedEventName.toString().equals(event.getName());
    return new HubAccumulator(channel, filter, quantity);
}
Also used : Amplify(com.amplifyframework.core.Amplify) HubChannel(com.amplifyframework.hub.HubChannel) Immutable(com.amplifyframework.util.Immutable) NonNull(androidx.annotation.NonNull) HubEventFilters(com.amplifyframework.hub.HubEventFilters) DataStoreChannelEventName(com.amplifyframework.datastore.DataStoreChannelEventName) AtomicReference(java.util.concurrent.atomic.AtomicReference) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) HubEventFilter(com.amplifyframework.hub.HubEventFilter) SubscriptionToken(com.amplifyframework.hub.SubscriptionToken) HubEvent(com.amplifyframework.hub.HubEvent) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) HubEventFilter(com.amplifyframework.hub.HubEventFilter) NonNull(androidx.annotation.NonNull)

Aggregations

NonNull (androidx.annotation.NonNull)1 Amplify (com.amplifyframework.core.Amplify)1 DataStoreChannelEventName (com.amplifyframework.datastore.DataStoreChannelEventName)1 HubChannel (com.amplifyframework.hub.HubChannel)1 HubEvent (com.amplifyframework.hub.HubEvent)1 HubEventFilter (com.amplifyframework.hub.HubEventFilter)1 HubEventFilters (com.amplifyframework.hub.HubEventFilters)1 SubscriptionToken (com.amplifyframework.hub.SubscriptionToken)1 Immutable (com.amplifyframework.util.Immutable)1 List (java.util.List)1 Objects (java.util.Objects)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1