Esempio n. 1
0
  public synchronized ContextControllerInstanceHandle contextPartitionInstantiate(
      Integer optionalContextPartitionId,
      int pathId,
      ContextController originator,
      EventBean optionalTriggeringEvent,
      Map<String, Object> optionalTriggeringPattern,
      Object partitionKey,
      Map<String, Object> contextProperties,
      ContextControllerState states,
      ContextInternalFilterAddendum filterAddendum,
      boolean isRecoveringResilient) {

    // assign context id
    int assignedContextId;
    if (optionalContextPartitionId != null) {
      assignedContextId = optionalContextPartitionId;
      contextPartitionIdManager.addExisting(optionalContextPartitionId);
    } else {
      assignedContextId = contextPartitionIdManager.allocateId();
    }

    // handle leaf creation
    List<AgentInstance> newInstances = new ArrayList<AgentInstance>();
    for (Map.Entry<String, ContextControllerStatementDesc> statementEntry : statements.entrySet()) {
      ContextControllerStatementDesc statementDesc = statementEntry.getValue();
      AgentInstance instance =
          startStatement(
              assignedContextId,
              statementDesc,
              originator,
              partitionKey,
              contextProperties,
              isRecoveringResilient);
      newInstances.add(instance);
    }

    // for all new contexts: evaluate this event for this statement
    if (optionalTriggeringEvent != null || optionalTriggeringPattern != null) {
      for (AgentInstance context : newInstances) {
        StatementAgentInstanceUtil.evaluateEventForStatement(
            servicesContext,
            optionalTriggeringEvent,
            optionalTriggeringPattern,
            context.getAgentInstanceContext());
      }
    }

    // save leaf
    long filterVersion = servicesContext.getFilterService().getFiltersVersion();
    agentInstances.put(
        assignedContextId,
        new ContextControllerTreeAgentInstanceList(
            filterVersion, partitionKey, contextProperties, newInstances));

    // update the filter version for this handle
    factory
        .getFactoryContext()
        .getAgentInstanceContextCreate()
        .getEpStatementAgentInstanceHandle()
        .getStatementFilterVersion()
        .setStmtFilterVersion(filterVersion);

    return new ContextNestedHandleImpl(assignedContextId);
  }