@@ -37,18 +37,57 @@ private DataStoreHubEventFilters() {}
3737 * @return A filter that watches for publication of the provided model.
3838 */
3939 public static HubEventFilter publicationOf (String modelName , String modelId ) {
40+ return outboxEventOf (
41+ DataStoreChannelEventName .OUTBOX_MUTATION_PROCESSED ,
42+ modelName ,
43+ modelId
44+ );
45+ }
46+
47+ /**
48+ * Watches for enqueue (out of mutation queue) of a given model.
49+ * Creates a filter that catches events from the mutation processor.
50+ * Events will pass if they mention the provided model by its name and ID,
51+ * and state that it has successfully been enqueued off of the mutation queue.
52+ * @param modelName Model name, e.g. "Post"
53+ * @param modelId The ID of a model instance that might be published
54+ * @return A filter that watches for publication of the provided model.
55+ */
56+ public static HubEventFilter enqueueOf (String modelName , String modelId ) {
57+ return outboxEventOf (
58+ DataStoreChannelEventName .OUTBOX_MUTATION_ENQUEUED ,
59+ modelName ,
60+ modelId
61+ );
62+ }
63+
64+ /**
65+ * Watches for the passed event (out of mutation queue) of a given model.
66+ * Creates a filter that catches events from the mutation processor.
67+ * Events will pass if they mention the provided model by its name and ID,
68+ * and state that it has successfully received passed event type off of the mutation queue.
69+ * @param eventType Either OUTBOX_MUTATION_ENQUEUED or OUTBOX_MUTATION_PROCESSED
70+ * @param modelName Model name, e.g. "Post"
71+ * @param modelId The ID of a model instance that might be published
72+ * @return A filter that watches for publication of the provided model.
73+ */
74+ private static HubEventFilter outboxEventOf (
75+ DataStoreChannelEventName eventType ,
76+ String modelName ,
77+ String modelId
78+ ) {
4079 return event -> {
41- if (!DataStoreChannelEventName . OUTBOX_MUTATION_PROCESSED .toString ().equals (event .getName ())) {
80+ if (!eventType .toString ().equals (event .getName ())) {
4281 return false ;
4382 }
4483 if (!(event .getData () instanceof OutboxMutationEvent )) {
4584 return false ;
4685 }
4786 OutboxMutationEvent <? extends Model > outboxMutationEvent =
48- (OutboxMutationEvent <? extends Model >) event .getData ();
87+ (OutboxMutationEvent <? extends Model >) event .getData ();
4988
5089 return modelId .equals (outboxMutationEvent .getElement ().getModel ().getPrimaryKeyString ()) &&
51- modelName .equals (outboxMutationEvent .getModelName ());
90+ modelName .equals (outboxMutationEvent .getModelName ());
5291 };
5392 }
5493
0 commit comments