本文整理汇总了Java中io.bootique.command.CommandOutcome类的典型用法代码示例。如果您正苦于以下问题:Java CommandOutcome类的具体用法?Java CommandOutcome怎么用?Java CommandOutcome使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommandOutcome类属于io.bootique.command包,在下文中一共展示了CommandOutcome类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import io.bootique.command.CommandOutcome; //导入依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
//retrieve the cache defined in the declaration file hazelcast.xml
Cache<String, Integer> declarativeCache = cacheManager.get()
.getCache("myCache1", String.class, Integer.class);
//put an entry...
//CacheEntryCreatedListener fires afterwards
declarativeCache.put("1", 1);
//retrieve the cache configured programmatically and contributed into Bootique
Cache<String, String> programmaticCache = cacheManager.get()
.getCache("myCache2", String.class, String.class);
//put an entry...
//CacheEntryCreatedListener fires afterwards
programmaticCache.put("key1", "value1");
return CommandOutcome.succeeded();
}
示例2: run
import io.bootique.command.CommandOutcome; //导入依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
//retrieve the cache defined in ehcache.xml
Cache<String, Integer> cache = cacheManager.get()
.getCache("myCache1", String.class, Integer.class);
//put an entry...
//CacheEntryCreatedListener fires afterwards
cache.put("1", 1);
//retrieve the cache configured programmatically and contributed into Bootique
Cache<Long, Long> myCache2 = cacheManager.get()
.getCache("myCache2", Long.class, Long.class);
//put an entry...
//CacheEntryCreatedListener fires afterwards
myCache2.put(1L, 1L);
return CommandOutcome.succeeded();
}
示例3: 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);
}
示例4: 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();
}
}
}
示例5: run
import io.bootique.command.CommandOutcome; //导入依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
DataSource dataSource = dataSourceFactoryProvider.get().forName("test1");
try (Connection c = dataSource.getConnection()) {
prepareDB(c);
for (String sql : cli.optionStrings("sql")) {
runSELECT(c, sql);
}
} catch (SQLException ex) {
logger.stderr("Error....", ex);
}
return CommandOutcome.succeeded();
}
示例6: testSchedule
import io.bootique.command.CommandOutcome; //导入依赖的package包/类
@Test
public void testSchedule() {
BomJob.COUNTER.set(0);
BomParameterizedJob.COUNTER.set(0);
CommandOutcome outcome = app.run(r -> {
// wait for scheduler to run jobs...
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
},
"--schedule", "-c", "classpath:io/bootique/bom/job/test.yml");
assertEquals(0, outcome.getExitCode());
assertTrue("Unexpected job count: " + BomJob.COUNTER.get(), BomJob.COUNTER.get() > 3);
assertTrue(BomParameterizedJob.COUNTER.get() > 17 * 3);
assertEquals(0, BomParameterizedJob.COUNTER.get() % 17);
}
示例7: testRun_Debug
import io.bootique.command.CommandOutcome; //导入依赖的package包/类
@Test
public void testRun_Debug() throws IOException {
File logFile = prepareLogFile("target/logback/testRun_Debug.log");
BQRuntime runtime = app
.app("--config=src/test/resources/io/bootique/bom/logback/test-debug.yml").createRuntime();
CommandOutcome outcome = runtime.run();
// stopping runtime to ensure the logs are flushed before we start making assertions...
runtime.shutdown();
assertEquals(0, outcome.getExitCode());
assertTrue(logFile.isFile());
String logfileContents = Files.lines(logFile.toPath()).collect(joining("\n"));
assertTrue(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-debug"));
assertTrue(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-info"));
assertTrue(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-warn"));
assertTrue(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-error"));
}
示例8: testRun_Warn
import io.bootique.command.CommandOutcome; //导入依赖的package包/类
@Test
public void testRun_Warn() throws IOException {
File logFile = prepareLogFile("target/logback/testRun_Warn.log");
BQRuntime runtime = app.app("--config=src/test/resources/io/bootique/bom/logback/test-warn.yml")
.createRuntime();
CommandOutcome outcome = runtime.run();
// stopping runtime to ensure the logs are flushed before we start making assertions...
runtime.shutdown();
assertEquals(0, outcome.getExitCode());
assertTrue(logFile.isFile());
String logfileContents = Files.lines(logFile.toPath()).collect(joining("\n"));
assertFalse(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-debug"));
assertFalse(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-info"));
assertTrue("Logfile contents: " + logfileContents,
logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-warn"));
assertTrue(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-error"));
}
示例9: testRun_Help
import io.bootique.command.CommandOutcome; //导入依赖的package包/类
@Test
public void testRun_Help() {
TestIO io = TestIO.noTrace();
BQRuntime runtime = app.app("--help")
.bootLogger(io.getBootLogger())
.startupAndWaitCheck()
// using longer startup timeout .. sometimes this fails on Travis..
.startupTimeout(8, TimeUnit.SECONDS)
.start();
CommandOutcome outcome = app.getOutcome(runtime).get();
assertEquals(0, outcome.getExitCode());
assertTrue(io.getStdout().contains("--help"));
assertTrue(io.getStdout().contains("--config"));
}
示例10: run
import io.bootique.command.CommandOutcome; //导入依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
System.out.println("SNOMED-CT interactive browser and search.");
boolean quit = false;
while (!quit) {
if (currentConcept() != null) {
System.out.println("****************************************");
System.out.println("Current: "+currentConcept().getConceptId() + ": " + currentConcept().getFullySpecifiedName());
System.out.println("****************************************");
}
System.out.println("Enter command:");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
try {
String line = bufferedReader.readLine();
quit = performCommand(line.trim());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return CommandOutcome.succeeded();
}
示例11: testRun
import io.bootique.command.CommandOutcome; //导入依赖的package包/类
@Test
public void testRun() {
CommandOutcome outcome = testFactory.app("-s")
.module(b -> UndertowModule.extend(b).addController(TestController.class))
.run();
assertTrue(outcome.isSuccess());
assertTrue(outcome.forkedToBackground());
// testing that the server is in the operational state by the time ServerCommand exits...
WebTarget base = ClientBuilder.newClient().target("http://localhost:8080");
Response r = base.path("/").request().get();
assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
assertEquals("Hello World!", r.readEntity(String.class));
}
示例12: testRun
import io.bootique.command.CommandOutcome; //导入依赖的package包/类
@Test
public void testRun() {
CommandOutcome outcome = testFactory.app("-s")
.module(b -> JettyModule.extend(b).addServlet(new TestServlet(), "x", "/"))
.run();
assertTrue(outcome.isSuccess());
assertTrue(outcome.forkedToBackground());
// testing that the server is in the operational state by the time ServerCommand exits...
WebTarget base = ClientBuilder.newClient().target("http://localhost:8080");
Response r = base.path("/").request().get();
assertEquals(Response.Status.OK.getStatusCode(), r.getStatus());
assertEquals("Hello World!", r.readEntity(String.class));
}
示例13: run
import io.bootique.command.CommandOutcome; //导入依赖的package包/类
@Override
public CommandOutcome run(Cli cli) {
Scheduler scheduler = schedulerProvider.get();
int jobCount;
List<String> jobNames = cli.optionStrings(JOB_OPTION);
if (jobNames == null || jobNames.isEmpty()) {
LOGGER.info("Starting scheduler");
jobCount = scheduler.start();
} else {
LOGGER.info("Starting scheduler for jobs: " + jobNames);
jobCount = scheduler.start(jobNames);
}
LOGGER.info("Started scheduler with {} trigger(s).", jobCount);
return CommandOutcome.succeededAndForkedToBackground();
}
示例14: 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;
}
示例15: checkStartupOutcome
import io.bootique.command.CommandOutcome; //导入依赖的package包/类
private Optional<CommandOutcome> checkStartupOutcome() {
// Either the command has finished, or it is still running, but the custom check is successful.
// The later test may be used for blocking commands that start some background processing and
// wait till the end.
if (outcome != null) {
return Optional.of(outcome);
}
if (startupCheck.apply(runtime)) {
// command is still running (perhaps waiting for a background task execution, or listening for
// requests), but the stack is in the state that can be tested already.
return Optional.of(CommandOutcome.succeededAndForkedToBackground());
}
logger.stderr("Daemon runtime hasn't started yet...");
return Optional.empty();
}