Ejemplo n.º 1
0
  public Activator init(
      String name,
      Map<String, List<Condition>> subscriptionCondition,
      JsonObject settings,
      Cell caller)
      throws Exception {
    this.name = name;
    this.caller = caller;

    // Add subscription from children to the list if there are any

    // Set conditions and
    subscriptionCondition
        .entrySet()
        .forEach(
            (Entry<String, List<Condition>> e) -> {

              // Create an activator condition
              List<ActivatorConditionManager> conditionManagerList =
                  new LinkedList<ActivatorConditionManager>();
              e.getValue()
                  .forEach(
                      (Condition c) -> {
                        // Create new condition manager from mapping
                        ActivatorConditionManager conditionManager =
                            new ActivatorConditionManager(c, e.getKey());
                        conditionManagerList.add(conditionManager);
                      });

              subscriptionConditionMapping.put(e.getKey(), conditionManagerList);

              // Subscribe datapoint
              this.caller.getDataStorage().subscribeDatapoint(e.getKey(), caller.getName());
            });

    // Count table
    this.conditionMaxCount = calculateTotalCount(subscriptionCondition);

    // Add and activate behavior
    // INFO: Instead of letting the caller add the jade behavior, the cell behavior adds itself
    behavior.addBehaviourToCallerCell(caller);

    // Read the initial value from the datapoint to trigger the conditions, especially the always
    // true conditions
    log.trace(
        "{}>Initialize all conditions, by testing them with their subscribed data", this.name);
    subscriptionCondition
        .entrySet()
        .forEach(
            (Entry<String, List<Condition>> e) -> {
              this.runActivation(this.caller.getDataStorage().read(e.getKey()));
            });

    log.trace("{}> initialization finished", this.name);

    return this;
  }
Ejemplo n.º 2
0
 @Override
 public String toString() {
   StringBuilder builder = new StringBuilder();
   builder.append("name=");
   builder.append(name);
   builder.append(", behavior=");
   builder.append(function.getFunctionName());
   builder.append(", caller=");
   builder.append(caller.getLocalName());
   builder.append(", conditions=");
   builder.append(subscriptionConditionMapping);
   return builder.toString();
 }