protected void removeProducer(Entity producer) { if (LOG.isDebugEnabled()) LOG.debug("{} stopped listening to {}", new Object[] {this, producer }); subscriptions().unsubscribe(producer); onProducerRemoved(producer); }
private void onItemRemoved(Movable item, boolean rebalanceNow) { if (LOG.isTraceEnabled()) LOG.trace("{} recording removal of item {}", this, item); subscriptions().unsubscribe(item); model.onItemRemoved(item); if (rebalanceNow) scheduleLatencyReductionJig(); }
/** * @deprecated since 0.9.0; see {@link SubscriptionSupport#unsubscribe(Entity, SubscriptionHandle)} and {@link BrooklynObject#subscriptions()} */ @Deprecated public boolean unsubscribe(Entity producer, SubscriptionHandle handle) { return subscriptions().unsubscribe(producer, handle); }
@Test public void testUnsubscribeRemovesAllSubscriptionsForThatEntity() throws Exception { policy.subscriptions().subscribe(entity, TestEntity.SEQUENCE, listener); policy.subscriptions().subscribe(entity, TestEntity.NAME, listener); policy.subscriptions().subscribe(entity, TestEntity.MY_NOTIF, listener); policy.subscriptions().subscribe(otherEntity, TestEntity.SEQUENCE, listener); policy.subscriptions().unsubscribe(entity); entity.sensors().set(TestEntity.SEQUENCE, 123); entity.sensors().set(TestEntity.NAME, "myname"); entity.sensors().emit(TestEntity.MY_NOTIF, 456); otherEntity.sensors().set(TestEntity.SEQUENCE, 789); Thread.sleep(SHORT_WAIT_MS); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(listener.getEvents(), ImmutableList.of( new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, otherEntity, 789))); }}); }
@Test public void testUnsubscribeUsingHandleStopsEvents() throws Exception { SubscriptionHandle handle1 = policy.subscriptions().subscribe(entity, TestEntity.SEQUENCE, listener); SubscriptionHandle handle2 = policy.subscriptions().subscribe(entity, TestEntity.NAME, listener); SubscriptionHandle handle3 = policy.subscriptions().subscribe(otherEntity, TestEntity.SEQUENCE, listener); policy.subscriptions().unsubscribe(entity, handle2); entity.sensors().set(TestEntity.SEQUENCE, 123); entity.sensors().set(TestEntity.NAME, "myname"); otherEntity.sensors().set(TestEntity.SEQUENCE, 456); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(listener.getEvents(), ImmutableList.of( new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, entity, 123), new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, otherEntity, 456))); }}); }
protected void unsubscribeFromGroup() { Group group = getGroup(); if (getSubscriptionTracker() != null && group != null) subscriptions().unsubscribe(group); }
private void onItemRemoved(ItemType item, NodeType parentContainer, boolean rebalanceNow) { if (LOG.isTraceEnabled()) LOG.trace("{} recording removal of item {}", this, item); subscriptions().unsubscribe(item); model.onItemRemoved(item); if (rebalanceNow) scheduleRebalance(); }
/** * @deprecated since 0.9.0; see {@link SubscriptionSupport#unsubscribe(Entity)} and {@link BrooklynObject#subscriptions()} */ @Deprecated public boolean unsubscribe(Entity producer) { return subscriptions().unsubscribe(producer); }