public abstract class AttributeSensorAndConfigKey<ConfigType,SensorType> extends BasicAttributeSensor<SensorType> implements ConfigKey.HasConfigKey<ConfigType>
Sensor
describing an attribute that can be configured with inputs that are used to derive the final value.
The ConfigKey
will have the same name and description as the sensor but not necessarily the same type.
Conversion to set the sensor value from the config key must be supplied in a subclass.
ConfigToAttributes.apply(EntityLocal, AttributeSensorAndConfigKey)
is useful to set the attribute from the sensor.
AttributeSensor.SensorPersistenceMode
Constructor and Description |
---|
AttributeSensorAndConfigKey(AttributeSensorAndConfigKey<ConfigType,SensorType> orig,
ConfigType defaultValue) |
AttributeSensorAndConfigKey(java.lang.Class<ConfigType> configType,
java.lang.Class<SensorType> sensorType,
java.lang.String name) |
AttributeSensorAndConfigKey(java.lang.Class<ConfigType> configType,
java.lang.Class<SensorType> sensorType,
java.lang.String name,
java.lang.String description) |
AttributeSensorAndConfigKey(java.lang.Class<ConfigType> configType,
java.lang.Class<SensorType> sensorType,
java.lang.String name,
java.lang.String description,
java.lang.Object defaultValue) |
AttributeSensorAndConfigKey(com.google.common.reflect.TypeToken<ConfigType> configType,
com.google.common.reflect.TypeToken<SensorType> sensorType,
java.lang.String name) |
AttributeSensorAndConfigKey(com.google.common.reflect.TypeToken<ConfigType> configType,
com.google.common.reflect.TypeToken<SensorType> sensorType,
java.lang.String name,
java.lang.String description) |
AttributeSensorAndConfigKey(com.google.common.reflect.TypeToken<ConfigType> configType,
com.google.common.reflect.TypeToken<SensorType> sensorType,
java.lang.String name,
java.lang.String description,
java.lang.Object defaultValue) |
Modifier and Type | Method and Description |
---|---|
SensorType |
getAsSensorValue(Entity e)
returns the sensor value for this attribute on the given entity, if present,
otherwise works out what the sensor value should be based on the config key's value
|
SensorType |
getAsSensorValue(ManagementContext managementContext) |
ConfigKey<ConfigType> |
getConfigKey() |
getPersistenceMode
equals, getDescription, getName, getNameParts, getType, getTypeName, getTypeToken, hashCode, newEvent, toString
getDescription, getName, getNameParts, getType, getTypeName, getTypeToken, newEvent
public AttributeSensorAndConfigKey(java.lang.Class<ConfigType> configType, java.lang.Class<SensorType> sensorType, java.lang.String name)
public AttributeSensorAndConfigKey(java.lang.Class<ConfigType> configType, java.lang.Class<SensorType> sensorType, java.lang.String name, java.lang.String description)
public AttributeSensorAndConfigKey(java.lang.Class<ConfigType> configType, java.lang.Class<SensorType> sensorType, java.lang.String name, java.lang.String description, java.lang.Object defaultValue)
public AttributeSensorAndConfigKey(com.google.common.reflect.TypeToken<ConfigType> configType, com.google.common.reflect.TypeToken<SensorType> sensorType, java.lang.String name)
public AttributeSensorAndConfigKey(com.google.common.reflect.TypeToken<ConfigType> configType, com.google.common.reflect.TypeToken<SensorType> sensorType, java.lang.String name, java.lang.String description)
public AttributeSensorAndConfigKey(com.google.common.reflect.TypeToken<ConfigType> configType, com.google.common.reflect.TypeToken<SensorType> sensorType, java.lang.String name, java.lang.String description, java.lang.Object defaultValue)
public AttributeSensorAndConfigKey(AttributeSensorAndConfigKey<ConfigType,SensorType> orig, ConfigType defaultValue)
public ConfigKey<ConfigType> getConfigKey()
getConfigKey
in interface ConfigKey.HasConfigKey<ConfigType>
public SensorType getAsSensorValue(Entity e)
calls to this may allocate resources (e.g. ports) so should be called only once and then (if non-null) assigned as the sensor's value
(for this reason this method should generally not be invoked by callers except in tests and by the framework,
and similarly should not be overridden; implement convertConfigToSensor(Object, Entity)
instead for single-execution calls.
the framework calls this from AbstractEntity.setAttribute(AttributeSensorAndConfigKey)
typically via ConfigToAttributes.apply(EntityLocal)
e.g. from SoftwareProcessImpl.preStart().)
public SensorType getAsSensorValue(ManagementContext managementContext)
#getAsSensorValue(Entity)}
Differs in that the config value is converted based on just the management context, rather
than for a specific entity. For example, useful if using {@link BrooklynConfigKeys} in BrooklynWebServer.