@Override public EntityType getEntityType() { if (entityType==null) return null; return entityType.getSnapshot(); }
/** Adds an effector with an explicit body */ @Beta public <T> void addEffector(Effector<T> effector, EffectorBody<T> body) { addEffector(effector, new EffectorBodyTaskFactory<T>(body)); }
/** * Adds the given {@link Sensor}s to this entity. */ public void addSensors(Iterable<? extends Sensor<?>> newSensors) { for (Sensor<?> sensor : newSensors) { addSensor(sensor); } }
private EntityDynamicType(Class<? extends Entity> clazz, AbstractEntity entity) { this.entityClass = clazz; this.entity = entity; setName((clazz.getCanonicalName() == null) ? clazz.getName() : clazz.getCanonicalName()); String id = entity==null ? clazz.getName() : entity.getId(); effectors.putAll(findEffectors(clazz, null)); if (LOG.isTraceEnabled()) LOG.trace("Entity {} effectors: {}", id, Joiner.on(", ").join(effectors.keySet())); sensors.putAll(findSensors(clazz, null)); if (LOG.isTraceEnabled()) LOG.trace("Entity {} sensors: {}", id, Joiner.on(", ").join(sensors.keySet())); buildConfigKeys(clazz, null, configKeys); if (LOG.isTraceEnabled()) LOG.trace("Entity {} config keys: {}", id, Joiner.on(", ").join(configKeys.keySet())); refreshSnapshot(); }
public static CatalogEntitySummary from(BrooklynRestResourceUtils b, CatalogItem<? extends Entity> item) { Class<? extends Entity> clazz = b.getCatalog().loadClass(item); EntityDynamicType typeMap = EntityTypes.getDefinedEntityType(clazz); EntityType type = typeMap.getSnapshot(); Set<EntityConfigSummary> config = Sets.newLinkedHashSet(); Set<SensorSummary> sensors = Sets.newLinkedHashSet(); Set<EffectorSummary> effectors = Sets.newLinkedHashSet(); for (ConfigKey<?> x: type.getConfigKeys()) config.add(EntityConfigSummary.forCatalog(x, typeMap.getConfigKeyField(x.getName()))); for (Sensor<?> x: type.getSensors()) sensors.add(SensorSummary.forCatalog(x)); for (Effector<?> x: type.getEffectors()) effectors.add(EffectorSummary.forCatalog(x)); return new CatalogEntitySummary(item.getId(), item.getName(), item.getJavaType(), item.getDescription(), item.getIconUrl(), config, sensors, effectors, makeLinks(item)); }
public void addSensorIfAbsent(Sensor<?> newSensor) { Sensor<?> prev = addSensorIfAbsentWithoutPublishing(newSensor); if (prev == null) { snapshotValid.set(false); entity.emit(AbstractEntity.SENSOR_ADDED, newSensor); } }
/** field where a config key is defined, for use getting annotations. note annotations are not inherited. */ public Field getConfigKeyField(String keyName) { return field(configKeys.get(keyName)); }
entityType = new EntityDynamicType(this);
@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 static CatalogEntitySummary catalogEntitySummary(BrooklynRestResourceUtils b, CatalogItem<? extends Entity> item) { Class<? extends Entity> clazz = b.getCatalog().loadClass(item); EntityDynamicType typeMap = EntityTypes.getDefinedEntityType(clazz); EntityType type = typeMap.getSnapshot(); Set<EntityConfigSummary> config = Sets.newLinkedHashSet(); Set<SensorSummary> sensors = Sets.newLinkedHashSet(); Set<EffectorSummary> effectors = Sets.newLinkedHashSet(); for (ConfigKey<?> x: type.getConfigKeys()) config.add(EntityTransformer.entityConfigSummary(x, typeMap.getConfigKeyField(x.getName()))); for (Sensor<?> x: type.getSensors()) sensors.add(SensorTransformer.sensorSummaryForCatalog(x)); for (Effector<?> x: type.getEffectors()) effectors.add(EffectorTransformer.effectorSummaryForCatalog(x)); return new CatalogEntitySummary(item.getId(), item.getName(), item.getJavaType(), item.getDescription(), tidyIconLink(b, item, item.getIconUrl()), config, sensors, effectors, makeLinks(item)); }
@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; }
/** Adds an effector with an explicit body */ @Beta public <T> void addEffector(Effector<T> effector, EffectorTaskFactory<T> body) { addEffector(new EffectorAndBody<T>(effector, body)); } /** Adds an effector with an explicit body */
/** attaches lifecycle effectors (start, restart, stop) to the given entity (post-creation) */ public void attachLifecycleEffectors(Entity entity) { ((EntityInternal)entity).getMutableEntityType().addEffector(newStartEffector()); ((EntityInternal)entity).getMutableEntityType().addEffector(newRestartEffector()); ((EntityInternal)entity).getMutableEntityType().addEffector(newStopEffector()); }