Exemplo n.º 1
0
 @Override
 public void processModule(Module module, String group, int index) {
   String type = module.getType();
   if (("source".equals(type) || "processor".equals(type) || "sink".equals(type))
       && group != null) {
     this.registerChannels(module.getComponents(MessageChannel.class), group, index);
     this.configureProperties(module, group);
   }
 }
Exemplo n.º 2
0
  /**
   * Processes a new {@link Trigger} being added. Currently, it supports adding {@link
   * CronTrigger}s. The {@link Trigger} is added to the common {@link
   * ConfigurableApplicationContext}.
   */
  @Override
  public void preProcessModule(Module module) {
    if (!TRIGGER.equals(module.getType())) {
      return;
    }
    Assert.notNull(
        commonApplicationContext, "The 'commonApplicationContext' property must not be null.");

    Map<String, Trigger> triggers = new HashMap<String, Trigger>();
    if (module.getProperties().containsKey(TriggerType.cron.name())) {
      Trigger trigger =
          new CronTrigger(module.getProperties().getProperty(TriggerType.cron.name()));
      triggers.put(TriggerType.cron.name(), trigger);
    }
    if (module.getProperties().containsKey(TriggerType.fixedDelay.name())) {
      Trigger trigger =
          new PeriodicTrigger(
              Long.parseLong(module.getProperties().getProperty(TriggerType.fixedDelay.name())));
      triggers.put(TriggerType.fixedDelay.name(), trigger);
    }
    if (module.getProperties().containsKey(TriggerType.fixedRate.name())) {
      PeriodicTrigger trigger =
          new PeriodicTrigger(
              Long.parseLong(module.getProperties().getProperty(TriggerType.fixedRate.name())));
      trigger.setFixedRate(true);
      triggers.put(TriggerType.fixedRate.name(), trigger);
    }
    if (triggers.size() == 0) {
      throw new ResourceDefinitionException(
          "No valid trigger property. Expected one of: cron, fixedDelay or fixedRate");
    } else if (triggers.size() > 1) {
      throw new ResourceDefinitionException(
          "Only one trigger property allowed, but received: "
              + StringUtils.collectionToCommaDelimitedString(triggers.keySet()));
    }
    commonApplicationContext
        .getBeanFactory()
        .registerSingleton(makeTriggerBeanName(module), triggers.values().iterator().next());
    configureProperties(module);
  }