/** * Unsubscribes the given producer. * * @see SubscriptionContext#unsubscribe(SubscriptionHandle) */ public boolean unsubscribe(Entity producer, SubscriptionHandle handle) { synchronized (subscriptions) { subscriptions.remove(producer, handle); } return context.unsubscribe(handle); }
/** * Unsubscribes the given producer. * * @see SubscriptionContext#unsubscribe(SubscriptionHandle) */ public boolean unsubscribe(Entity producer) { Collection<SubscriptionHandle> handles; synchronized (subscriptions) { handles = subscriptions.removeAll(producer); } if (handles != null) { for (SubscriptionHandle handle : handles) { context.unsubscribe(handle); } return true; } return false; }
public void unsubscribeAll() { Collection<SubscriptionHandle> subscriptionsSnapshot; synchronized (subscriptions) { subscriptionsSnapshot = ImmutableList.copyOf(subscriptions.values()); subscriptions.clear(); } for (SubscriptionHandle s: subscriptionsSnapshot) { context.unsubscribe(s); } } }
} finally { if (subscription != null) { ((EntityInternal)entity).getSubscriptionContext().unsubscribe(subscription);
@Override public synchronized void recompute() { if (subscriptionHandle != null) getSubscriptionContext().unsubscribe(subscriptionHandle); if (subscriptionHandle2 != null) getSubscriptionContext().unsubscribe(subscriptionHandle2); Entity t = getTarget(); if (t != null) { subscriptionHandle = subscribeToChildren(t, Startable.SERVICE_UP, new SensorEventListener<Boolean>() { @Override public void onEvent(SensorEvent<Boolean> event) { boolean changed = (event.getValue()) ? addMember(event.getSource()) : removeMember(event.getSource()); if (changed) { recomputeAddresses(); } }}); subscriptionHandle2 = subscribe(t, Changeable.MEMBER_REMOVED, new SensorEventListener<Entity>() { @Override public void onEvent(SensorEvent<Entity> event) { boolean changed = removeMember(event.getValue()); if (changed) { recomputeAddresses(); } }}); setMembers(t.getChildren(), EntityPredicates.attributeEqualTo(Startable.SERVICE_UP, true)); } recomputeAddresses(); }