示例#1
0
  @Override
  protected void preStart() {
    for (final SshPollIdentifier pollInfo : polls.keySet()) {
      Set<SshPollConfig<?>> configs = polls.get(pollInfo);
      long minPeriod = Integer.MAX_VALUE;
      Set<AttributePollHandler<SshPollValue>> handlers = Sets.newLinkedHashSet();

      for (SshPollConfig<?> config : configs) {
        handlers.add(new AttributePollHandler<SshPollValue>(config, entity, this));
        if (config.getPeriod() > 0) minPeriod = Math.min(minPeriod, config.getPeriod());
      }

      getPoller()
          .scheduleAtFixedRate(
              new Callable<SshPollValue>() {
                public SshPollValue call() throws Exception {
                  return exec(pollInfo.command, pollInfo.env);
                }
              },
              new DelegatingPollHandler(handlers),
              minPeriod);
    }
  }
示例#2
0
  protected SshFeed(Builder builder) {
    super(builder.entity);
    machine =
        checkNotNull(
            builder.machine != null ? builder.machine : getMachineOfEntity(builder.entity),
            "machine");
    execAsCommand = builder.execAsCommand;

    for (SshPollConfig<?> config : builder.polls) {
      SshPollConfig<?> configCopy = new SshPollConfig(config);
      if (configCopy.getPeriod() < 0) configCopy.period(builder.period, builder.periodUnits);
      String command = config.getCommand();
      Map<String, String> env = config.getEnv();
      polls.put(new SshPollIdentifier(command, env), configCopy);
    }
  }