Skip to content

Commit

Permalink
Ported MOSIP-27386 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nambirajanr committed Aug 20, 2024
1 parent 3730a3a commit 4d97735
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.task.DelegatingSecurityContextAsyncTaskExecutor;
import org.springframework.web.client.DefaultResponseErrorHandler;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.function.client.WebClient;
Expand Down Expand Up @@ -189,6 +190,15 @@ public void setId(Map<String, String> id) {
this.id = id;
}

@Value("${mosip.idrepo.identity-core-pool-size:3}")
private int corePoolSize;

@Value("${mosip.idrepo.identity-max-pool-size:3}")
private int maxPoolSize;

@Value("${mosip.idrepo.identity-queue-capacity:500}")
private int queueCapacity;

/**
* Sets the allowed bio types.
*
Expand Down Expand Up @@ -353,4 +363,24 @@ private void logThreadQueueDetails(ThreadPoolTaskExecutor threadPoolTaskExecutor
threadPoolTaskExecutor.getActiveCount(),
threadPoolTaskExecutor.getThreadPoolExecutor().getTaskCount(), threadPoolQueueSize);
}

/*
* This bean is returned because for async task the security context needs to be
* passed.
*
*/
@Bean("withSecurityContext")
public DelegatingSecurityContextAsyncTaskExecutor taskExecutor() {
return new DelegatingSecurityContextAsyncTaskExecutor(threadPoolTaskExecutor());
}

private ThreadPoolTaskExecutor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(corePoolSize);
executor.setMaxPoolSize(maxPoolSize);
executor.setQueueCapacity(queueCapacity);
executor.setThreadNamePrefix("idrepo-");
executor.initialize();
return executor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class BiometricExtractionServiceImpl implements BiometricExtractionServic
* @return the completable future
* @throws IdRepoAppException the id repo app exception
*/
@Async
@Async("withSecurityContext")
public CompletableFuture<List<BIR>> extractTemplate(String uinHash, String fileName,
String extractionType, String extractionFormat, List<BIR> birsForModality) throws IdRepoAppException {
try {
Expand Down

0 comments on commit 4d97735

Please sign in to comment.