예제 #1
0
파일: Server.java 프로젝트: hlambertOld/ctk
  /**
   * This method stores the attribute name values, both in persistent storage and in local storage.
   *
   * @param atts AttributeNameValues to store
   */
  public void storeAttributeNameValues(Attributes atts) {
    store(atts);

    AttributeNameValue time = atts.getAttributeNameValue(TIMESTAMP);
    long timestamp = 0;
    if (time != null) {
      Long l = new Long((String) time.getValue());
      if (l != null) timestamp = l.longValue();
      else {
        System.out.println("ERROR: in <storeAttributeNameValues> timestamp null");
      }
    }

    for (int i = 0; i < atts.numAttributes(); i++) {
      AttributeNameValue attNew = (AttributeNameValue) atts.getAttributeAt(i);
      String attName = attNew.getName();
      Object o = attributesTimes.get(attName);
      long storedTime = -1;
      if (o != null) storedTime = ((Long) o).longValue();
      else System.out.println("ERROR: in <storeAttributeNameValues> storedTime null");
      if (storedTime != -1 && storedTime <= timestamp) {
        AttributeNameValue attOld = attributesCache.getAttributeNameValue(attName);
        attOld.setValue(attNew.getValue());
      }
    }
  }
예제 #2
0
파일: Server.java 프로젝트: hlambertOld/ctk
  /**
   * This method is called to aggregate the list of constant attributes that the widgets relevant to
   * this server provide. This should be called after a constructor sets the widget handles to use
   * or after setWidgets() has been called.
   *
   * @return AttributeNameValues the server constant attributes
   */
  protected Attributes initConstantAttributes() {
    // this protects us against the Widget constructor
    // that calls us too early (we havent' got the widgets yet)
    // it's good practice anyway
    if (widgets == null) {
      return null;
    }

    Attributes atts = new Attributes();
    for (int i = 0; i < widgets.size(); i++) {
      WidgetHandle handle = widgets.getWidgetHandleAt(i);

      DataObject widgetAtts =
          getWidgetConstantAttributes(handle.getHostName(), handle.getPort(), handle.getId());
      String error = new Error(widgetAtts).getError();
      if (error != null) {
        if (error.equals(Error.NO_ERROR)) {
          Attributes wAtts = new Attributes(widgetAtts);
          for (int j = 0; j < wAtts.numAttributes(); j++) {
            AttributeNameValue wAtt = (AttributeNameValue) wAtts.getAttributeAt(j);
            if (atts.getAttributeNameValue(wAtt.getName()) == null) {
              atts.addAttributeNameValue(wAtt);
            }
          }
        }
      }
    }

    atts.addAttributes(setServerConstantAttributes());

    return atts;
  }
예제 #3
0
 /**
  * This method checks the list of incoming attributes to ensure that the interpreter can handle
  * these attributes.
  *
  * @param inAtts List of incoming attributes to check
  * @return whether the list of attributes is valid
  */
 private boolean canHandle(Attributes inAtts) {
   for (int i = 0; i < inAtts.numAttributes(); i++) {
     Attribute inAtt = inAtts.getAttributeAt(i);
     if (!isInAttribute(inAtt.getName())) {
       return false;
     }
   }
   return true;
 }
예제 #4
0
파일: Server.java 프로젝트: hlambertOld/ctk
  /**
   * This method runs a query on a widget, asking for either it's latest acquired data (QUERY) or
   * asking for the widget to acquire and return new data (UPDATE_AND_QUERY). Currently, it deals
   * with QUERY and UPDATE_AND_QUERY in exactly the same way.
   *
   * @param query DataObject containing the query request
   * @param update Whether or not to acquire new data
   * @param error String containing the incoming error value
   * @return DataObject containing the reply to the query
   */
  protected DataObject queryWidget(DataObject query, boolean update, String error) {
    System.out.println(query);
    DataObject result = null;
    Vector v = new Vector();
    if (update) {
      result = new DataObject(UPDATE_AND_QUERY_REPLY, v);
    } else {
      result = new DataObject(QUERY_REPLY, v);
    }

    Attributes atts = new Attributes(query);
    Error err = new Error(error);
    if (err.getError() == null) {
      if (atts == null) {
        err.setError(Error.MISSING_PARAMETER_ERROR);
      } else if (!canHandle(atts)) {
        err.setError(Error.INVALID_ATTRIBUTE_ERROR);
      }
    }

    if (err.getError() == null) {
      Attributes subset = attributesCache.getSubset(atts);
      if (subset.numAttributes() == 0) {
        err.setError(Error.INVALID_DATA_ERROR);
      } else {
        v.addElement(subset.toDataObject());
        if (subset.numAttributes() >= atts.numAttributes()) {
          err.setError(Error.NO_ERROR);
        } else {
          err.setError(Error.INCOMPLETE_DATA_ERROR);
        }
      }
    }
    v.addElement(err.toDataObject());
    return result;
  }