public Sensor<?> addSensorIfAbsentWithoutPublishing(Sensor<?> newSensor) { Sensor<?> prev = sensors.putIfAbsent(newSensor.getName(), newSensor); if (prev == null) { invalidateSnapshot(); } return prev; }
/** * Removes the named {@link Sensor} from this entity. */ public Sensor<?> removeSensor(String sensorName) { Sensor<?> result = sensors.remove(sensorName); if (result != null) { invalidateSnapshot(); instance.sensors().emit(AbstractEntity.SENSOR_REMOVED, result); } return result; }
public void clearConfigKeys() { Map<String, FieldAndValue<ConfigKey<?>>> oldKeys = MutableMap.copyOf(configKeys); configKeys.clear(); invalidateSnapshot(); for (FieldAndValue<ConfigKey<?>> k: oldKeys.values()) { instance.sensors().emit(AbstractEntity.CONFIG_KEY_REMOVED, k.value); } }
/** * Adds the given {@link Sensor} to this entity. */ public void addSensor(Sensor<?> newSensor) { sensors.put(newSensor.getName(), newSensor); invalidateSnapshot(); instance.sensors().emit(AbstractEntity.SENSOR_ADDED, newSensor); }
/** * Removes the named {@link ConfigKey} from this entity. */ public boolean removeConfigKey(ConfigKey<?> key) { FieldAndValue<ConfigKey<?>> result = configKeys.remove(key.getName()); if (result != null) { invalidateSnapshot(); ConfigKey<?> removedKey = result.value; instance.sensors().emit(AbstractEntity.CONFIG_KEY_REMOVED, removedKey); return true; } else { return false; } }
/** * Adds the given {@link ConfigKey} to this entity. */ public void addConfigKey(ConfigKey<?> newKey) { configKeys.put(newKey.getName(), new FieldAndValue<ConfigKey<?>>(null, newKey)); invalidateSnapshot(); instance.sensors().emit(AbstractEntity.CONFIG_KEY_ADDED, newKey); }
/** * Removes the given {@link Effector} from this entity. * <p> * Note that if the argument is an instance of {@link EffectorWithBody} it will * still be possible to invoke the effector on the entity by calling * <code>entity.invoke(effector, argumentsMap)</code>. */ @Beta public void removeEffector(Effector<?> effector) { Effector<?> removed = effectors.remove(effector.getName()); invalidateSnapshot(); if (removed != null) { instance.sensors().emit(AbstractEntity.EFFECTOR_REMOVED, removed.getName()); } }
/** * Adds the given {@link Effector} to this entity. */ @Beta public void addEffector(Effector<?> newEffector) { Effector<?> oldEffector = effectors.put(Preconditions.checkNotNull(newEffector.getName(), "Missing 'name' for effector"), newEffector); invalidateSnapshot(); if (oldEffector!=null) instance.sensors().emit(AbstractEntity.EFFECTOR_CHANGED, newEffector.getName()); else instance.sensors().emit(AbstractEntity.EFFECTOR_ADDED, newEffector.getName()); }