Пример #1
0
  /**
   * Update the waiting threads according to the wakeup reason (dispatched element). The
   * corresponding waiting activity/thread is notified.
   */
  public void updateWaitingThreads() {
    if (waittimes != null) {
      //			IClockService clock =
      // (IClockService)interpreter.getServiceProvider().getService(IClockService.class);

      IClockService clock = interpreter.getClockService();
      for (Iterator it = waittimes.keySet().iterator(); it.hasNext(); ) {
        ProcessThread thread = (ProcessThread) it.next();
        if (((Number) waittimes.get(thread)).longValue() <= clock.getTime()) {
          it.remove();
          assert thread.isWaiting();
          BpmnPlanBodyInstance.this.notify(
              thread.getActivity(),
              thread,
              AbstractEventIntermediateTimerActivityHandler.TIMER_EVENT);
        }
      }
    }

    Object dispelem = state.getAttributeValue(rplan, OAVBDIRuntimeModel.plan_has_dispatchedelement);
    //		System.out.println("dispatched: "+dispelem);

    if (dispelem != null) {
      for (Iterator it = context.getAllThreads().iterator(); it.hasNext(); ) {
        ProcessThread thread = (ProcessThread) it.next();
        try {
          if (thread.isWaiting() && thread.getWaitFilter().filter(dispelem)) {
            BpmnPlanBodyInstance.this.notify(thread.getActivity(), thread, getFlyweight(dispelem));
          }
        } catch (Exception e) {
          // just catch filter exceptions.
        }
      }
    }
  }
Пример #2
0
 /** Must be called on process execution thread! Gets infos about the current threads. */
 protected ProcessThreadInfo[] getThreadInfos() {
   List ret = null;
   ThreadContext tc = instance.getThreadContext();
   Set threads = tc.getAllThreads();
   if (threads != null) {
     ret = new ArrayList();
     for (Iterator it = threads.iterator(); it.hasNext(); ) {
       ProcessThread pt = (ProcessThread) it.next();
       ret.add(
           new ProcessThreadInfo(
               pt.getId(),
               pt.getActivity(), // pt.getLastEdge(),
               pt.getException(),
               pt.isWaiting(),
               pt.getData() == null ? new HashMap() : new HashMap(pt.getData())));
     }
   }
   return (ProcessThreadInfo[]) ret.toArray(new ProcessThreadInfo[ret.size()]);
 }
Пример #3
0
  /**
   * Get the cumulated wait abstraction for all threads.
   *
   * @return The wait abstraction.
   */
  public Object getWaitAbstraction() {
    Object ret = null;
    String pool = getPool(getLastState());
    if (!POOL_UNDEFINED.equals(pool)) {
      ret = getState().createObject(OAVBDIRuntimeModel.waitabstraction_type);
      boolean empty = true;

      for (Iterator it = context.getAllThreads().iterator(); it.hasNext(); ) {
        ProcessThread pt = (ProcessThread) it.next();
        if (pt.isWaiting() && pt.belongsTo(pool, null)) {
          MActivity act = pt.getActivity();
          if (MBpmnModel.EVENT_INTERMEDIATE_MESSAGE.equals(act.getActivityType())) {
            String type = (String) pt.getWaitInfo();
            if (type == null) throw new RuntimeException("Message type not specified: " + type);
            SFlyweightFunctionality.addMessageEvent(ret, type, state, rcapa);
            empty = false;
          } else if (MBpmnModel.EVENT_INTERMEDIATE_SIGNAL.equals(act.getActivityType())) {
            String type = (String) pt.getWaitInfo();
            if (type == null)
              throw new RuntimeException("Internal event type not specified: " + type);
            SFlyweightFunctionality.addInternalEvent(ret, type, state, rcapa);
            empty = false;
          } else if (MBpmnModel.EVENT_INTERMEDIATE_RULE.equals(act.getActivityType())) {
            String type = (String) pt.getWaitInfo();
            if (type == null) throw new RuntimeException("Rule type not specified: " + type);
            SFlyweightFunctionality.addCondition(ret, type, state, rcapa);
            empty = false;
          } else if (MBpmnModel.EVENT_INTERMEDIATE_MULTIPLE.equals(act.getActivityType())) {
            List edges = pt.getActivity().getOutgoingSequenceEdges();
            Object[] was = (Object[]) pt.getWaitInfo();

            for (int i = 0; i < edges.size(); i++) {
              MSequenceEdge edge = (MSequenceEdge) edges.get(i);
              MActivity nextact = edge.getTarget();
              if (MBpmnModel.EVENT_INTERMEDIATE_MESSAGE.equals(nextact.getActivityType())) {
                String type = (String) was[i];
                if (type == null) throw new RuntimeException("Message type not specified: " + type);
                SFlyweightFunctionality.addMessageEvent(ret, type, state, rcapa);
                empty = false;
              } else if (MBpmnModel.EVENT_INTERMEDIATE_SIGNAL.equals(nextact.getActivityType())) {
                String type = (String) was[i];
                if (type == null)
                  throw new RuntimeException("Internal event type not specified: " + type);
                SFlyweightFunctionality.addInternalEvent(ret, type, state, rcapa);
                empty = false;
              } else if (MBpmnModel.EVENT_INTERMEDIATE_RULE.equals(nextact.getActivityType())) {
                String type = (String) was[i];
                if (type == null) throw new RuntimeException("Rule type not specified: " + type);
                SFlyweightFunctionality.addCondition(ret, type, state, rcapa);
                empty = false;
              } else if (MBpmnModel.EVENT_INTERMEDIATE_TIMER.equals(nextact.getActivityType())) {
                // nothing to do with waitqueue.
              } else {
                throw new RuntimeException("Unknown event: " + nextact);
              }
            }
          }

          // todo: condition wait

          // todo: time wait?!
        }
      }

      if (empty) {
        state.dropObject(ret);
        ret = null;
      }
    }

    return ret;
  }