public static AttributeSensor<String> endpointSensor(AttributeSensor source) { List<String> name = Lists.transform(source.getNameParts(), new Function<String, String>() { @Override public String apply(@Nullable String input) { String target = PORT; if (input.equals(target)) return ENDPOINT; if (input.endsWith(target)) { return input.replace(target, ENDPOINT); } target = Strings.toInitialCapOnly(PORT); if (input.endsWith(target)) { return input.replace(target, Strings.toInitialCapOnly(ENDPOINT)); } return input; } }); if (!name.contains(ENDPOINT)) name.add(ENDPOINT); return Sensors.newStringSensor(Joiner.on(".").join(name), source.getDescription() + " (Docker mapping)"); }
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 = update(attribute.getNameParts(), newValue); return (isNull(oldValue)) ? null : oldValue; }
@SuppressWarnings("unchecked") public <T> T getValue(AttributeSensor<T> sensor) { return (T) TypeCoercions.coerce(getValue(sensor.getNameParts()), sensor.getType()); }
public void remove(AttributeSensor<?> attribute) { BrooklynLogging.log(log, BrooklynLogging.levelDebugOrTraceIfReadOnly(entity), "removing attribute {} on {}", attribute.getName(), entity); remove(attribute.getNameParts()); }
@Test public void canGetAttributeByNameParts() { // Initially null assertNull(entityImpl.getAttributeByNameParts(COLOR.getNameParts())); // Once set, returns val entity.sensors().set(COLOR, "red"); assertEquals(entityImpl.getAttributeByNameParts(COLOR.getNameParts()), "red"); } }