use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionInfo in project FAAAST-Service by FraunhoferIOSB.
the class MessageBusInternal method run.
/**
* Take an EventMessage from the queue. Iterate over all subscribers and
* check which filter applies and call the subscription handler
*/
@Override
public void run() {
running.set(true);
try {
while (running.get()) {
EventMessage message = messageQueue.take();
Class<? extends EventMessage> messageType = message.getClass();
for (SubscriptionInfo subscription : subscriptions.values()) {
if (subscription.getSubscribedEvents().stream().anyMatch(x -> x.isAssignableFrom(messageType)) && subscription.getFilter().test(message.getElement())) {
subscription.getHandler().accept(message);
}
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionInfo in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method subscribeMessageBus.
/**
* Subscribes to Events on the MessageBus (e.g. ValueChangeEvents).
*/
private void subscribeMessageBus() {
try {
if (messageBus != null) {
logger.debug("subscribeMessageBus: subscribe ValueChangeEvents");
SubscriptionInfo info = SubscriptionInfo.create(ValueChangeEventMessage.class, (t) -> {
try {
valueChanged(t.getElement(), t.getNewValue(), t.getOldValue());
} catch (StatusException ex2) {
logger.error("valueChanged Exception", ex2);
}
});
SubscriptionId rv = messageBus.subscribe(info);
subscriptions.add(rv);
info = SubscriptionInfo.create(ElementCreateEventMessage.class, (x) -> {
try {
elementCreated(x.getElement(), x.getValue());
} catch (Exception ex3) {
logger.error("elementCreated Exception", ex3);
}
});
rv = messageBus.subscribe(info);
subscriptions.add(rv);
info = SubscriptionInfo.create(ElementDeleteEventMessage.class, (x) -> {
try {
elementDeleted(x.getElement());
} catch (Exception ex3) {
logger.error("elementDeleted Exception", ex3);
}
});
rv = messageBus.subscribe(info);
subscriptions.add(rv);
info = SubscriptionInfo.create(ElementUpdateEventMessage.class, (x) -> {
try {
elementUpdated(x.getElement(), x.getValue());
} catch (Exception ex3) {
logger.error("elementUpdated Exception", ex3);
}
});
rv = messageBus.subscribe(info);
subscriptions.add(rv);
} else {
logger.warn("MessageBus not available!");
}
} catch (Throwable ex) {
logger.error("subscribeMessageBus Exception", ex);
throw ex;
}
}
Aggregations