Skip to content

Commit 3a7f751

Browse files
fjtiradomatheusandre1
authored andcommitted
Review comments
Signed-off-by: Matheus André <matheusandr2@gmail.com>
1 parent 28cc938 commit 3a7f751

4 files changed

Lines changed: 11 additions & 25 deletions

File tree

impl/core/src/main/java/io/serverlessworkflow/impl/WorkflowMutableInstance.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,6 @@ public <T> T addMetadataIfAbsent(String key, Supplier<T> supplier) {
355355
return (T) additionalObjects.computeIfAbsent(key, k -> supplier.get());
356356
}
357357

358-
public Object computeCorrelationValue(String key, Object value) {
359-
return additionalObjects.computeIfAbsent(key, k -> value);
360-
}
361-
362358
@Override
363359
public <T> Optional<T> findMetadata(String key, Class<T> objectClass) {
364360
Object value = additionalObjects.get(key);

impl/core/src/main/java/io/serverlessworkflow/impl/events/AbstractTypeConsumer.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import io.serverlessworkflow.impl.WorkflowApplication;
2525
import io.serverlessworkflow.impl.WorkflowContext;
2626
import io.serverlessworkflow.impl.WorkflowModel;
27-
import io.serverlessworkflow.impl.WorkflowModelFactory;
2827
import java.util.AbstractCollection;
2928
import java.util.ArrayList;
3029
import java.util.Collection;
@@ -61,8 +60,7 @@ public TypeEventRegistrationBuilder listen(
6160
application.cloudEventPredicateFactory().build(application, properties);
6261
Collection<CloudEventPredicate> correlationPredicates =
6362
buildCorrelationPredicates(register.getCorrelate(), application);
64-
return new TypeEventRegistrationBuilder(
65-
type, cePredicate, correlationPredicates, application.modelFactory());
63+
return new TypeEventRegistrationBuilder(type, cePredicate, correlationPredicates);
6664
}
6765

6866
private Collection<CloudEventPredicate> buildCorrelationPredicates(
@@ -83,27 +81,21 @@ private Collection<CloudEventPredicate> buildCorrelationPredicates(
8381

8482
@Override
8583
public Collection<TypeEventRegistrationBuilder> listenToAll(WorkflowApplication application) {
86-
return List.of(
87-
new TypeEventRegistrationBuilder(null, null, List.of(), application.modelFactory()));
84+
return List.of(new TypeEventRegistrationBuilder(null, null, List.of()));
8885
}
8986

9087
private static class CloudEventConsumer extends AbstractCollection<TypeEventRegistration>
9188
implements Consumer<CloudEvent> {
92-
private final WorkflowModelFactory modelFactory;
9389
private Collection<TypeEventRegistration> registrations = new CopyOnWriteArrayList<>();
9490

95-
CloudEventConsumer(WorkflowModelFactory modelFactory) {
96-
this.modelFactory = modelFactory;
97-
}
98-
9991
@Override
10092
public void accept(CloudEvent ce) {
10193
logger.debug("Received cloud event {}", ce);
10294
for (TypeEventRegistration registration : registrations) {
103-
if (registration.predicate().test(ce, registration.workflow(), registration.task())) {
104-
if (!testCorrelation(ce, registration)) {
105-
continue;
106-
}
95+
boolean predicateMatch =
96+
registration.predicate() == null
97+
|| registration.predicate().test(ce, registration.workflow(), registration.task());
98+
if (predicateMatch && testCorrelation(ce, registration)) {
10799
registration.consumer().accept(ce);
108100
}
109101
}
@@ -118,7 +110,7 @@ private boolean testCorrelation(CloudEvent ce, TypeEventRegistration registratio
118110
for (CloudEventPredicate pred : predicates) {
119111
if (pred instanceof ModelAwareCloudEventPredicate ma) {
120112
if (eventModel == null) {
121-
eventModel = modelFactory.from(ce);
113+
eventModel = registration.workflow().definition().application().modelFactory().from(ce);
122114
}
123115
if (!ma.test(eventModel, registration.workflow(), registration.task())) {
124116
return false;
@@ -175,7 +167,7 @@ public TypeEventRegistration register(
175167
.computeIfAbsent(
176168
registration.type(),
177169
k -> {
178-
CloudEventConsumer consumer = new CloudEventConsumer(builder.modelFactory());
170+
CloudEventConsumer consumer = new CloudEventConsumer();
179171
register(k, consumer);
180172
return consumer;
181173
})

impl/core/src/main/java/io/serverlessworkflow/impl/events/CorrelationPredicate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public boolean test(WorkflowModel eventModel, WorkflowContext workflow, TaskCont
7575

7676
if (expectResolver == null) {
7777
String stateKey = correlationStateKey(task);
78-
Object firstValue = workflow.instance().computeCorrelationValue(stateKey, eventValue);
78+
Object firstValue = workflow.instance().addMetadataIfAbsent(stateKey, () -> eventValue);
7979
boolean result = Objects.equals(eventValue, firstValue);
8080
logger.debug(
8181
"Correlation no expect, eventValue='{}', firstValue='{}', match={}",

impl/core/src/main/java/io/serverlessworkflow/impl/events/TypeEventRegistrationBuilder.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,16 @@
1515
*/
1616
package io.serverlessworkflow.impl.events;
1717

18-
import io.serverlessworkflow.impl.WorkflowModelFactory;
1918
import java.util.Collection;
2019
import java.util.Collections;
2120

2221
public record TypeEventRegistrationBuilder(
2322
String type,
2423
CloudEventPredicate cePredicate,
25-
Collection<CloudEventPredicate> correlationPredicates,
26-
WorkflowModelFactory modelFactory)
24+
Collection<CloudEventPredicate> correlationPredicates)
2725
implements EventRegistrationBuilder {
2826

2927
public TypeEventRegistrationBuilder(String type, CloudEventPredicate cePredicate) {
30-
this(type, cePredicate, Collections.emptyList(), null);
28+
this(type, cePredicate, Collections.emptyList());
3129
}
3230
}

0 commit comments

Comments
 (0)