Permalink
Browse files

Update event websocket

  • Loading branch information...
mcicolella committed Jul 7, 2018
1 parent 1163baf commit 720430d2688a6eca08ad342b3f7e1c9d188f1c49
@@ -43,7 +43,7 @@
* @author Mauro Cicolella
*/
@Path(AtmosphereEventResource.PATH)
@Api(value = "ws_event", description = "WS for receiving event notifications", position = 10)
@Api(value = "ws_event", description = "WS for receiving event notifications", position = 50)
@AtmosphereService(
dispatch = false,
interceptors = {AtmosphereResourceLifecycleInterceptor.class},
@@ -52,13 +52,11 @@
public class AtmosphereEventResource extends AbstractWSResource {
private static final Logger LOG = LoggerFactory.getLogger(AtmosphereEventResource.class.getName());
public final static String PATH = "event";
@Override
public void broadcast(EventTemplate message) {
if (api != null) {
String msg = "";
String msgType = "";
String payload = "";
@@ -79,50 +77,34 @@ public void broadcast(EventTemplate message) {
} else if (message instanceof ZoneHasChanged) {
msgType = "zone-changed";
} else if (message instanceof PluginHasChanged) {
payload = message.getPayload().getStatementValue("plugin.name");
if (api != null) {
for (Client client : api.getClients("plugin")) {
Plugin plugin = (Plugin) client;
if (plugin.getName().equalsIgnoreCase(message.getPayload().getStatementValue("plugin.name"))) {
try {
payload = om.writeValueAsString(plugin);
} catch (JsonProcessingException ex) {
LOG.error("Error processing Json data", ex);
}
}
}
}
switch (message.getProperty("plugin.action")) {
case "START":
msgType = "plugin-started";
if (api != null) {
for (Client client : api.getClients("plugin")) {
Plugin plugin = (Plugin) client;
if (plugin.getName().equalsIgnoreCase(message.getPayload().getStatementValue("plugin.name"))) {
payload = plugin.toString();
}
}
}
break;
case "STOP":
msgType = "plugin-stopped";
if (api != null) {
for (Client client : api.getClients("plugin")) {
Plugin plugin = (Plugin) client;
if (plugin.getName().equalsIgnoreCase(message.getPayload().getStatementValue("plugin.name"))) {
payload = plugin.toString();
}
}
}
break;
case "ENQUEUE":
msgType = "plugin-installed";
if (api != null) {
for (Client client : api.getClients("plugin")) {
Plugin plugin = (Plugin) client;
if (plugin.getName().equalsIgnoreCase(message.getPayload().getStatementValue("plugin.name"))) {
try {
payload = om.writeValueAsString(plugin);
} catch (JsonProcessingException ex) {
LOG.error("Error processing Json data", ex);
}
}
}
}
break;
case "DEQUEUE":
msgType = "plugin-uninstalled";
payload = message.getPayload().getStatementValue("plugin.name");
break;
}
} else if (message instanceof MessageEvent) {
@@ -133,15 +115,11 @@ public void broadcast(EventTemplate message) {
LOG.error("Error processing Json data", ex);
}
}
// broadcast message
try {
BroadcasterFactory
.getDefault()
.lookup("/" + RestAPIv3.API_VERSION + "/ws/" + AtmosphereEventResource.PATH)
.broadcast(om.writeValueAsString(msgType + "#" + payload));
} catch (JsonProcessingException ex) {
}
BroadcasterFactory
.getDefault()
.lookup("/" + RestAPIv3.API_VERSION + "/ws/" + AtmosphereEventResource.PATH)
.broadcast(msgType + "#" + payload);
}
}
}
@@ -44,7 +44,6 @@
@Api(value = "plugins", description = "Operations on plugins", position = 7)
public class PluginResource extends AbstractResource<Plugin> {
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "List all installed plugins", position = 10)
@@ -150,21 +149,21 @@ public Response stop(
@Override
protected URI doCopy(String UUID) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
protected URI doCreate(Plugin o) throws URISyntaxException {
throw new UnsupportedOperationException("Not supported yet.");
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
protected boolean doDelete(String UUID) {
throw new UnsupportedOperationException("Not supported yet.");
throw new UnsupportedOperationException("Not supported yet.");
}
@Override
protected Plugin doUpdate(String UUID, Plugin o) {
throw new UnsupportedOperationException("Not supported yet.");
throw new UnsupportedOperationException("Not supported yet.");
}
}

0 comments on commit 720430d

Please sign in to comment.