本文整理汇总了Java中io.bootique.command.CommandOutcome.failed方法的典型用法代码示例。如果您正苦于以下问题:Java CommandOutcome.failed方法的具体用法?Java CommandOutcome.failed怎么用?Java CommandOutcome.failed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.bootique.command.CommandOutcome
的用法示例。
在下文中一共展示了CommandOutcome.failed方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import io.bootique.command.CommandOutcome; //导入方法依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
String topic = cli.optionString(TOPIC_OPT);
if (topic == null) {
return CommandOutcome.failed(-1, "No --topic specified");
}
ProducerConfig<byte[], String> config = ProducerConfig
.charValueConfig()
.bootstrapServers(cli.optionStrings(BOOTSTRAP_SERVER_OPT))
.build();
Producer<byte[], String> producer = kafkaProvider.get().createProducer(DEFAULT_CLUSTER_NAME, config);
shutdownManager.addShutdownHook(() -> {
producer.close();
// give a bit of time to stop..
Thread.sleep(200);
});
return runConsole(topic, producer);
}
示例2: run
import io.bootique.command.CommandOutcome; //导入方法依赖的package包/类
public CommandOutcome run(Consumer<BQRuntime> beforeShutdownCallback, String... args) {
BootLogger logger = createBootLogger();
Bootique bootique = Bootique.app(args).bootLogger(logger);
configure(bootique);
BQRuntime runtime = bootique.createRuntime();
try {
return runtime.getInstance(Runner.class).run();
} catch (Exception e) {
logger.stderr("Error", e);
return CommandOutcome.failed(1, getStderr());
} finally {
try {
beforeShutdownCallback.accept(runtime);
}
finally {
runtime.shutdown();
}
}
}
示例3: run
import io.bootique.command.CommandOutcome; //导入方法依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
List<String> jobNames = cli.optionStrings(JOB_OPTION);
if (jobNames == null || jobNames.isEmpty()) {
return CommandOutcome.failed(1,
String.format("No jobs specified. Use '--%s' option to provide job names", JOB_OPTION));
}
LOGGER.info("Will run job(s): " + jobNames);
Scheduler scheduler = schedulerProvider.get();
CommandOutcome outcome;
if (cli.hasOption(SERIAL_OPTION)) {
outcome = runSerial(jobNames, scheduler);
} else {
outcome = runParallel(jobNames, scheduler);
}
return outcome;
}
示例4: testStart_StartupFailure
import io.bootique.command.CommandOutcome; //导入方法依赖的package包/类
@Test
public void testStart_StartupFailure() {
CommandOutcome failed = CommandOutcome.failed(-1, "Intended failure");
try {
testFactory.app("")
.module(b ->
BQCoreModule.extend(b).setDefaultCommand(cli -> failed))
.startupCheck(r -> false)
.start();
} catch (BootiqueException e) {
assertEquals(-1, e.getOutcome().getExitCode());
assertEquals("Daemon failed to start: " + failed, e.getOutcome().getMessage());
}
}
示例5: runConsole
import io.bootique.command.CommandOutcome; //导入方法依赖的package包/类
private CommandOutcome runConsole(String topic, Producer<byte[], String> producer) {
System.out.println("");
System.out.println(" Start typing messages below. Type '\\q' to exit.");
System.out.println("");
try (BufferedReader stdinReader = new BufferedReader(new InputStreamReader(System.in))) {
readAndPost(stdinReader, topic, producer);
return CommandOutcome.succeeded();
} catch (IOException ex) {
return CommandOutcome.failed(-1, ex);
}
}
示例6: run
import io.bootique.command.CommandOutcome; //导入方法依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
ObjectContext context = cayenne.get().newContext();
PrintWriter writer = new PrintWriter(System.out);
try (CSVWriter csv = new CSVWriter(writer)) {
SelectQuery<Concept> query = SelectQuery.query(Concept.class, Concept.RECURSIVE_PARENT_CONCEPTS.dot(Concept.CONCEPT_ID).eq(Category.PHARMACEUTICAL_OR_BIOLOGICAL_PRODUCT.conceptId));
String[] row = new String[] {"product", "isPrescribable","conceptIdentifier","type", "isSearchable", "prescribeAs" };
csv.writeNext(row);
try (ResultBatchIterator<Concept> iterator = query.batchIterator(context, 500)) {
while (iterator.hasNext()) {
List<Concept> batch = iterator.next();
for (Concept c : batch) {
Dmd.Product.productForConcept(c).ifPresent(p -> {
row[0] = c.getPreferredDescription().getTerm();
row[1] = String.valueOf(_productIsPrescribable(c, p));
row[2] = c.getConceptId().toString();
row[3] = p.abbreviation();
row[4] = String.valueOf(_productIsSearchable(c, p));
row[5] = _prescribingNotes(c, p);
csv.writeNext(row);
});
}
}
}
} catch (IOException e) {
e.printStackTrace();
return CommandOutcome.failed(-1, e);
}
return CommandOutcome.succeeded();
}
示例7: run
import io.bootique.command.CommandOutcome; //导入方法依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
LOGGER.info("Will run Undertow Server...");
UndertowServer server = serverProvider.get();
try {
server.start();
} catch (Exception e) {
return CommandOutcome.failed(1, e);
}
return CommandOutcome.succeededAndForkedToBackground();
}
示例8: run
import io.bootique.command.CommandOutcome; //导入方法依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
Server server = serverProvider.get();
try {
// this blocks until a successful start or an error, then releases current thread, while Jetty
// stays running on the background
server.start();
} catch (Exception e) {
return CommandOutcome.failed(1, e);
}
return CommandOutcome.succeededAndForkedToBackground();
}
示例9: runParallel
import io.bootique.command.CommandOutcome; //导入方法依赖的package包/类
private CommandOutcome runParallel(List<String> jobNames, Scheduler scheduler) {
List<JobFuture> futures = jobNames.stream().map(scheduler::runOnce).collect(Collectors.toList());
long failedCount = futures.stream()
.map(JobFuture::get)
.peek(this::processResult)
.filter(result -> !result.isSuccess())
.count();
return (failedCount > 0) ? CommandOutcome.failed(1, "Some of the jobs failed") : CommandOutcome.succeeded();
}
示例10: runSerial
import io.bootique.command.CommandOutcome; //导入方法依赖的package包/类
private CommandOutcome runSerial(List<String> jobNames, Scheduler scheduler) {
for (String jobName : jobNames) {
JobResult result = scheduler.runOnce(jobName).get();
processResult(result);
if (!result.isSuccess()) {
return CommandOutcome.failed(1, "One of the jobs failed");
}
}
return CommandOutcome.succeeded();
}
示例11: processExceptions
import io.bootique.command.CommandOutcome; //导入方法依赖的package包/类
private CommandOutcome processExceptions(Throwable th, Throwable parentTh) {
if (th instanceof BootiqueException) {
CommandOutcome originalOutcome = ((BootiqueException) th).getOutcome();
// BootiqueException should be stripped of the exception cause and reported on a single line
// TODO: should we still print the stack trace via logger.trace?
return CommandOutcome.failed(originalOutcome.getExitCode(), originalOutcome.getMessage());
}
String thMessage = th != null ? th.getMessage() : null;
String message = thMessage != null ? "Command exception: '" + thMessage + "'." : "Command exception.";
return CommandOutcome.failed(1, message, parentTh);
}
示例12: run
import io.bootique.command.CommandOutcome; //导入方法依赖的package包/类
/**
* @param runtime runtime started by Bootique.
* @return the outcome of the command execution.
* @deprecated since 0.23. Previously this method existed to catch and process run exceptions, but it doesn't
* have wide enough scope for this, so exception processing was moved to {@link #exec()}.
*/
@Deprecated
private CommandOutcome run(BQRuntime runtime) {
try {
return runtime.getRunner().run();
}
// handle startup Guice exceptions
catch (ProvisionException e) {
// TODO: a dependency on JOPT OptionException shouldn't be here
return (e.getCause() instanceof OptionException) ? CommandOutcome.failed(1, e.getCause().getMessage())
: CommandOutcome.failed(1, e);
}
}
示例13: BootiqueException
import io.bootique.command.CommandOutcome; //导入方法依赖的package包/类
public BootiqueException(int exitCode, String message) {
this.outcome = CommandOutcome.failed(exitCode, message, this);
}