/** * Updates the value. * * @param path the path to the value. * @param newValue the new value * @return the old value. * @throws IllegalArgumentException if path is null or empty */ // TODO path must be ordered(and legal to contain duplicates like "a.b.a"; list would be better public <T> T update(Collection<String> path, T newValue) { checkPath(path); if (newValue == null) { newValue = typedNull(); } if (log.isTraceEnabled()) { log.trace("setting sensor {}={} for {}", new Object[] {path, newValue, entity}); } T oldValue = (T) values.put(path, newValue); return (isNull(oldValue)) ? null : oldValue; }
@Override public <T> T getAttribute(AttributeSensor<T> attribute) { return attributesInternal.getValue(attribute); }
/** * Gets the value * * @param path the path of the value to get * @return the value * @throws IllegalArgumentException path is null or empty. */ public Object getValue(Collection<String> path) { // TODO previously this would return a map of the sub-tree if the path matched a prefix of a group of sensors, // or the leaf value if only one value. Arguably that is not required - what is/was the use-case? // checkPath(path); Object result = values.get(path); return (isNull(result)) ? null : result; }
public <T> T updateWithoutPublishing(AttributeSensor<T> attribute, T newValue) { if (log.isTraceEnabled()) { Object oldValue = getValue(attribute); if (!Objects.equal(oldValue, newValue != null)) { log.trace("setting attribute {} to {} (was {}) on {}", new Object[] {attribute.getName(), newValue, oldValue, entity}); } else { log.trace("setting attribute {} to {} (unchanged) on {}", new Object[] {attribute.getName(), newValue, this}); } } T oldValue = (T) update(attribute.getNameParts(), newValue); return (isNull(oldValue)) ? null : oldValue; }
attributesInternal = new AttributeMap(this, managementContext.getStorage().<Collection<String>, Object>getMap(id+"-attributes")); if (oldAttribs.asRawMap().size() > 0) { for (Map.Entry<Collection<String>,Object> entry : oldAttribs.asRawMap().entrySet()) { attributesInternal.update(entry.getKey(), entry.getValue());
@Override public void removeAttribute(AttributeSensor<?> attribute) { attributesInternal.remove(attribute); entityType.removeSensor(attribute); }
public <T> T update(AttributeSensor<T> attribute, T newValue) { T oldValue = updateWithoutPublishing(attribute, newValue); entity.emitInternal(attribute, newValue); return oldValue; }
public void remove(Collection<String> path) { checkPath(path); if (log.isTraceEnabled()) { log.trace("removing sensor {} for {}", new Object[] {path, entity}); } values.remove(path); }
public Map<String, Object> asMap() { Map<String, Object> result = Maps.newLinkedHashMap(); for (Map.Entry<Collection<String>, Object> entry : values.entrySet()) { String sensorName = Joiner.on('.').join(entry.getKey()); Object val = (isNull(entry.getValue())) ? null : entry.getValue(); result.put(sensorName, val); } return result; }
@Override public Map<AttributeSensor, Object> getAllAttributes() { Map<AttributeSensor, Object> result = Maps.newLinkedHashMap(); Map<String, Object> attribs = attributesInternal.asMap(); for (Map.Entry<String,Object> entry : attribs.entrySet()) { AttributeSensor attribKey = (AttributeSensor) entityType.getSensor(entry.getKey()); if (attribKey == null) { LOG.warn("When retrieving all attributes of {}, ignoring attribute {} because no matching AttributeSensor found", this, entry.getKey()); } else { result.put(attribKey, entry.getValue()); } } return result; }
@Override public <T> T setAttribute(AttributeSensor<T> attribute, T val) { T result = attributesInternal.update(attribute, val); if (result == null) { // could be this is a new sensor entityType.addSensorIfAbsent(attribute); } getManagementSupport().getEntityChangeListener().onAttributeChanged(attribute); return result; }
public void remove(AttributeSensor<?> attribute) { if (log.isDebugEnabled()) { log.debug("removing attribute {} on {}", attribute.getName(), entity); } remove(attribute.getNameParts()); }
@Override public <T> T setAttributeWithoutPublishing(AttributeSensor<T> attribute, T val) { T result = attributesInternal.updateWithoutPublishing(attribute, val); if (result == null) { // could be this is a new sensor entityType.addSensorIfAbsentWithoutPublishing(attribute); } getManagementSupport().getEntityChangeListener().onAttributeChanged(attribute); return result; }
public <T> T getAttributeByNameParts(List<String> nameParts) { return (T) attributesInternal.getValue(nameParts); }
public <T> T getValue(AttributeSensor<T> sensor) { return (T) getValue(sensor.getNameParts()); }