Skip to content

Commit

Permalink
[Fix #3628] Avoiding concurrency issues with Instance and ServiceLoad…
Browse files Browse the repository at this point in the history
…er (#3632)
  • Loading branch information
fjtirado authored Aug 22, 2024
1 parent 6c817b9 commit 2ff45a4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
*/
package org.kie.kogito.process.dynamic;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;

import org.drools.core.common.InternalKnowledgeRuntime;
import org.jbpm.process.instance.InternalProcessRuntime;
Expand All @@ -41,8 +41,8 @@ public class ProcessInstanceDynamicCallHelper {
private ProcessInstanceDynamicCallHelper() {
}

public static void executeRestCall(RestWorkItemHandler handler, Stream<Process<?>> processes, String processId, String processInstanceId, RestCallInfo input) {
Process<?> processDef = processes.filter(p -> p.id().equals(processId)).findAny().orElseThrow(() -> new IllegalArgumentException("Cannot find process " + processId));
public static void executeRestCall(RestWorkItemHandler handler, Collection<Process<?>> processes, String processId, String processInstanceId, RestCallInfo input) {
Process<?> processDef = processes.stream().filter(p -> p.id().equals(processId)).findAny().orElseThrow(() -> new IllegalArgumentException("Cannot find process " + processId));
WorkflowProcessInstance pi = (WorkflowProcessInstance) findProcessInstance(processDef, processInstanceId);
WorkflowProcessImpl process = (WorkflowProcessImpl) pi.getProcess();
if (!process.isDynamic()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,29 @@
*/
package org.kie.kogito.process.expr;

import java.util.Collection;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.stream.Collectors;

public class ExpressionHandlerFactory {

private ExpressionHandlerFactory() {
}

private static final ServiceLoader<ExpressionHandler> serviceLoader = ServiceLoader.load(ExpressionHandler.class);
private static final Collection<ExpressionHandler> expressionHandlers = ServiceLoader.load(ExpressionHandler.class).stream()
.map(ServiceLoader.Provider::get).collect(Collectors.toUnmodifiableList());

public static Expression get(String lang, String expr) {
return getExpressionHandler(lang).orElseThrow(
() -> new IllegalArgumentException("Unsupported language " + lang)).get(expr);
}

public static boolean isSupported(String lang) {
return serviceLoader.stream().anyMatch(p -> p.get().lang().equals(lang));
return expressionHandlers.stream().map(ExpressionHandler::lang).anyMatch(lang::equals);
}

private static Optional<ExpressionHandler> getExpressionHandler(String lang) {
return serviceLoader.stream().filter(p -> p.get().lang().equals(lang)).findFirst().map(p -> p.get());
return expressionHandlers.stream().filter(p -> p.lang().equals(lang)).findFirst();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
*/
package org.kie.kogito.process.dynamic;

import java.util.Collection;
import java.util.stream.Collectors;

import org.kie.kogito.process.Process;
import org.kogito.workitem.rest.RestWorkItemHandler;

Expand All @@ -39,13 +42,17 @@
@Path("/_dynamic")
public class ProcessInstanceDynamicCallsResource {

@Inject
Instance<Process<?>> processes;
@Inject
Vertx vertx;
@Inject
WebClientOptions sslOptions;
private RestWorkItemHandler handler;
private Collection<Process<?>> processes;

@Inject
ProcessInstanceDynamicCallsResource(Instance<Process<?>> processes) {
this.processes = processes.stream().collect(Collectors.toUnmodifiableList());
}

@PostConstruct
void init() {
Expand All @@ -57,8 +64,7 @@ void init() {
@Consumes(MediaType.APPLICATION_JSON)
@Path("/{processId}/{processInstanceId}/rest")
public Response executeRestCall(@PathParam("processId") String processId, @PathParam("processInstanceId") String processInstanceId, RestCallInfo input) {
ProcessInstanceDynamicCallHelper.executeRestCall(handler, processes.stream(), processId, processInstanceId, input);
ProcessInstanceDynamicCallHelper.executeRestCall(handler, processes, processId, processInstanceId, input);
return Response.status(200).build();
}

}

0 comments on commit 2ff45a4

Please sign in to comment.