private void onContainerAdded(Entity container, boolean rebalanceNow) { subscriptions().subscribe(container, Attributes.LOCATION_CHANGED, eventHandler); Location location = locationFinder.apply(container); if (LOG.isTraceEnabled()) LOG.trace("{} recording addition of container {} in location {}", new Object[] {this, container, location}); model.onContainerAdded(container, location); if (rebalanceNow) scheduleLatencyReductionJig(); }
@Override public void setEntity(EntityLocal entity) { super.setEntity(entity); if (!(entity instanceof SoftwareProcess)) { throw new IllegalArgumentException("Expected SoftwareProcess, but got entity "+entity); } subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, Attributes.SERVICE_STATE_ACTUAL, this); subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, Attributes.SERVICE_UP, this); }
private void onItemAdded(ItemType item, NodeType parentContainer, boolean rebalanceNow) { Preconditions.checkArgument(item instanceof Movable, "Added item "+item+" must implement Movable"); if (LOG.isTraceEnabled()) LOG.trace("{} recording addition of item {} in container {}", new Object[] {this, item, parentContainer}); subscriptions().subscribe(item, metric, eventHandler); // Update the model, including the current metric value (if any). boolean immovable = elvis(item.getConfig(Movable.IMMOVABLE), false); Number currentValue = item.getAttribute(metric); model.onItemAdded(item, parentContainer, immovable); if (currentValue != null) model.onItemWorkrateUpdated(item, currentValue.doubleValue()); if (rebalanceNow) scheduleRebalance(); }
@Override public void setEntity(EntityLocal entity) { super.setEntity(entity); subscriptions().subscribe(entity, AbstractEntity.LOCATION_ADDED, this); }
private void subscribeLaunch() { subscriptions().subscribe(entity, Attributes.SERVICE_STATE_ACTUAL, new EntityLaunchListener(this)); }
@Test public void testSubscriptionNotReceivesInitialValueEventsByDefault() { entity.sensors().set(TestEntity.SEQUENCE, 123); entity.sensors().set(TestEntity.NAME, "myname"); policy.subscriptions().subscribe(entity, TestEntity.SEQUENCE, listener); policy.subscriptions().subscribe(entity, TestEntity.NAME, listener); Asserts.succeedsContinually(ImmutableMap.of("timeout", SHORT_WAIT_MS), new Runnable() { @Override public void run() { assertEquals(listener.getEvents(), ImmutableList.of()); }}); }
@Override public void setEntity(EntityLocal entity) { super.setEntity(entity); Preconditions.checkNotNull(getConfig(EFFECTOR), EFFECTOR); sensor = getSensor(); subscriptions().subscribe(entity, sensor, this); LOG.debug("{} subscribed to {} events on {}", new Object[]{this, sensor, entity}); }
@Override public void setEntity(EntityLocal entity) { super.setEntity(entity); subscriptions().subscribe(null, TestEntity.NAME, handler); }
@Test public void testContextEntityOnEnricherSubscriptionCallbackTask() { TestEnricher enricher = entity.enrichers().add(EnricherSpec.create(TestEnricher.class)); enricher.subscriptions().subscribe(observedEntity, TestEntity.NAME, listener); observedEntity.sensors().set(TestEntity.NAME, "myval"); assertListenerCalledOnceWithContextEntityEventually(listener, entity); }
@Override protected void addProducerHardcoded(Entity producer) { subscriptions().subscribe(producer, sourceSensor, this); onProducerAdded(producer); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void setEntity(EntityLocal entity) { super.setEntity(entity); this.producer = getConfig(PRODUCER) == null ? entity: getConfig(PRODUCER); this.sourceSensor = (AttributeSensor<S>) getRequiredConfig(SOURCE_SENSOR); this.targetSensor = (AttributeSensor<Map<TKey,TVal>>) getRequiredConfig(TARGET_SENSOR); this.key = (TKey) getConfig(KEY_IN_TARGET_SENSOR); this.computing = (Function) getRequiredConfig(COMPUTING); this.removingIfResultIsNull = getConfig(REMOVING_IF_RESULT_IS_NULL); subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), producer, sourceSensor, this); highlightTriggers(sourceSensor, producer); }
private void onItemAdded(Movable item, boolean rebalanceNow) { Entity parentContainer = item.getAttribute(Movable.CONTAINER); if (LOG.isTraceEnabled()) LOG.trace("{} recording addition of item {} in container {}", new Object[] {this, item, parentContainer}); subscriptions().subscribe(item, itemUsageMetric, eventHandler); // Update the model, including the current metric value (if any). Map<? extends Movable, Double> currentValue = item.getAttribute(itemUsageMetric); boolean immovable = elvis(item.getConfig(Movable.IMMOVABLE), false); model.onItemAdded(item, parentContainer, immovable); if (currentValue != null) { model.onItemUsageUpdated(item, currentValue); } if (rebalanceNow) scheduleLatencyReductionJig(); }
@Test public void testSubscriptionReceivesInitialValueEvents() { entity.sensors().set(TestEntity.SEQUENCE, 123); entity.sensors().set(TestEntity.NAME, "myname"); policy.subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, TestEntity.SEQUENCE, listener); policy.subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, TestEntity.NAME, listener); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertEquals(listener.getEvents(), ImmutableList.of( new BasicSensorEvent<Integer>(TestEntity.SEQUENCE, entity, 123), new BasicSensorEvent<String>(TestEntity.NAME, entity, "myname"))); }}); }
@Override protected void addProducerHardcoded(Entity producer) { for (Sensor<?> sourceSensor: getSourceSensors()) { subscriptions().subscribe(producer, sourceSensor, this); } onProducerAdded(producer); }
@Override protected void addProducerMember(Entity producer) { subscriptions().subscribe(producer, sourceSensor, this); onProducerAdded(producer); }
@SuppressWarnings("unchecked") @Override public void setEntity(EntityLocal entity) { super.setEntity(entity); subscriptions().subscribe(entity, SERVICE_PROCESS_IS_RUNNING, this); subscriptions().subscribe(entity, Attributes.SERVICE_UP, this); highlightTriggers(MutableList.of(SERVICE_PROCESS_IS_RUNNING, Attributes.SERVICE_UP), entity); onUpdated(); }
@Override public void setEntity(EntityLocal entity) { assert entity instanceof Group; super.setEntity(entity); subscriptions().subscribe(null, Startable.SERVICE_UP, handler); for (Entity e : ((EntityInternal) entity).getManagementContext().getEntityManager().getEntities()) { if (Objects.equal(e.getApplicationId(), entity.getApplicationId())) updateMembership(e); } }
@Test public void testContextEntityOnPolicySubscriptionCallbackTask() { TestPolicy policy = entity.policies().add(PolicySpec.create(TestPolicy.class)); policy.subscriptions().subscribe(observedEntity, TestEntity.NAME, listener); observedEntity.sensors().set(TestEntity.NAME, "myval"); assertListenerCalledOnceWithContextEntityEventually(listener, entity); }
@Override public void setEntity(EntityLocal entity) { super.setEntity(entity); effector = getEffector(); if (Boolean.TRUE.equals(config().get(RUNNING))) { running.set(true); resubmitOnResume(); } AttributeSensor<Boolean> sensor = config().get(START_SENSOR); subscriptions().subscribe(ImmutableMap.of("notifyOfInitialValue", true), entity, sensor, this); }