public static void performTransition(
      ActivityInstanceBean activityInstance, TransitionTarget transitionTarget, boolean complete) {
    ExecutionPlan plan = new ExecutionPlan(transitionTarget);
    plan.assertNoOtherActiveActivities();

    ModelManager mm = ModelManagerFactory.getCurrent();
    IActivity target =
        mm.findActivity(transitionTarget.getModelOid(), transitionTarget.getActivityRuntimeOid());
    if (target == null) {
      throw new ObjectNotFoundException(
          BpmRuntimeError.MDL_UNKNOWN_ACTIVITY_IN_MODEL.raise(
              transitionTarget.getActivityRuntimeOid(), transitionTarget.getModelOid()));
    }

    BpmRuntimeEnvironment rtEnv = PropertyLayerProviderInterceptor.getCurrent();
    ExecutionPlan oldPlan = rtEnv.getExecutionPlan();
    try {
      rtEnv.setExecutionPlan(plan);
      if (complete) {
        ActivityInstanceUtils.complete(activityInstance, null, null, true);
      } else {
        long rootOid = plan.getRootActivityInstanceOid();
        if (rootOid != activityInstance.getOID()) {
          activityInstance = ActivityInstanceUtils.lock(rootOid);
        }
        ActivityInstanceUtils.abortActivityInstance(activityInstance);
      }
    } finally {
      rtEnv.setExecutionPlan(oldPlan);
    }
  }
Ejemplo n.º 2
0
 @Override
 public Collection<IDaemon> getDaemons() {
   List<IModel> models = ModelManagerFactory.getCurrent().findActiveModels();
   if (!models.isEmpty()) {
     Set<String> ids = CollectionUtils.newSet();
     List<IDaemon> daemons = CollectionUtils.newList();
     for (IModel model : models) {
       // Compute and store the model dependent daemons in model for faster lookup
       List<IDaemon> modelDependentDaemons;
       synchronized (model) {
         modelDependentDaemons =
             (List<IDaemon>) model.getRuntimeAttribute(CACHED_DAEMON_FACTORY);
         if (modelDependentDaemons == null) {
           modelDependentDaemons = CollectionUtils.newList();
           for (Iterator i = model.getAllTriggerTypes(); i.hasNext(); ) {
             ITriggerType type = (ITriggerType) i.next();
             if (type.isPullTrigger()) {
               modelDependentDaemons.add(new TriggerDaemon(type));
             }
           }
           model.setRuntimeAttribute(CACHED_DAEMON_FACTORY, modelDependentDaemons);
         }
       }
       // Compute union of all daemons
       // This always has to be computed as the daemons of a model might change
       // if new model version is deployed
       for (IDaemon daemon : modelDependentDaemons) {
         String type = daemon.getType();
         if (!ids.contains(type)) {
           daemons.add(daemon);
           ids.add(type);
         }
       }
     }
     return daemons;
   }
   return Collections.emptyList();
 }