本文整理了Java中org.apache.brooklyn.api.entity.Entity.subscriptions()
方法的一些代码示例,展示了Entity.subscriptions()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity.subscriptions()
方法的具体详情如下:
包路径:org.apache.brooklyn.api.entity.Entity
类名称:Entity
方法名:subscriptions
暂无
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
/**
* Asserts that the entity's value for this attribute changes, by registering a subscription and checking the value.
*
* @param entity The entity whose attribute will be checked.
* @param attribute The attribute to check on the entity.
*
* @throws AssertionError if the assertion fails.
*/
public static void assertAttributeChangesEventually(final Entity entity, final AttributeSensor<?> attribute) {
final Object origValue = entity.getAttribute(attribute);
final AtomicBoolean changed = new AtomicBoolean();
SubscriptionHandle handle = entity.subscriptions().subscribe(entity, attribute, new SensorEventListener<Object>() {
@Override public void onEvent(SensorEvent<Object> event) {
if (!Objects.equal(origValue, event.getValue())) {
changed.set(true);
}
}});
try {
Asserts.succeedsEventually(new Runnable() {
@Override public void run() {
Asserts.assertTrue(changed.get(), entity + " -> " + attribute + " not changed from "+origValue);
}});
} finally {
entity.subscriptions().unsubscribe(entity, handle);
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-webapp
protected <T> SubscriptionHandle recordEvents(Entity entity, AttributeSensor<T> sensor, final List<SensorEvent<T>> events) {
SensorEventListener<T> listener = new SensorEventListener<T>() {
@Override public void onEvent(SensorEvent<T> event) {
log.info("onEvent: {}", event);
events.add(event);
}
};
return entity.subscriptions().subscribe(entity, sensor, listener);
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-camp
protected static RecordingSensorEventListener<Object> subscribeToHaSensors(Entity entity) {
RecordingSensorEventListener<Object> listener = new RecordingSensorEventListener<>();
entity.subscriptions().subscribe(entity, HASensors.ENTITY_RECOVERED, listener);
entity.subscriptions().subscribe(entity, HASensors.ENTITY_FAILED, listener);
return listener;
}
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
subscription = entity.subscriptions().subscribe(source, sensor, new SensorEventListener<T>() {
@Override public void onEvent(SensorEvent<T> event) {
synchronized (publishedValues) { publishedValues.add(event.getValue()); }
}});
for (final AttributeAndSensorCondition abortCondition : abortSensorConditions) {
abortSubscriptions.add(entity.subscriptions().subscribe(abortCondition.source, abortCondition.sensor, new SensorEventListener<Object>() {
@Override public void onEvent(SensorEvent<Object> event) {
if (abortCondition.predicate.apply(event.getValue())) {
} finally {
if (subscription != null) {
entity.subscriptions().unsubscribe(subscription);
entity.subscriptions().unsubscribe(handle);
代码示例来源:origin: org.apache.brooklyn/brooklyn-core
@Test(groups="Integration")
@SuppressWarnings("deprecation")
public void testHttpSensorSuppressingDuplicates() throws Exception {
RecordingSensorEventListener<String> listener = new RecordingSensorEventListener<>();
entity.subscriptions().subscribe(entity, SENSOR_STRING, listener);
HttpRequestSensor<Integer> sensor = new HttpRequestSensor<Integer>(ConfigBag.newInstance()
.configure(HttpRequestSensor.SUPPRESS_DUPLICATES, true)
.configure(HttpRequestSensor.SENSOR_PERIOD, Duration.millis(1))
.configure(HttpRequestSensor.SENSOR_NAME, SENSOR_STRING.getName())
.configure(HttpRequestSensor.SENSOR_TYPE, STRING_TARGET_TYPE)
.configure(HttpRequestSensor.JSON_PATH, "$.myKey")
.configure(HttpRequestSensor.SENSOR_URI, serverUrl + "/myKey/myValue"));
sensor.apply((org.apache.brooklyn.api.entity.EntityLocal)entity);
entity.sensors().set(Attributes.SERVICE_UP, true);
EntityAsserts.assertAttributeEqualsEventually(entity, SENSOR_STRING, "myValue");
listener.assertHasEventEventually(Predicates.alwaysTrue());
Asserts.succeedsContinually(new Runnable() {
@Override public void run() {
listener.assertEventCount(1);
}});
}
内容来源于网络,如有侵权,请联系作者删除!