/** @deprecated since 0.7.0 only {@link AbstractEnricher} has emit convenience */ @Deprecated protected <T> void emit(Sensor<T> sensor, Object val) { checkState(entity != null, "entity must first be set"); if (val == Entities.UNCHANGED) { return; } if (val == Entities.REMOVE) { ((EntityInternal)entity).removeAttribute((AttributeSensor<T>) sensor); return; } T newVal = TypeCoercions.coerce(val, sensor.getTypeToken()); if (sensor instanceof AttributeSensor) { entity.sensors().set((AttributeSensor<T>)sensor, newVal); } else { entity.sensors().emit(sensor, newVal); } }
@Override public void postLaunch() { entity.sensors().set(NginxController.PID_FILE, getRunDir() + "/" + AbstractSoftwareProcessSshDriver.PID_FILENAME); if (((AbstractController)entity).isSsl()) { entity.sensors().set(Attributes.HTTPS_PORT, getPort()); ((EntityInternal)entity).removeAttribute(Attributes.HTTP_PORT); } else { entity.sensors().set(Attributes.HTTP_PORT, getPort()); ((EntityInternal)entity).removeAttribute(Attributes.HTTPS_PORT); } super.postLaunch(); }
@Test public void testRemoveSensorThroughEntity() throws Exception{ entity.sensors().set(TEST_SENSOR, "abc"); entity.removeAttribute(TEST_SENSOR); assertFalse(entity.getEntityType().getSensors().contains(TEST_SENSOR), "sensors="+entity.getEntityType().getSensors()); assertEquals(entity.getAttribute(TEST_SENSOR), null); assertEventuallyListenerEventsEqual(ImmutableList.of(BasicSensorEvent.ofUnchecked(SENSOR_ADDED, entity, TEST_SENSOR), BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, TEST_SENSOR))); }
@SuppressWarnings("unchecked") protected void setSensor(Object v) { if (Entities.isNoLongerManaged(entity)) { if (Tasks.isInterrupted()) return; log.warn(""+entity+" is not managed; feed "+this+" setting "+sensor+" to "+v+" at this time is not supported ("+Tasks.current()+")"); } if (v == FeedConfig.UNCHANGED) { // nothing } else if (v == FeedConfig.REMOVE) { ((EntityInternal)entity).removeAttribute(sensor); feed.onRemoveSensor(sensor); } else if (sensor == FeedConfig.NO_SENSOR) { // nothing } else { Object coercedV = TypeCoercions.coerce(v, sensor.getType()); if (suppressDuplicates && Objects.equal(coercedV, entity.getAttribute(sensor))) { // no change; nothing } else { entity.sensors().set(sensor, coercedV); feed.onPublishSensor(sensor, coercedV); } } }