use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionId in project FAAAST-Service by FraunhoferIOSB.
the class MessageBusInternal method subscribe.
@Override
public SubscriptionId subscribe(SubscriptionInfo subscriptionInfo) {
if (subscriptionInfo == null) {
throw new IllegalArgumentException("subscription must be non-null");
}
SubscriptionId subscriptionId = new SubscriptionId();
subscriptions.put(subscriptionId, subscriptionInfo);
return subscriptionId;
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionId 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;
}
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionId in project FAAAST-Service by FraunhoferIOSB.
the class Util method setUpEventCheck.
public static void setUpEventCheck(Referable expected, Class<? extends EventMessage> clazz, Supplier<?> call) {
AtomicBoolean fired = new AtomicBoolean(false);
SubscriptionId subscriptionId = IntegrationTestHttpEndpoint.messageBus.subscribe(SubscriptionInfo.create(clazz, x -> {
if (ElementReadEventMessage.class.isAssignableFrom(x.getClass())) {
Assert.assertEquals(expected, ((ElementReadEventMessage) x).getValue());
fired.set(true);
}
if (ElementCreateEventMessage.class.isAssignableFrom(x.getClass())) {
Assert.assertEquals(expected, ((ElementCreateEventMessage) x).getValue());
fired.set(true);
}
if (ElementUpdateEventMessage.class.isAssignableFrom(x.getClass())) {
Assert.assertEquals(expected, ((ElementUpdateEventMessage) x).getValue());
fired.set(true);
}
if (ElementDeleteEventMessage.class.isAssignableFrom(x.getClass())) {
Assert.assertEquals(expected, ((ElementDeleteEventMessage) x).getValue());
fired.set(true);
}
}));
call.get();
Assert.assertTrue(fired.get());
IntegrationTestHttpEndpoint.messageBus.unsubscribe(subscriptionId);
}
use of de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionId in project FAAAST-Service by FraunhoferIOSB.
the class IntegrationTestHttpEndpoint method testGETShellsEvent.
@Test
public void testGETShellsEvent() {
List<AssetAdministrationShell> actual = new ArrayList<>();
List<AssetAdministrationShell> expected = environment.getAssetAdministrationShells();
SubscriptionId subscriptionId = messageBus.subscribe(SubscriptionInfo.create(ElementReadEventMessage.class, x -> {
actual.add((AssetAdministrationShell) x.getValue());
}));
getListCall(HTTP_SHELLS, AssetAdministrationShell.class);
Assert.assertEquals(expected, actual);
messageBus.unsubscribe(subscriptionId);
}
Aggregations