当前位置: 首页>>代码示例>>Java>>正文


Java Command类代码示例

本文整理汇总了Java中org.apache.twill.api.Command的典型用法代码示例。如果您正苦于以下问题:Java Command类的具体用法?Java Command怎么用?Java Command使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Command类属于org.apache.twill.api包,在下文中一共展示了Command类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: restartInstances

import org.apache.twill.api.Command; //导入依赖的package包/类
@Override
public final ListenableFuture<Set<String>> restartInstances(
  Map<String, ? extends Set<Integer>> runnableToInstanceIds) {
  Map<String, String> runnableToStringInstanceIds =
    Maps.transformEntries(runnableToInstanceIds, new Maps.EntryTransformer<String, Set<Integer>, String>() {
      @Override
      public String transformEntry(String runnableName, Set<Integer> instanceIds) {
        validateInstanceIds(runnableName, instanceIds);
        return GSON.toJson(instanceIds, new TypeToken<Set<Integer>>() {}.getType());
      }
    });
  Command updateStateCommand = Command.Builder.of(Constants.RESTART_RUNNABLES_INSTANCES)
    .addOptions(runnableToStringInstanceIds)
    .build();
  Message message = SystemMessages.updateRunnablesInstances(updateStateCommand);

  return sendMessage(message, runnableToInstanceIds.keySet());
}
 
开发者ID:apache,项目名称:twill,代码行数:19,代码来源:AbstractTwillController.java

示例2: handleSetInstances

import org.apache.twill.api.Command; //导入依赖的package包/类
/**
 * Attempts to change the number of running instances.
 *
 * @return {@code true} if the message does requests for changes in number of running instances of a runnable,
 * {@code false} otherwise.
 */
private boolean handleSetInstances(Message message, Runnable completion) {
  if (message.getType() != Message.Type.SYSTEM || message.getScope() != Message.Scope.RUNNABLE) {
    return false;
  }

  Command command = message.getCommand();
  Map<String, String> options = command.getOptions();
  if (!"instances".equals(command.getCommand()) || !options.containsKey("count")) {
    return false;
  }

  final String runnableName = message.getRunnableName();
  if (runnableName == null || runnableName.isEmpty() || !twillSpec.getRunnables().containsKey(runnableName)) {
    LOG.info("Unknown runnable {}", runnableName);
    return false;
  }

  final int newCount = Integer.parseInt(options.get("count"));
  final int oldCount = expectedContainers.getExpected(runnableName);

  LOG.info("Received change instances request for {}, from {} to {}.", runnableName, oldCount, newCount);

  if (newCount == oldCount) {   // Nothing to do, simply complete the request.
    completion.run();
    return true;
  }

  instanceChangeExecutor.execute(createSetInstanceRunnable(message, completion, oldCount, newCount));
  return true;
}
 
开发者ID:apache,项目名称:twill,代码行数:37,代码来源:ApplicationMasterService.java

示例3: handleCommand

import org.apache.twill.api.Command; //导入依赖的package包/类
@Override
public void handleCommand(Command command) throws Exception {
  super.handleCommand(command);
  if (HANGING_RUNNABLE_STOP_SECS.equals(command.getCommand())) {
    int time = Integer.parseInt(command.getOptions().get(HANGING_RUNNABLE_STOP_SECS));
    LOG.info("Got sleep time from message = {} secs", time);
    sleepTime.set(time);
  }
}
 
开发者ID:apache,项目名称:twill,代码行数:10,代码来源:RestartRunnableTestRun.java

示例4: testFailureRestart

import org.apache.twill.api.Command; //导入依赖的package包/类
@Test
public void testFailureRestart() throws Exception {
  TwillRunner runner = getTwillRunner();

  ResourceSpecification resource = ResourceSpecification.Builder.with()
    .setVirtualCores(1)
    .setMemory(512, ResourceSpecification.SizeUnit.MEGA)
    .setInstances(2)
    .build();
  TwillController controller = runner.prepare(new FailureRunnable(), resource)
    .withApplicationArguments("failure")
    .withArguments(FailureRunnable.class.getSimpleName(), "failure2")
    .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
    .start();

  Iterable<Discoverable> discoverables = controller.discoverService("failure");
  Assert.assertTrue(waitForSize(discoverables, 2, 120));

  // Make sure we see the right instance IDs
  Assert.assertEquals(Sets.newHashSet(0, 1), getInstances(discoverables));

  // Kill server with instanceId = 0
  controller.sendCommand(FailureRunnable.class.getSimpleName(), Command.Builder.of("kill0").build());

  // Make sure the runnable is killed.
  Assert.assertTrue(waitForSize(discoverables, 1, 120));

  // Wait for the restart
  Assert.assertTrue(waitForSize(discoverables, 2, 120));

  // Make sure we see the right instance IDs
  Assert.assertEquals(Sets.newHashSet(0, 1), getInstances(discoverables));

  controller.terminate().get(120, TimeUnit.SECONDS);
}
 
开发者ID:apache,项目名称:twill,代码行数:36,代码来源:FailureRestartTestRun.java

示例5: handleCommand

import org.apache.twill.api.Command; //导入依赖的package包/类
@Override
public void handleCommand(Command command) throws Exception {
  if (command.getCommand().equals("kill" + getContext().getInstanceId())) {
    killed = true;
    running = false;
    serverSocket.close();
  }
}
 
开发者ID:apache,项目名称:twill,代码行数:9,代码来源:FailureRestartTestRun.java

示例6: restartAllInstances

import org.apache.twill.api.Command; //导入依赖的package包/类
@Override
public final ListenableFuture<String> restartAllInstances(String runnableName) {
  Command updateStateCommand = Command.Builder.of(Constants.RESTART_ALL_RUNNABLE_INSTANCES).
    build();
  Message message = SystemMessages.updateRunnableInstances(updateStateCommand, runnableName);
  return sendMessage(message, updateStateCommand.getCommand());
}
 
开发者ID:apache,项目名称:twill,代码行数:8,代码来源:AbstractTwillController.java

示例7: updateLogLevels

import org.apache.twill.api.Command; //导入依赖的package包/类
/**
 * Helper method to get System {@link Message} for updating the log levels for one or all runnables.
 *
 * @param runnableName The name of the runnable to update the log level, null if apply to all runnables.
 * @param logLevels The log levels to be updated.
 * @return An instance of System {@link Message} to update the log levels.
 */
public static Message updateLogLevels(@Nullable String runnableName, Map<String, LogEntry.Level> logLevels) {
  Preconditions.checkNotNull(logLevels);
  Preconditions.checkArgument(!(logLevels.containsKey(Logger.ROOT_LOGGER_NAME)
                                && logLevels.get(Logger.ROOT_LOGGER_NAME) == null));
  Map<String, String> options = convertLogEntryToString(logLevels);
  return new SimpleMessage(Message.Type.SYSTEM,
                           runnableName == null ? Message.Scope.ALL_RUNNABLE : Message.Scope.RUNNABLE,
                           runnableName, Command.Builder.of(SET_LOG_LEVEL).addOptions(options).build());
}
 
开发者ID:apache,项目名称:twill,代码行数:17,代码来源:SystemMessages.java

示例8: resetLogLevels

import org.apache.twill.api.Command; //导入依赖的package包/类
/**
* Helper method to get System {@link Message} for resetting log levels for one or all runnables.
*
* @param runnableName The name of the runnable to set the log level, null if apply to all runnables.
* @return An instance of System {@link Message} to reset the log levels.
*/
public static Message resetLogLevels(@Nullable String runnableName, Set<String> loggerNames) {
  return new SimpleMessage(Message.Type.SYSTEM,
                           runnableName == null ? Message.Scope.ALL_RUNNABLE : Message.Scope.RUNNABLE,
                           runnableName, Command.Builder.of(RESET_LOG_LEVEL)
                             .addOptions(Maps.uniqueIndex(loggerNames, Functions.toStringFunction())).build());
}
 
开发者ID:apache,项目名称:twill,代码行数:13,代码来源:SystemMessages.java

示例9: deserialize

import org.apache.twill.api.Command; //导入依赖的package包/类
@Override
public Message deserialize(JsonElement json, Type typeOfT,
                           JsonDeserializationContext context) throws JsonParseException {
  JsonObject jsonObj = json.getAsJsonObject();

  Message.Type type = Message.Type.valueOf(jsonObj.get("type").getAsString());
  Message.Scope scope = Message.Scope.valueOf(jsonObj.get("scope").getAsString());
  JsonElement name = jsonObj.get("runnableName");
  String runnableName = (name == null || name.isJsonNull()) ? null : name.getAsString();
  Command command = context.deserialize(jsonObj.get("command"), Command.class);

  return new SimpleMessage(type, scope, runnableName, command);
}
 
开发者ID:apache,项目名称:twill,代码行数:14,代码来源:MessageCodec.java

示例10: serialize

import org.apache.twill.api.Command; //导入依赖的package包/类
@Override
public JsonElement serialize(Message message, Type typeOfSrc, JsonSerializationContext context) {
  JsonObject jsonObj = new JsonObject();
  jsonObj.addProperty("type", message.getType().name());
  jsonObj.addProperty("scope", message.getScope().name());
  jsonObj.addProperty("runnableName", message.getRunnableName());
  jsonObj.add("command", context.serialize(message.getCommand(), Command.class));

  return jsonObj;
}
 
开发者ID:apache,项目名称:twill,代码行数:11,代码来源:MessageCodec.java

示例11: testController

import org.apache.twill.api.Command; //导入依赖的package包/类
@Test
public void testController() throws ExecutionException, InterruptedException, TimeoutException {
  InMemoryZKServer zkServer = InMemoryZKServer.builder().build();
  zkServer.startAndWait();

  LOG.info("ZKServer: " + zkServer.getConnectionStr());

  try {
    RunId runId = RunIds.generate();
    ZKClientService zkClientService = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
    zkClientService.startAndWait();

    Service service = createService(zkClientService, runId);
    service.startAndWait();

    TwillController controller = getController(zkClientService, "testController", runId);
    controller.sendCommand(Command.Builder.of("test").build()).get(2, TimeUnit.SECONDS);
    controller.terminate().get(2, TimeUnit.SECONDS);

    final CountDownLatch terminateLatch = new CountDownLatch(1);
    service.addListener(new ServiceListenerAdapter() {
      @Override
      public void terminated(Service.State from) {
        terminateLatch.countDown();
      }
    }, Threads.SAME_THREAD_EXECUTOR);

    Assert.assertTrue(service.state() == Service.State.TERMINATED || terminateLatch.await(2, TimeUnit.SECONDS));

    zkClientService.stopAndWait();

  } finally {
    zkServer.stopAndWait();
  }
}
 
开发者ID:apache,项目名称:twill,代码行数:36,代码来源:ControllerTest.java

示例12: handleSetInstances

import org.apache.twill.api.Command; //导入依赖的package包/类
/**
 * Attempts to change the number of running instances.
 * @return {@code true} if the message does requests for changes in number of running instances of a runnable,
 *         {@code false} otherwise.
 */
private boolean handleSetInstances(final Message message, final Runnable completion) {
  if (message.getType() != Message.Type.SYSTEM || message.getScope() != Message.Scope.RUNNABLE) {
    return false;
  }

  Command command = message.getCommand();
  Map<String, String> options = command.getOptions();
  if (!"instances".equals(command.getCommand()) || !options.containsKey("count")) {
    return false;
  }

  final String runnableName = message.getRunnableName();
  if (runnableName == null || runnableName.isEmpty() || !twillSpec.getRunnables().containsKey(runnableName)) {
    LOG.info("Unknown runnable {}", runnableName);
    return false;
  }

  final int newCount = Integer.parseInt(options.get("count"));
  final int oldCount = expectedContainers.getExpected(runnableName);

  LOG.info("Received change instances request for {}, from {} to {}.", runnableName, oldCount, newCount);

  if (newCount == oldCount) {   // Nothing to do, simply complete the request.
    completion.run();
    return true;
  }

  instanceChangeExecutor.execute(createSetInstanceRunnable(message, completion, oldCount, newCount));
  return true;
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:36,代码来源:ApplicationMasterService.java

示例13: onReceived

import org.apache.twill.api.Command; //导入依赖的package包/类
@Override
public ListenableFuture<String> onReceived(final String messageId, final Message message) {
  LOG.debug("Message received: {} {}.", messageId, message);

  if (handleSecureStoreUpdate(message)) {
    return Futures.immediateFuture(messageId);
  }

  final SettableFuture<String> result = SettableFuture.create();
  Command command = message.getCommand();
  if (message.getType() == Message.Type.SYSTEM
    && "instances".equals(command.getCommand()) && command.getOptions().containsKey("count")) {
    context.setInstanceCount(Integer.parseInt(command.getOptions().get("count")));
  }

  commandExecutor.execute(new Runnable() {

    @Override
    public void run() {
      try {
        runnable.handleCommand(message.getCommand());
        result.set(messageId);
      } catch (Exception e) {
        result.setException(e);
      }
    }
  });
  return result;
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:30,代码来源:TwillContainerService.java

示例14: testFailureRestart

import org.apache.twill.api.Command; //导入依赖的package包/类
@Test
public void testFailureRestart() throws Exception {
  TwillRunner runner = YarnTestUtils.getTwillRunner();

  ResourceSpecification resource = ResourceSpecification.Builder.with()
    .setVirtualCores(1)
    .setMemory(512, ResourceSpecification.SizeUnit.MEGA)
    .setInstances(2)
    .build();
  TwillController controller = runner.prepare(new FailureRunnable(), resource)
    .withApplicationArguments("failure")
    .withArguments(FailureRunnable.class.getSimpleName(), "failure2")
    .addLogHandler(new PrinterLogHandler(new PrintWriter(System.out, true)))
    .start();

  Iterable<Discoverable> discoverables = controller.discoverService("failure");
  Assert.assertTrue(YarnTestUtils.waitForSize(discoverables, 2, 120));

  // Make sure we see the right instance IDs
  Assert.assertEquals(Sets.newHashSet(0, 1), getInstances(discoverables));

  // Kill server with instanceId = 0
  controller.sendCommand(FailureRunnable.class.getSimpleName(), Command.Builder.of("kill0").build());

  // Make sure the runnable is killed.
  Assert.assertTrue(YarnTestUtils.waitForSize(discoverables, 1, 120));

  // Wait for the restart
  Assert.assertTrue(YarnTestUtils.waitForSize(discoverables, 2, 120));

  // Make sure we see the right instance IDs
  Assert.assertEquals(Sets.newHashSet(0, 1), getInstances(discoverables));

  controller.stopAndWait();
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:36,代码来源:FailureRestartTestRun.java

示例15: testController

import org.apache.twill.api.Command; //导入依赖的package包/类
@Test
public void testController() throws ExecutionException, InterruptedException, TimeoutException {
  InMemoryZKServer zkServer = InMemoryZKServer.builder().build();
  zkServer.startAndWait();

  LOG.info("ZKServer: " + zkServer.getConnectionStr());

  try {
    RunId runId = RunIds.generate();
    ZKClientService zkClientService = ZKClientService.Builder.of(zkServer.getConnectionStr()).build();
    zkClientService.startAndWait();

    Service service = createService(zkClientService, runId);
    service.startAndWait();

    TwillController controller = getController(zkClientService, runId);
    controller.sendCommand(Command.Builder.of("test").build()).get(2, TimeUnit.SECONDS);
    controller.stop().get(2, TimeUnit.SECONDS);

    Assert.assertEquals(ServiceController.State.TERMINATED, controller.state());

    final CountDownLatch terminateLatch = new CountDownLatch(1);
    service.addListener(new ServiceListenerAdapter() {
      @Override
      public void terminated(Service.State from) {
        terminateLatch.countDown();
      }
    }, Threads.SAME_THREAD_EXECUTOR);

    Assert.assertTrue(service.state() == Service.State.TERMINATED || terminateLatch.await(2, TimeUnit.SECONDS));

    zkClientService.stopAndWait();

  } finally {
    zkServer.stopAndWait();
  }
}
 
开发者ID:chtyim,项目名称:incubator-twill,代码行数:38,代码来源:ControllerTest.java


注:本文中的org.apache.twill.api.Command类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。