/** * 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); }
/** @see SubscriptionContext#subscribe(Entity, Sensor, SensorEventListener) */ public <T> SubscriptionHandle subscribe(Entity producer, Sensor<T> sensor, SensorEventListener<? super T> listener) { SubscriptionHandle handle = context.subscribe(producer, sensor, listener); synchronized (subscriptions) { subscriptions.put(producer, handle); } return handle; }
/** @see SubscriptionContext#subscribeToChildren(Entity, Sensor, SensorEventListener) */ public <T> SubscriptionHandle subscribeToChildren(Entity parent, Sensor<T> sensor, SensorEventListener<? super T> listener) { SubscriptionHandle handle = context.subscribeToChildren(parent, sensor, listener); synchronized (subscriptions) { subscriptions.put(parent, handle); } return handle; }
SubscriptionHandle subscription = null; try { subscription = ((EntityInternal)entity).getSubscriptionContext().subscribe(source, sensor, new SensorEventListener<T>() { @Override public void onEvent(SensorEvent<T> event) { data.set(event.getValue()); } finally { if (subscription != null) { ((EntityInternal)entity).getSubscriptionContext().unsubscribe(subscription);
/** * @see SubscriptionContext#subscribeToMembers(Group, Sensor, SensorEventListener) */ public <T> SubscriptionHandle subscribeToMembers(Group parent, Sensor<T> sensor, SensorEventListener<? super T> listener) { SubscriptionHandle handle = context.subscribeToMembers(parent, sensor, listener); synchronized (subscriptions) { subscriptions.put(parent, handle); } return handle; }
public void onManagementStopped(ManagementTransitionInfo info) { synchronized (this) { if (managementContext != info.getManagementContext()) { throw new IllegalStateException("Has different management context: "+managementContext+"; expected "+info.getManagementContext()); } if (subscriptionContext != null) subscriptionContext.unsubscribeAll(); entityChangeListener = EntityChangeListener.NOOP; managementContextUsable.set(false); currentlyDeployed.set(false); executionContext = null; subscriptionContext = null; } // TODO framework stopped activities, e.g. serialize state ? entity.invalidateReferences(); synchronized (this) { managementContext = null; nonDeploymentManagementContext.setMode(NonDeploymentManagementContext.NonDeploymentManagementContextMode.MANAGEMENT_STOPPED); } }
public <T> void emitInternal(Sensor<T> sensor, T val) { SubscriptionContext subsContext = getSubscriptionContext(); if (subsContext != null) subsContext.publish(sensor.newEvent(getProxyIfAvailable(), val)); }
/** * 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); } } }
@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(); }