/** * Adds the given {@link Sensor}s to this entity. */ public void addSensors(Iterable<? extends Sensor<?>> newSensors) { for (Sensor<?> sensor : newSensors) { addSensor(sensor); } }
@Override public void apply(EntityLocal entity) { sensor = newSensor(entity); ((EntityInternal) entity).getMutableEntityType().addSensor(sensor); }
@Test public void testAddSensors() throws Exception{ entity.getMutableEntityType().addSensor(TEST_SENSOR); assertEquals(entity.getEntityType().getSensors(), ImmutableSet.builder().addAll(DEFAULT_SENSORS).add(TEST_SENSOR).build()); assertEventuallyListenerEventsEqual(ImmutableList.of(BasicSensorEvent.ofUnchecked(SENSOR_ADDED, entity, TEST_SENSOR))); }
private void addSpecParameters(EntitySpec<?> spec, EntityDynamicType edType) { // if coming from a catalog item, parsed by CAMP, then the spec list of parameters is canonical, // the parent item has had its config keys set as parameters here with those non-inheritable // via type definition removed, so wipe those on the EDT to make sure non-inheritable ones are removed; // OTOH if item is blank, it was set as a java type, not inheriting it, // and the config keys on the dynamic type are the correct ones to use, and usually there is nothing in spec.parameters, // except what is being added programmatically. // (this logic could get confused if catalog item ID referred to some runtime-inherited context, // but those semantics should no longer be used -- https://issues.apache.org/jira/browse/BROOKLYN-445) if (Strings.isNonBlank(spec.getCatalogItemId())) { edType.clearConfigKeys(); } for (SpecParameter<?> param : spec.getParameters()) { edType.addConfigKey(param.getConfigKey()); if (param.getSensor()!=null) edType.addSensor(param.getSensor()); } }
@Override public void apply(@SuppressWarnings("deprecation") final org.apache.brooklyn.api.entity.EntityLocal entity) { final AttributeSensor<ReleaseableLatch> sensor = Sensors.newSensor(ReleaseableLatch.class, sensorName); ((EntityInternal) entity).getMutableEntityType().addSensor(sensor); final Task<ReleaseableLatch> resolveValueTask = DependentConfiguration.maxConcurrency(maxConcurrency); class SetValue implements Runnable { @Override public void run() { ReleaseableLatch releaseableLatch = resolveValueTask.getUnchecked(); log.debug(this+" setting sensor "+sensor+" to "+releaseableLatch+" on "+entity); entity.sensors().set(sensor, releaseableLatch); } } Task<ReleaseableLatch> setValueTask = Tasks.<ReleaseableLatch>builder().displayName("Setting " + sensor + " on " + entity).body(new SetValue()).build(); Entities.submit(entity, Tasks.sequential("Resolving and setting " + sensor + " on " + entity, resolveValueTask, setValueTask)); }
@Override public void apply(@SuppressWarnings("deprecation") org.apache.brooklyn.api.entity.EntityLocal entity) { Effector<String> eff = Effectors.effector(String.class, EFFECTOR_SAY_HELLO).parameter(String.class, "name").impl( new EffectorBody<String>() { @Override public String call(ConfigBag parameters) { Object name = parameters.getStringKey("name"); entity().sensors().set(Sensors.newStringSensor(SENSOR_LAST_HELLO), Strings.toString(name)); return helloWord()+" "+name; } }).build(); ((EntityInternal)entity).getMutableEntityType().addEffector(eff); ((EntityInternal)entity).getMutableEntityType().addSensor(Sensors.newStringSensor(SENSOR_HELLO_DEFINED)); AttributeSensor<String> emitted = Sensors.newStringSensor(SENSOR_HELLO_DEFINED_EMITTED); ((EntityInternal)entity).getMutableEntityType().addSensor(emitted); entity.sensors().set(emitted, "1"); }