コード例 #1
0
ファイル: NCubeManager.java プロジェクト: ccriderGAIG/n-cube
  /**
   * Apply existing advices loaded into the NCubeManager, to the passed in n-cube. This allows
   * advices to be added first, and then let them be applied 'on demand' as an n-cube is loaded
   * later.
   *
   * @param appId ApplicationID
   * @param ncube NCube to which all matching advices will be applied.
   */
  private static void applyAdvices(ApplicationID appId, NCube ncube) {
    final Map<String, Advice> appAdvices = advices.get(appId);

    if (MapUtilities.isEmpty(appAdvices)) {
      return;
    }
    for (Map.Entry<String, Advice> entry : appAdvices.entrySet()) {
      final Advice advice = entry.getValue();
      final String wildcard = entry.getKey().replace(advice.getName() + '/', "");
      final String regex = StringUtilities.wildcardToRegexString(wildcard);
      final Axis axis = ncube.getAxis("method");
      addAdviceToMatchedCube(advice, regex, ncube, axis);
    }
  }
コード例 #2
0
 private void weaving(String caseID, String adviceJoinPointID, boolean isCaseConstraintcalled) {
   AdviceQuery query = new AdviceQuery();
   List<Advice> advs = query.getAdvicesByAdviceJoinPointID(adviceJoinPointID);
   boolean unsuspend = true;
   if ((advs != null) && (advs.size() > 0)) {
     for (Advice adv : advs) {
       if (!adv.isSynched()) {
         unsuspend = false;
       }
     }
   }
   System.out.println("==== ===== " + (advs == null ? "null" : Integer.valueOf(advs.size())));
   if ((unsuspend) || (advs == null) || (advs.size() == 0)) {
     unsuspendCase(caseID);
   }
 }
コード例 #3
0
  private void CasePostConstraint(YSpecificationID specID, String caseID, String data) {
    AdviceQuery query = new AdviceQuery();
    List<Advice> advs = query.getByAdviceCaseID(caseID);
    if ((advs != null) && (advs.size() > 0)) {
      Advice advice = (Advice) advs.get(0);

      System.out.println("==================== advice is finished" + advice.getId());

      this._Persister.beginTransaction();
      this._Persister.delete(advice);
      this._Persister.commit();

      weaving(advice.getParentCaseID(), advice.getAdjpID(), true);
      System.out.println("==================== advice is weaved");
    }
  }
コード例 #4
0
ファイル: NCubeManager.java プロジェクト: ccriderGAIG/n-cube
  /** Associate Advice to all n-cubes that match the passed in regular expression. */
  public static void addAdvice(ApplicationID appId, String wildcard, Advice advice) {
    validateAppId(appId);
    ConcurrentMap<String, Advice> current = advices.get(appId);
    if (current == null) {
      current = new ConcurrentHashMap<>();
      ConcurrentMap<String, Advice> mapRef = advices.putIfAbsent(appId, current);
      if (mapRef != null) {
        current = mapRef;
      }
    }

    current.put(advice.getName() + '/' + wildcard, advice);

    // Apply newly added advice to any fully loaded (hydrated) cubes.
    String regex = StringUtilities.wildcardToRegexString(wildcard);
    Map<String, Object> cubes = getCacheForApp(appId);

    for (Object value : cubes.values()) {
      if (value instanceof NCube) { // apply advice to hydrated cubes
        NCube ncube = (NCube) value;
        Axis axis = ncube.getAxis("method");
        addAdviceToMatchedCube(advice, regex, ncube, axis);
      }
    }
  }
コード例 #5
0
  private void ItemPreConstraint(WorkItemRecord wir, String data) {
    Collection<String> advices = evaluateRule(wir.getSpecURI(), wir.getTaskName(), data);
    if (advices.size() > 0) {
      suspendCase(wir.getCaseID().substring(0, wir.getCaseID().indexOf('.')));
      for (String s : advices) {
        try {
          uploadAdvice(s);

          String res = mapItemParamsToAdviceCaseParams(s, getInputParams(getAdviceID(s)), data);

          Advice advice = new Advice();
          advice.setParentSpecID(wir.getSpecIdentifier());
          advice.setParentSpecName(wir.getSpecURI());
          advice.setParentCaseID(wir.getCaseID().substring(0, wir.getCaseID().indexOf('.')));

          advice.setAdjpID(wir.getID());
          advice.setAdjpDataString(data);
          advice.setAdviceName(s);

          advice.setSynched(false);

          this._Persister.beginTransaction();
          this._Persister.insert(advice);
          this._Persister.commit();

          String adviceCaseID = launchAdvice(getAdviceID(s), res);

          advice.setAdviceCaseID(adviceCaseID);

          this._Persister.beginTransaction();
          this._Persister.update(advice);
          this._Persister.commit();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
コード例 #6
0
  private void ItemPostConstraint(WorkItemRecord wir, String data) {
    AdviceQuery query = new AdviceQuery();

    List<Advice> advs = query.getAdvicesByAdviceJoinPointID(wir.getID());
    if ((advs != null) && (advs.size() > 0)) {
      suspendCase(wir.getCaseID().substring(0, wir.getCaseID().indexOf('.')));
      System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
      System.out.println(
          "suspended case is " + wir.getCaseID().substring(0, wir.getCaseID().indexOf('.')));
      for (Advice advice : advs) {
        SAXBuilder builder = new SAXBuilder();

        List<org.jdom2.Element> ls = null;
        org.jdom2.Element root = null;
        try {
          org.jdom2.Document document = builder.build(new StringReader(data));
          ls = document.getRootElement().getChildren();
        } catch (Exception e) {
          System.out.println(e);
        }
        String s = "<" + advice.getProceedName() + ">";
        for (org.jdom2.Element l : ls) {
          s = s + "<" + l.getName() + ">" + l.getText() + "</" + l.getName() + ">";
        }
        s = s + "</" + advice.getProceedName() + ">";

        connect();

        advice.setSynched(false);
        this._Persister.beginTransaction();
        this._Persister.update(advice);
        this._Persister.commit();

        System.out.println(
            "*** try to checkin workitem with proceed id of "
                + advice.getProceedID()
                + " - with data: "
                + s);
        try {
          _ibClient.checkInWorkItem(advice.getProceedID(), s, "", _handle);
        } catch (IOException e) {
          System.out.println("************************ problem in checkin");
          e.printStackTrace();
        }
      }
    }
  }
コード例 #7
0
  private void handleProceedPlaceholder(WorkItemRecord enabledWorkItem) {
    connect();
    try {
      WorkItemRecord childWorkItem = checkOut(enabledWorkItem.getID(), _handle);
      AdviceQuery query = new AdviceQuery();

      List<Advice> advs = query.getByAdviceName(enabledWorkItem.getSpecURI());
      System.out.println(">>>> Number of the same advices are " + advs.size());
      if ((advs != null) && (advs.size() > 0)) {
        System.out.println(">>>> Number of the launched advices are " + advs.size());
        do {
          advs = query.getByAdviceCaseID(enabledWorkItem.getCaseID());
        } while ((advs == null) || (advs.size() == 0));
        System.out.println(">>>> Number of the launched advices are " + advs.size());

        Advice advice = (Advice) advs.get(0);
        advice.setSynched(true);
        advice.setProceedName(enabledWorkItem.getTaskName());
        advice.setProceedID(childWorkItem.getID());

        this._Persister.beginTransaction();
        this._Persister.update(advice);
        this._Persister.commit();

        System.out.println(">>>> Proceed Name is " + advice.getProceedName());
        System.out.println(">>>> Proceed ID is " + advice.getProceedID());

        org.jdom2.Element d =
            getDataforCase(
                advice.getParentSpecName(),
                advice.getParentCaseID(),
                _ibClient.getCaseData(enabledWorkItem.getCaseID(), _handle));

        this._ixClient.updateCaseData(advice.getParentCaseID(), d, _handle);

        weaving(advice.getParentCaseID(), advice.getAdjpID(), false);
      }
    } catch (IOException | YAWLException e) {
      e.printStackTrace();
    }
  }
コード例 #8
0
 public void addToWorld(int Y, World mundo) {
   mundo.addObject(nombre, 110 + (nombre.getImage().getWidth() / 2), Y);
   mundo.addObject(puntos, 420 + (puntos.getImage().getWidth() / 2), Y);
 }