commandInvocation
.outbound(new RestPayloadImpl.Outbound(false))
.subject(getSubject())
.managedJob()
.parameters(params);
final EventChannel ec = new EventChannel();
AdminCommandListener listener = new AdminCommandListener() {
private AdminCommandEventBroker broker;
private void unregister() {
if (broker != null) {
broker.unregisterListener(this);
}
}
@Override
public void onAdminCommandEvent(String name, Object event) {
if (name == null || event == null) {
return;
}
if (BrokerListenerRegEvent.EVENT_NAME_LISTENER_REG.equals(name)) {
BrokerListenerRegEvent blre = (BrokerListenerRegEvent) event;
broker = blre.getBroker();
return;
}
if (name.startsWith(AdminCommandEventBroker.LOCAL_EVENT_PREFIX)) {
return; //Prevent events from client to be send back to client
}
if (ec.isClosed()) {
unregister();
return;
}
if ((event instanceof Number) ||
(event instanceof CharSequence) ||
(event instanceof Boolean)) {
event = String.valueOf(event);
}
OutboundEvent outEvent = new OutboundEvent.Builder()
.name(name)
.mediaType(event instanceof String ?
MediaType.TEXT_PLAIN_TYPE :
MediaType.APPLICATION_JSON_TYPE)
.data(event.getClass(), event)
.build();
try {
ec.write(outEvent);
} catch (Exception ex) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, strings.getLocalString("sse.writeevent.exception",
"Can not write object as SSE (type = {0})",
event.getClass().getName()), ex);
}
if (ec.isClosed()) {
unregister();
}
}
}
};