Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a custom executor that sets JAXB correctly #542

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion plugin/cql/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opencds.cqf.ruler</groupId>
Expand All @@ -17,5 +18,9 @@
<groupId>org.opencds.cqf.cql</groupId>
<artifactId>evaluator.spring</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
</dependencies>
</project>
14 changes: 14 additions & 0 deletions plugin/cql/src/main/java/org/opencds/cqf/ruler/cql/CqlConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.ForkJoinPool;

import org.cqframework.cql.cql2elm.CqlTranslatorOptions;
import org.cqframework.cql.cql2elm.LibraryManager;
Expand Down Expand Up @@ -48,6 +50,8 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;
import org.springframework.security.concurrent.DelegatingSecurityContextExecutor;
import org.springframework.security.core.context.SecurityContextHolder;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
Expand Down Expand Up @@ -321,4 +325,14 @@ public ITermReadSvcR4 termReadSvcR4() {
public ITermReadSvcR5 termReadSvcR5() {
return new PreExpandedTermReadSvcR5();
}

@Bean(name = "cqlExecutor")
public Executor cqlExecutor() {
CqlForkJoinWorkerThreadFactory factory = new CqlForkJoinWorkerThreadFactory();
ForkJoinPool myCommonPool = new ForkJoinPool(Math.min(32767, Runtime.getRuntime().availableProcessors()), factory,
null, false);

return new DelegatingSecurityContextExecutor(myCommonPool,
SecurityContextHolder.getContext());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.opencds.cqf.ruler.cql;

import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory;
import java.util.concurrent.ForkJoinWorkerThread;

// This class resolves issues with loading JAXB in a server environment and using CompleteableFutures
// https://stackoverflow.com/questions/49113207/completablefuture-forkjoinpool-set-class-loader
class CqlForkJoinWorkerThreadFactory implements ForkJoinWorkerThreadFactory {

@Override
public final ForkJoinWorkerThread newThread(ForkJoinPool pool) {
return new CqlForkJoinWorkerThread(pool);
}

private static class CqlForkJoinWorkerThread extends ForkJoinWorkerThread {

private CqlForkJoinWorkerThread(final ForkJoinPool pool) {
super(pool);
// set the correct classloader here
setContextClassLoader(Thread.currentThread().getContextClassLoader());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.regex.Pattern;

import com.google.common.base.Strings;

import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.MutablePair;
Expand Down Expand Up @@ -52,6 +51,8 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.google.common.base.Strings;

import ca.uhn.fhir.model.api.annotation.Description;
import ca.uhn.fhir.rest.annotation.Operation;
import ca.uhn.fhir.rest.annotation.OperationParam;
Expand Down Expand Up @@ -130,6 +131,9 @@ public String toDisplayString() {
@Autowired
private CrProperties crProperties;

@Autowired
private Executor cqlExecutor;

/**
* Implements the <a href=
* "http://build.fhir.org/ig/HL7/davinci-deqm/OperationDefinition-care-gaps.html">$care-gaps</a>
Expand Down Expand Up @@ -209,29 +213,29 @@ public Parameters careGapsReport(RequestDetails theRequestDetails,
throw new NotImplementedException("Non subject parameters have not been implemented.");
}

List<CompletableFuture<Parameters.ParametersParameterComponent>> futures = new ArrayList<>();
List<CompletableFuture<Parameters.ParametersParameterComponent>> futures = new ArrayList<>();

Parameters result = initializeResult();

if (crProperties.getThreadedCareGapsEnabled()) {
(patients)
.forEach(
patient -> {
futures.add(CompletableFuture.supplyAsync(() -> patientReports(theRequestDetails,
periodStart, periodEnd, patient, status, measures, organization)));
});
.forEach(
patient -> {
futures.add(CompletableFuture.supplyAsync(() -> patientReports(theRequestDetails,
periodStart, periodEnd, patient, status, measures, organization), cqlExecutor));
});

futures.forEach(x -> result.addParameter(x.join()));
} else {
(patients)
.forEach(
patient -> {
Parameters.ParametersParameterComponent patientParameter = patientReports(theRequestDetails,
periodStart, periodEnd, patient, status, measures, organization);
if (patientParameter != null) {
result.addParameter(patientParameter);
}
});
.forEach(
patient -> {
Parameters.ParametersParameterComponent patientParameter = patientReports(theRequestDetails,
periodStart, periodEnd, patient, status, measures, organization);
if (patientParameter != null) {
result.addParameter(patientParameter);
}
});
}

return result;
Expand Down
Loading