示例#1
0
  /**
   * Returns a string representation of this state using only observable object instances.
   *
   * @return a string representation of this state using only observable object instances.
   */
  public String getStateDescription() {

    String desc = "";
    for (ObjectInstance o : objectInstances) {
      desc = desc + o.getObjectDescription() + "\n";
    }

    return desc;
  }
示例#2
0
 private List<ObjectInstance> objectListDifference(
     List<ObjectInstance> objects, List<String> toRemove) {
   List<ObjectInstance> remaining = new ArrayList<ObjectInstance>(objects.size());
   for (ObjectInstance oi : objects) {
     String oname = oi.getName();
     if (!toRemove.contains(oname)) {
       remaining.add(oi);
     }
   }
   return remaining;
 }
示例#3
0
  /**
   * Initializes this state as a deep copy of the object instances in the provided source state s
   *
   * @param s the source state from which this state will be initialized.
   */
  public State(State s) {

    this.initDataStructures();

    for (ObjectInstance o : s.objectInstances) {
      this.addObject(o.copy());
    }

    for (ObjectInstance o : s.hiddenObjectInstances) {
      this.addObject(o.copy());
    }
  }
示例#4
0
  private List<ObjectInstance> objectsMatchingClass(List<ObjectInstance> sourceObs, String cname) {

    List<ObjectInstance> res = new ArrayList<ObjectInstance>(sourceObs.size());

    for (ObjectInstance o : sourceObs) {

      if (o.getTrueClassName().equals(cname)) {
        res.add(o);
      }
    }

    return res;
  }
  @Override
  public List<CamelProcessorMBean> getProcessors(String managementName) throws Exception {
    String id = managementName != null ? managementName : camelContextManagementName;

    ObjectName query =
        ObjectName.getInstance("org.apache.camel:context=" + id + ",type=processors,*");

    Set<ObjectInstance> names = queryNames(query, null);
    List<CamelProcessorMBean> answer = new ArrayList<CamelProcessorMBean>();
    for (ObjectInstance on : names) {
      CamelProcessorMBean processor;
      if (ManagedSendProcessor.class.getName().equals(on.getClassName())) {
        processor =
            (CamelProcessorMBean)
                newProxyInstance(on.getObjectName(), CamelSendProcessorMBean.class, true);
      } else if (ManagedDelayer.class.getName().equals(on.getClassName())) {
        processor =
            (CamelProcessorMBean)
                newProxyInstance(on.getObjectName(), CamelDelayProcessorMBean.class, true);
      } else if (ManagedThrottler.class.getName().equals(on.getClassName())) {
        processor =
            (CamelProcessorMBean)
                newProxyInstance(on.getObjectName(), CamelThrottleProcessorMBean.class, true);
      } else {
        processor =
            (CamelProcessorMBean)
                newProxyInstance(on.getObjectName(), CamelProcessorMBean.class, true);
      }
      answer.add(processor);
    }
    return answer;
  }
示例#6
0
文件: Q2.java 项目: rlishtaba/jPOS
 private void start(ObjectInstance instance) {
   try {
     factory.startQBean(this, instance.getObjectName());
   } catch (Exception e) {
     getLog().warn("start", e);
   }
 }
示例#7
0
  @Override
  public boolean equals(Object other) {

    if (this == other) {
      return true;
    }

    if (!(other instanceof State)) {
      return false;
    }

    State so = (State) other;

    if (this.numTotalObjets() != so.numTotalObjets()) {
      return false;
    }

    Set<String> matchedObjects = new HashSet<String>();
    for (List<ObjectInstance> objects : objectIndexByTrueClass.values()) {

      String oclass = objects.get(0).getTrueClassName();
      List<ObjectInstance> oobjects = so.getObjectsOfTrueClass(oclass);
      if (objects.size() != oobjects.size()) {
        return false;
      }

      for (ObjectInstance o : objects) {
        boolean foundMatch = false;
        for (ObjectInstance oo : oobjects) {
          String ooname = oo.getName();
          if (matchedObjects.contains(ooname)) {
            continue;
          }
          if (o.valueEquals(oo)) {
            foundMatch = true;
            matchedObjects.add(ooname);
            break;
          }
        }
        if (!foundMatch) {
          return false;
        }
      }
    }

    return true;
  }
  @Override
  public List<CamelThreadPoolMBean> getThreadPools(String managementName) throws Exception {
    String id = managementName != null ? managementName : camelContextManagementName;

    ObjectName query =
        ObjectName.getInstance("org.apache.camel:context=" + id + ",type=threadpools,*");

    Set<ObjectInstance> names = queryNames(query, null);
    List<CamelThreadPoolMBean> answer = new ArrayList<CamelThreadPoolMBean>();
    for (ObjectInstance on : names) {
      CamelThreadPoolMBean pool =
          (CamelThreadPoolMBean)
              newProxyInstance(on.getObjectName(), CamelThreadPoolMBean.class, true);
      answer.add(pool);
    }
    return answer;
  }
  @Override
  public List<CamelEndpointMBean> getEndpoints(String managementName) throws Exception {
    String id = managementName != null ? managementName : camelContextManagementName;

    ObjectName query =
        ObjectName.getInstance("org.apache.camel:context=" + id + ",type=endpoints,*");

    Set<ObjectInstance> names = queryNames(query, null);
    List<CamelEndpointMBean> answer = new ArrayList<CamelEndpointMBean>();
    for (ObjectInstance on : names) {
      CamelEndpointMBean endpoint;
      if (ManagedBrowsableEndpoint.class.getName().equals(on.getClassName())
          || SedaEndpoint.class.getName().equals(on.getClassName())) {
        endpoint =
            (CamelEndpointMBean)
                newProxyInstance(on.getObjectName(), CamelBrowsableEndpointMBean.class, true);
      } else if (on.getClassName().startsWith("org.apache.camel.component.jms")) {
        // special for JMS endpoints as they are browsable as well
        endpoint =
            (CamelEndpointMBean)
                newProxyInstance(on.getObjectName(), CamelBrowsableEndpointMBean.class, true);
      } else {
        endpoint =
            (CamelEndpointMBean)
                newProxyInstance(on.getObjectName(), CamelEndpointMBean.class, true);
      }
      answer.add(endpoint);
    }
    return answer;
  }
示例#10
0
  /**
   * Adds object instance o to this state.
   *
   * @param o the object instance to be added to this state.
   */
  public void addObject(ObjectInstance o) {

    String oname = o.getName();

    if (objectMap.containsKey(oname)) {
      return; // don't add an object that conflicts with another object of the same name
    }

    objectMap.put(oname, o);

    if (o.getObjectClass().hidden) {
      hiddenObjectInstances.add(o);
    } else {
      objectInstances.add(o);
    }

    this.addObjectClassIndexing(o);
  }
  @Override
  public ManagedBacklogTracerMBean getCamelTracer(String managementName) throws Exception {
    String id = managementName != null ? managementName : camelContextManagementName;

    ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + id + ",type=tracer,*");

    Set<ObjectInstance> names = queryNames(query, null);
    for (ObjectInstance on : names) {
      if (on.getClassName().equals("org.apache.camel.management.mbean.ManagedBacklogTracer")) {
        ManagedBacklogTracerMBean tracer =
            (ManagedBacklogTracerMBean)
                newProxyInstance(on.getObjectName(), ManagedBacklogTracerMBean.class, true);
        return tracer;
      }
    }

    // tracer not found
    return null;
  }
示例#12
0
  /**
   * Removes the object instance o from this state.
   *
   * @param o the object instance to remove from this state.
   */
  public void removeObject(ObjectInstance o) {
    if (o == null) {
      return;
    }

    String oname = o.getName();

    if (!objectMap.containsKey(oname)) {
      return; // make sure we're removing something that actually exists in this state!
    }

    if (o.getObjectClass().hidden) {
      hiddenObjectInstances.remove(o);
    } else {
      objectInstances.remove(o);
    }

    objectMap.remove(oname);

    this.removeObjectClassIndexing(o);
  }
  @Override
  public List<CamelRouteMBean> getRoutes(String managementName) throws Exception {
    String id = managementName != null ? managementName : camelContextManagementName;

    ObjectName query = ObjectName.getInstance("org.apache.camel:context=" + id + ",type=routes,*");

    Set<ObjectInstance> names = queryNames(query, null);
    List<CamelRouteMBean> answer = new ArrayList<CamelRouteMBean>();
    for (ObjectInstance on : names) {
      CamelRouteMBean route;
      if (ManagedSuspendableRoute.class.getName().equals(on.getClassName())) {
        route =
            (CamelRouteMBean)
                newProxyInstance(on.getObjectName(), CamelSuspendableRouteMBean.class, true);
      } else {
        route = (CamelRouteMBean) newProxyInstance(on.getObjectName(), CamelRouteMBean.class, true);
      }
      answer.add(route);
    }
    return answer;
  }
示例#14
0
  private void removeObjectClassIndexing(ObjectInstance o) {

    String otclass = o.getTrueClassName();
    List<ObjectInstance> classTList = objectIndexByTrueClass.get(otclass);

    // if this index has more than one entry, then we can just remove from it and be done
    if (classTList.size() > 1) {
      classTList.remove(o);
    } else {
      // otherwise we have to remove class entries for it
      objectIndexByTrueClass.remove(otclass);
    }
  }
示例#15
0
  private void addObjectClassIndexing(ObjectInstance o) {

    String otclass = o.getTrueClassName();

    // manage true indexing
    if (objectIndexByTrueClass.containsKey(otclass)) {
      objectIndexByTrueClass.get(otclass).add(o);
    } else {

      ArrayList<ObjectInstance> classList = new ArrayList<ObjectInstance>();
      classList.add(o);
      objectIndexByTrueClass.put(otclass, classList);
    }
  }
  @Override
  public List<CamelConsumerMBean> getConsumers(String managementName) throws Exception {
    String id = managementName != null ? managementName : camelContextManagementName;

    ObjectName query =
        ObjectName.getInstance("org.apache.camel:context=" + id + ",type=consumers,*");

    Set<ObjectInstance> names = queryNames(query, null);
    List<CamelConsumerMBean> answer = new ArrayList<CamelConsumerMBean>();
    for (ObjectInstance on : names) {
      CamelConsumerMBean consumer;
      if (ManagedScheduledPollConsumer.class.getName().equals(on.getClassName())) {
        consumer =
            (CamelConsumerMBean)
                newProxyInstance(on.getObjectName(), CamelScheduledPollConsumerMBean.class, true);
      } else {
        consumer =
            (CamelConsumerMBean)
                newProxyInstance(on.getObjectName(), CamelConsumerMBean.class, true);
      }
      answer.add(consumer);
    }
    return answer;
  }
示例#17
0
  /**
   * This method computes a matching from objects in the receiver to value-identical objects in the
   * parameter state so. The matching is returned as a map from the object names in the receiving
   * state to the matched objects in state so. If enforceStateExactness is set to true, then the
   * returned matching will be an empty map if the two states are not OO-MDP-wise identical (i.e.,
   * if there is a not a bijection between value-identical objects of the two states). If
   * enforceExactness is false and the states are not identical, the the method will return the
   * largest matching between objects that can be made.
   *
   * @param so the state to whose objects the receiving state's objects should be matched
   * @param enforceStateExactness whether to require that states are identical to return a matching
   * @return a matching from this receiving state's objects to objects in so that have identical
   *     values.
   */
  public Map<String, String> getObjectMatchingTo(State so, boolean enforceStateExactness) {

    Map<String, String> matching = new HashMap<String, String>();

    if (this.numTotalObjets() != so.numTotalObjets() && enforceStateExactness) {
      return new HashMap<String, String>(); // states are not equal and therefore cannot be matched
    }

    Set<String> matchedObs = new HashSet<String>();

    for (List<ObjectInstance> objects : objectIndexByTrueClass.values()) {

      String oclass = objects.get(0).getTrueClassName();
      List<ObjectInstance> oobjects = so.getObjectsOfTrueClass(oclass);
      if (objects.size() != oobjects.size() && enforceStateExactness) {
        return new HashMap<
            String, String>(); // states are not equal and therefore cannot be matched
      }

      for (ObjectInstance o : objects) {
        boolean foundMatch = false;
        for (ObjectInstance oo : oobjects) {
          if (matchedObs.contains(oo.getName())) {
            continue; // already matched this one; check another
          }
          if (o.valueEquals(oo)) {
            foundMatch = true;
            matchedObs.add(oo.getName());
            matching.put(o.getName(), oo.getName());
            break;
          }
        }
        if (!foundMatch && enforceStateExactness) {
          return new HashMap<
              String, String>(); // states are not equal and therefore cannot be matched
        }
      }
    }

    return matching;
  }
示例#18
0
文件: Q2.java 项目: rlishtaba/jPOS
 public ObjectName getObjectName() {
   return instance != null ? instance.getObjectName() : null;
 }
示例#19
0
 /**
  * Renames the identifier for the object instance currently named originalName with the name
  * newName.
  *
  * @param originalName the original name of the object instance to be renamed in this state
  * @param newName the new name of the object instance
  */
 public void renameObject(String originalName, String newName) {
   ObjectInstance o = objectMap.get(originalName);
   o.setName(newName);
   objectMap.remove(originalName);
   objectMap.put(newName, o);
 }
示例#20
0
 /**
  * Renames the identifier for object instance o in this state to newName.
  *
  * @param o the object instance to rename in this state
  * @param newName the new name of the object instance
  */
 public void renameObject(ObjectInstance o, String newName) {
   String originalName = o.getName();
   o.setName(newName);
   objectMap.remove(originalName);
   objectMap.put(newName, o);
 }