protected AttributeSensor<?> getAttributeKey(String key) { AttributeSensor<?> result=null; if (attributeKeys!=null) { result = attributeKeys.get(key); if (result!=null && !LEGACY_KEY_DESCRIPTION.equals(result.getDescription())) return result; } AttributeSensor<?> resultStatic = (AttributeSensor<?>) getStaticSensorKeys().get(key); if (resultStatic!=null) return resultStatic; if (result!=null) return result; // see notes on legacy config key log.warn("Sensor "+key+": "+LEGACY_KEY_DESCRIPTION); return Sensors.newSensor(Object.class, key, LEGACY_KEY_DESCRIPTION); }
public static AttributeSensor<String> endpointSensor(AttributeSensor source) { List<String> name = Lists.transform(source.getNameParts(), new Function<String, String>() { @Override public String apply(@Nullable String input) { String target = PORT; if (input.equals(target)) return ENDPOINT; if (input.endsWith(target)) { return input.replace(target, ENDPOINT); } target = Strings.toInitialCapOnly(PORT); if (input.endsWith(target)) { return input.replace(target, Strings.toInitialCapOnly(ENDPOINT)); } return input; } }); if (!name.contains(ENDPOINT)) name.add(ENDPOINT); return Sensors.newStringSensor(Joiner.on(".").join(name), source.getDescription() + " (Docker mapping)"); }
public static AttributeSensor<String> mappedPortSensor(AttributeSensor source) { return Sensors.newStringSensor(MAPPED + "." + source.getName(), source.getDescription() + " (Docker mapping)"); } public static AttributeSensor<String> endpointSensor(AttributeSensor source) {
public static <T> AttributeSensor<T> newSensorRenamed(String newName, AttributeSensor<T> sensor) { return new BasicAttributeSensor<T>(sensor.getTypeToken(), newName, sensor.getDescription()); }
@SuppressWarnings({ "unchecked", "rawtypes" }) public WindowsPerformanceCounterPollConfig(AttributeSensor<T> sensor) { super(sensor); description(sensor.getDescription()); onSuccess((Function)Functions.identity()); }
@Test public void testMementoNotTooBig() throws Exception { origApp.addChild(EntitySpec.create(TestEntity.class)); // dynamic conf key origApp.config().set(TestEntity.CONF_NAME, "slim"); // declared sensor origApp.sensors().set(TestApplication.MY_ATTRIBUTE, "foo"); // dynamic sensor origApp.sensors().set(TestEntity.SEQUENCE, 98765); // dynamic effector origApp.getMutableEntityType().addEffector(SayHiBody.EFFECTOR); RebindTestUtils.stopPersistence(origApp); File mementoFile = new File(new File(mementoDir, "entities"), origApp.getId()); String memento = Streams.readFullyAndClose(new FileReader(mementoFile)); log.info("memento is:\n"+memento); // make sure it's not too long, and doesn't have declared items Assert.assertTrue(memento.length() < 4000, "length is: "+memento.length()); Assert.assertFalse(memento.contains("restart")); Assert.assertFalse(memento.contains(TestApplication.MY_ATTRIBUTE.getDescription())); Assert.assertFalse(memento.toLowerCase().contains("typetoken")); }