use of fish.payara.micro.cdi.Inbound in project Payara by payara.
the class ClusteredCDIEventBusImpl method eventReceived.
@Override
public void eventReceived(final PayaraClusteredCDIEvent event) {
// first check if the event is targetted at a specific instance
String instanceName = event.getProperty(INSTANCE_PROPERTY);
if (!(instanceName == null) && !(instanceName.length() == 0)) {
// there is an instance name filter
String[] names = deserializeToArray(instanceName);
boolean forUs = false;
String thisInstance = runtime.getInstanceName();
for (String name : names) {
if (name.equals(thisInstance)) {
forUs = true;
break;
}
}
if (!forUs)
return;
}
try (Context ctx = ctxUtil.pushContext()) {
managedExecutorService.submit(new Runnable() {
@Override
public void run() {
ClassLoader oldCL = Utility.getClassLoader();
try {
Utility.setContextClassLoader(ctxUtil.getInvocationClassLoader());
// create the set of qualifiers for the event
// first add Inbound qualifier with the correct properties
Set<Annotation> qualifiers = new HashSet<>();
Serializable eventPayload = event.getPayload();
Inbound inbound = new Inbound() {
@Override
public String eventName() {
return event.getProperty(EVENT_PROPERTY);
}
@Override
public Class<? extends Annotation> annotationType() {
return Inbound.class;
}
};
qualifiers.add(inbound);
// Now create Qualifiers for the sent event qualifiers
Set<Annotation> receivedQualifiers = event.getQualifiers();
for (Annotation receivedQualifier : receivedQualifiers) {
// strip out OutBound as we don't want it even though it was sent over
if (!(receivedQualifier instanceof Outbound)) {
qualifiers.add(receivedQualifier);
}
}
Annotation[] annotations = qualifiers.toArray(new Annotation[0]);
bm.fireEvent(eventPayload, annotations);
} catch (IOException | ClassNotFoundException ex) {
Logger.getLogger(ClusteredCDIEventBusImpl.class.getName()).log(ex.getCause() instanceof IllegalStateException ? Level.FINE : Level.INFO, "Received Event but could not process it", ex);
} finally {
Utility.setContextClassLoader(oldCL);
}
}
});
}
}
Aggregations