|
1 | 1 | package com.marklogic.client.modulesloader.impl; |
2 | 2 |
|
3 | | -import java.io.File; |
4 | | -import java.io.IOException; |
5 | | -import java.util.*; |
6 | | -import java.util.concurrent.Future; |
7 | | -import java.util.concurrent.TimeUnit; |
8 | | - |
9 | | -import com.marklogic.client.io.marker.QueryOptionsWriteHandle; |
10 | | -import org.springframework.beans.factory.DisposableBean; |
11 | | -import org.springframework.core.io.FileSystemResource; |
12 | | -import org.springframework.core.io.Resource; |
13 | | -import org.springframework.core.task.AsyncTaskExecutor; |
14 | | -import org.springframework.core.task.SimpleAsyncTaskExecutor; |
15 | | -import org.springframework.core.task.SyncTaskExecutor; |
16 | | -import org.springframework.core.task.TaskExecutor; |
17 | | -import org.springframework.scheduling.concurrent.ExecutorConfigurationSupport; |
18 | | -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
19 | | -import org.springframework.util.FileCopyUtils; |
20 | | - |
21 | 3 | import com.fasterxml.jackson.databind.JsonNode; |
22 | 4 | import com.fasterxml.jackson.databind.ObjectMapper; |
23 | 5 | import com.marklogic.client.DatabaseClient; |
24 | | -import com.marklogic.client.admin.ExtensionLibrariesManager; |
25 | | -import com.marklogic.client.admin.ExtensionMetadata; |
26 | | -import com.marklogic.client.admin.NamespacesManager; |
27 | | -import com.marklogic.client.admin.QueryOptionsManager; |
28 | | -import com.marklogic.client.admin.ResourceExtensionsManager; |
| 6 | +import com.marklogic.client.admin.*; |
29 | 7 | import com.marklogic.client.admin.ResourceExtensionsManager.MethodParameters; |
30 | | -import com.marklogic.client.admin.ServerConfigurationManager; |
31 | 8 | import com.marklogic.client.admin.ServerConfigurationManager.UpdatePolicy; |
32 | | -import com.marklogic.client.admin.TransformExtensionsManager; |
33 | 9 | import com.marklogic.client.helper.FilenameUtil; |
34 | 10 | import com.marklogic.client.helper.LoggingObject; |
35 | 11 | import com.marklogic.client.io.Format; |
36 | 12 | import com.marklogic.client.io.InputStreamHandle; |
37 | | -import com.marklogic.client.modulesloader.ExtensionMetadataAndParams; |
38 | | -import com.marklogic.client.modulesloader.ExtensionMetadataProvider; |
39 | | -import com.marklogic.client.modulesloader.Modules; |
40 | | -import com.marklogic.client.modulesloader.ModulesFinder; |
41 | | -import com.marklogic.client.modulesloader.ModulesLoader; |
42 | | -import com.marklogic.client.modulesloader.ModulesManager; |
| 13 | +import com.marklogic.client.modulesloader.*; |
| 14 | +import org.springframework.beans.factory.DisposableBean; |
| 15 | +import org.springframework.core.io.FileSystemResource; |
| 16 | +import org.springframework.core.io.Resource; |
| 17 | +import org.springframework.core.task.SyncTaskExecutor; |
| 18 | +import org.springframework.core.task.TaskExecutor; |
| 19 | +import org.springframework.scheduling.concurrent.ExecutorConfigurationSupport; |
| 20 | +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; |
| 21 | +import org.springframework.util.FileCopyUtils; |
| 22 | + |
| 23 | +import java.io.File; |
| 24 | +import java.io.IOException; |
| 25 | +import java.util.*; |
| 26 | +import java.util.concurrent.Future; |
| 27 | +import java.util.concurrent.TimeUnit; |
43 | 28 |
|
44 | 29 | /** |
45 | 30 | * Default implementation of ModulesLoader. Loads everything except assets via the REST API. Assets are either loaded |
@@ -101,6 +86,11 @@ protected void initializeDefaultTaskExecutor() { |
101 | 86 | if (taskThreadCount > 1) { |
102 | 87 | ThreadPoolTaskExecutor tpte = new ThreadPoolTaskExecutor(); |
103 | 88 | tpte.setCorePoolSize(taskThreadCount); |
| 89 | + |
| 90 | + // 10 minutes should be plenty of time to wait for REST API modules to be loaded |
| 91 | + tpte.setAwaitTerminationSeconds(60 * 10); |
| 92 | + tpte.setWaitForTasksToCompleteOnShutdown(true); |
| 93 | + |
104 | 94 | tpte.afterPropertiesSet(); |
105 | 95 | this.taskExecutor = tpte; |
106 | 96 | } else { |
@@ -551,17 +541,13 @@ public void run() { |
551 | 541 | } |
552 | 542 |
|
553 | 543 | /** |
554 | | - * Ensures that if we're using an AsyncTaskExecutor, we capture the Future and add it to our list so we can ensure |
555 | | - * we wait for it to finish. |
| 544 | + * Protected in case a subclass wants to execute the Runnable in a different way - e.g. capturing the Future |
| 545 | + * that could be returned. |
556 | 546 | * |
557 | 547 | * @param r |
558 | 548 | */ |
559 | 549 | protected void executeTask(Runnable r) { |
560 | | - if (taskExecutor instanceof AsyncTaskExecutor) { |
561 | | - taskFutures.add(((AsyncTaskExecutor)taskExecutor).submit(r)); |
562 | | - } else { |
563 | | - taskExecutor.execute(r); |
564 | | - } |
| 550 | + taskExecutor.execute(r); |
565 | 551 | } |
566 | 552 |
|
567 | 553 | public File installNamespace(File f) { |
|
0 commit comments