From cadca518ec3a8a6d55992a82eff6ddd5e135858c Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Tue, 20 Apr 2021 09:14:50 -0400 Subject: [PATCH] Add options to BaseCommand --- .../main/java/ca/uhn/fhir/cli/BaseCommand.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/BaseCommand.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/BaseCommand.java index b2b9cb837c3..2e511c26433 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/BaseCommand.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/BaseCommand.java @@ -31,6 +31,7 @@ import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.time.DateUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -70,6 +71,9 @@ public abstract class BaseCommand implements Comparable { protected static final String VERBOSE_LOGGING_PARAM = "l"; protected static final String VERBOSE_LOGGING_PARAM_LONGOPT = "logging"; protected static final String VERBOSE_LOGGING_PARAM_DESC = "If specified, verbose logging will be used."; + protected static final int DEFAULT_THREAD_COUNT = 10; + protected static final String THREAD_COUNT = "thread-count"; + // TODO: Don't use qualified names for loggers in HAPI CLI. private static final Logger ourLog = LoggerFactory.getLogger(BaseCommand.class); protected FhirContext myFhirCtx; @@ -87,6 +91,11 @@ public abstract class BaseCommand implements Comparable { addOptionalOption(theOptions, null, BEARER_TOKEN_PARAM_LONGOPT, BEARER_TOKEN_PARAM_NAME, BEARER_TOKEN_PARAM_DESC); } + protected void addThreadCountOption(Options theOptions) { + addOptionalOption(theOptions, null, THREAD_COUNT, "count", "If specified, this argument specifies the number of worker threads used (default is " + DEFAULT_THREAD_COUNT + ")"); + } + + protected String promptUser(String thePrompt) throws ParseException { System.out.print(ansi().bold().fgBrightDefault()); System.out.print(thePrompt); @@ -309,6 +318,12 @@ public abstract class BaseCommand implements Comparable { return getFhirContext().getResourceDefinition("Bundle").getImplementingClass(IBaseBundle.class); } + protected int getThreadCount(CommandLine theCommandLine) throws ParseException { + Integer parallelismThreadCount = getAndParsePositiveIntegerParam(theCommandLine, THREAD_COUNT); + parallelismThreadCount = ObjectUtils.defaultIfNull(parallelismThreadCount, DEFAULT_THREAD_COUNT); + return parallelismThreadCount.intValue(); + } + public abstract String getCommandDescription(); public abstract String getCommandName();