@Override public void apply(EntityLocal entity) { WindowsPerformanceCounterFeed.Builder builder = WindowsPerformanceCounterFeed.builder() .period(period) .entity(entity); for (Map<String, String> sensorConfig : sensors) { String name = sensorConfig.get("name"); String sensorType = sensorConfig.get("sensorType"); Class<?> clazz; try { clazz = Strings.isNonEmpty(sensorType) ? ((EntityInternal)entity).getManagementContext().getCatalog().getRootClassLoader().loadClass(sensorType) : String.class; } catch (ClassNotFoundException e) { throw new IllegalStateException("Could not load type "+sensorType+" for sensor "+name, e); } builder.addSensor(sensorConfig.get("counter"), Sensors.newSensor(clazz, name, sensorConfig.get("description"))); } entity.addFeed(builder.build()); } }
@Test public void testFeedDeDupe() throws Exception { testPollsAndParsesHttpGetResponse(); entity.addFeed(feed); log.info("Feed 0 is: "+feed); testPollsAndParsesHttpGetResponse(); log.info("Feed 1 is: "+feed); entity.addFeed(feed); FeedSupport feeds = ((EntityInternal)entity).feeds(); Assert.assertEquals(feeds.getFeeds().size(), 1, "Wrong feed count: "+feeds.getFeeds()); }
@Test(groups="Integration") public void testFeedDeDupe() throws Exception { testReturnsShellExitStatus(); entity.addFeed(feed); log.info("Feed 0 is: "+feed); testReturnsShellExitStatus(); log.info("Feed 1 is: "+feed); entity.addFeed(feed); FeedSupport feeds = ((EntityInternal)entity).feeds(); Assert.assertEquals(feeds.getFeeds().size(), 1, "Wrong feed count: "+feeds.getFeeds()); }
@Test public void testFeedDeDupe() throws Exception { testPollsFunctionRepeatedlyToSetAttribute(); entity.addFeed(feed); log.info("Feed 0 is: "+feed); Feed feed0 = feed; testPollsFunctionRepeatedlyToSetAttribute(); entity.addFeed(feed); log.info("Feed 1 is: "+feed); Feed feed1 = feed; Assert.assertFalse(feed1==feed0); FeedSupport feeds = ((EntityInternal)entity).feeds(); Assert.assertEquals(feeds.getFeeds().size(), 1, "Wrong feed count: "+feeds.getFeeds()); // a couple extra checks, compared to the de-dupe test in other *FeedTest classes Feed feedAdded = Iterables.getOnlyElement(feeds.getFeeds()); Assert.assertTrue(feedAdded==feed1); Assert.assertFalse(feedAdded==feed0); }
@Override public void apply(final EntityLocal entity) { super.apply(entity); epochSensor = Sensors.newLongSensor(sensor.getName() + ".epoch"); if (entity.sensors().get(epochSensor) == null) { Long epoch = epochSupplier.get(); if (epoch == null) { epoch = CURRENT_TIME_SUPPLIER.get(); } entity.sensors().set(epochSensor, epoch); } FunctionFeed feed = FunctionFeed.builder() .entity(entity) .poll(new FunctionPollConfig<>(sensor).callable(new UpdateTimeSince(entity))) .period(period) .build(); entity.addFeed(feed); }
@Override public JmxFeed call() throws Exception { JmxHelper helper = new JmxHelper(entity); JmxFeed feed = JmxFeed.builder() .entity(entity) .period(period) .helper(helper) .pollAttribute(new JmxAttributePollConfig<T>(sensor) .objectName(objectName) .attributeName(attribute) .suppressDuplicates(Boolean.TRUE.equals(suppressDuplicates)) .onFailureOrException(Functions.<T>constant((T) defaultValue))) .build(); entity.addFeed(feed); return feed; } })
.build(); entity.addFeed(feed);
.build(); entity.addFeed(feed);
entity.addFeed(feed);