示例#1
0
  /** @see DynamicMBean#setAttributes */
  public AttributeList setAttributes(AttributeList attributes) {

    /* Sanity checking. */
    if (attributes == null) {
      throw new IllegalArgumentException("attribute list can't be null");
    }

    /* Set each attribute specified. */
    AttributeList results = new AttributeList();
    for (int i = 0; i < attributes.size(); i++) {
      Attribute attr = (Attribute) attributes.get(i);
      try {
        /* Set new value. */
        jeHelper.setAttribute(targetEnv, attr);

        /*
         * Add the name and new value to the result list. Be sure
         * to ask the MBean for the new value, rather than simply
         * using attr.getValue(), because the new value may not
         * be same if it is modified according to the JE
         * implementation.
         */
        String name = attr.getName();
        Object newValue = jeHelper.getAttribute(targetEnv, name);
        results.add(new Attribute(name, newValue));
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    return results;
  }
示例#2
0
  private static boolean checkAttrs(String what, AttributeList attrs) {
    if (attrs.size() != 1) {
      System.out.println(
          "TEST FAILS: list returned by " + what + " does not have size 1: " + attrs);
      return false;
    }
    Attribute attr = (Attribute) attrs.get(0);
    if (!"Exotic".equals(attr.getName())) {
      System.out.println("TEST FAILS: " + what + " returned wrong " + "attribute: " + attr);
      return false;
    }

    return true;
  }
示例#3
0
 public final AttributeList setAttributes(AttributeList attributes) {
   final AttributeList result = new AttributeList(attributes.size());
   for (Object attrObj : attributes) {
     // We can't use AttributeList.asList because it has side-effects
     Attribute attr = (Attribute) attrObj;
     try {
       setAttribute(attr);
       result.add(new Attribute(attr.getName(), attr.getValue()));
     } catch (Exception e) {
       // OK: attribute is not included in returned list, per spec
       // XXX: log the exception
     }
   }
   return result;
 }
  /* ------------------------------------------------------------ */
  public AttributeList setAttributes(AttributeList attrs) {
    log.debug("setAttributes");

    AttributeList results = new AttributeList(attrs.size());
    Iterator iter = attrs.iterator();
    while (iter.hasNext()) {
      try {
        Attribute attr = (Attribute) iter.next();
        setAttribute(attr);
        results.add(new Attribute(attr.getName(), getAttribute(attr.getName())));
      } catch (Exception e) {
        log.warn(LogSupport.EXCEPTION, e);
      }
    }
    return results;
  }
示例#5
0
  public synchronized AttributeList setAttributes(AttributeList list) {
    AttributeList results = new AttributeList();
    for (int i = 0; i < list.size(); i++) {
      Attribute attr = (Attribute) list.get(i);

      if (setNamedAttribute(attr)) {
        results.add(attr);
      } else {
        if (log.isWarnEnabled()) {
          log.warn(
              "Failed to update attribute name "
                  + attr.getName()
                  + " with value "
                  + attr.getValue());
        }
      }
    }
    return results;
  }
 /**
  * Set the service that this configuration wraps
  *
  * @param target the target to set
  */
 public void setTarget(final RifidiService target) {
   if (this.target.compareAndSet(null, target)) {
     if (target != null) {
       // get the whole list of attributes from the target as we might
       // only
       // have a partial list from the config file
       target.setAttributes(attributes);
       // keep a local clone
       attributes = (AttributeList) target.getAttributes().clone();
       nameToPos = new HashMap<String, Integer>();
       List<Attribute> attrs = attributes.asList();
       if (target instanceof AbstractSensor<?>) {
         for (SessionDTO sessionDTO : sessionDTOs.keySet()) {
           try {
             ((AbstractSensor<?>) target).createSensorSession(sessionDTO);
             // test to see if the session should be
             // restarted
             if (shouldStartSession(sessionDTO)) {
               // if it should, restart it
               restartSession((AbstractSensor<?>) target, sessionDTO);
             }
           } catch (CannotCreateSessionException e) {
             logger.error("Cannot Create Session ", e);
           } catch (Exception e) {
             logger.error("Cannot restart session ", e);
           }
         }
       }
       for (int count = 0; count < attributes.size(); count++) {
         nameToPos.put(attrs.get(count).getName(), count);
       }
       jmxService.publish(this);
       return;
     }
     jmxService.unpublish(this);
     return;
   }
   // if the value was already set we got a problem
   logger.warn("Tried to set the target but was already set.");
 }