Search in sources :

Example 1 with UiMessageHandler

use of org.onosproject.ui.UiMessageHandler in project onos by opennetworkinglab.

the class UiWebSocket method onWebSocketText.

@Override
public void onWebSocketText(String data) {
    lastActive = System.currentTimeMillis();
    try {
        ObjectNode message = (ObjectNode) mapper.reader().readTree(data);
        String type = message.path(EVENT).asText(UNKNOWN);
        if (sessionToken == null) {
            authenticate(type, message);
        } else {
            UiMessageHandler handler = handlers.get(type);
            if (handler != null) {
                log.debug("RX message: {}", message);
                handler.process(message);
            } else {
                log.warn("No GUI message handler for type {}", type);
            }
        }
    } catch (Error | Exception e) {
        log.warn("Unable to parse GUI message {} due to", data, e);
        log.debug("Boom!!!", e);
    }
}
Also used : UiMessageHandler(org.onosproject.ui.UiMessageHandler) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ServiceNotFoundException(org.onlab.osgi.ServiceNotFoundException) IOException(java.io.IOException)

Example 2 with UiMessageHandler

use of org.onosproject.ui.UiMessageHandler in project onos by opennetworkinglab.

the class UiWebSocket method createHandlersAndOverlays.

// Creates new message handlers.
private synchronized void createHandlersAndOverlays() {
    log.debug("Creating handlers and overlays...");
    handlers = new HashMap<>();
    overlayCache = new TopoOverlayCache();
    overlay2Cache = new Topo2OverlayCache();
    Map<Class<?>, UiMessageHandler> handlerInstances = new HashMap<>();
    UiExtensionService service = directory.get(UiExtensionService.class);
    lionBundleMap = generateLionMap(service);
    service.getExtensions().forEach(ext -> {
        UiMessageHandlerFactory factory = ext.messageHandlerFactory();
        if (factory != null) {
            factory.newHandlers().forEach(handler -> {
                try {
                    handler.init(this, directory);
                    injectLionBundles(handler, lionBundleMap);
                    handler.messageTypes().forEach(type -> handlers.put(type, handler));
                    handlerInstances.put(handler.getClass(), handler);
                } catch (Exception e) {
                    log.warn("Unable to setup handler {} due to", handler, e);
                }
            });
        }
        registerOverlays(ext);
    });
    handlerCrossConnects(handlerInstances);
    overlay2Cache.switchOverlay(null, Traffic2Overlay.OVERLAY_ID);
    log.debug("#handlers = {}, #overlays = Topo: {}, Topo2: {}", handlers.size(), overlayCache.size(), overlay2Cache.size());
}
Also used : UiMessageHandlerFactory(org.onosproject.ui.UiMessageHandlerFactory) UiMessageHandler(org.onosproject.ui.UiMessageHandler) Topo2OverlayCache(org.onosproject.ui.impl.topo.Topo2OverlayCache) HashMap(java.util.HashMap) UiExtensionService(org.onosproject.ui.UiExtensionService) ServiceNotFoundException(org.onlab.osgi.ServiceNotFoundException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)2 ServiceNotFoundException (org.onlab.osgi.ServiceNotFoundException)2 UiMessageHandler (org.onosproject.ui.UiMessageHandler)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 HashMap (java.util.HashMap)1 UiExtensionService (org.onosproject.ui.UiExtensionService)1 UiMessageHandlerFactory (org.onosproject.ui.UiMessageHandlerFactory)1 Topo2OverlayCache (org.onosproject.ui.impl.topo.Topo2OverlayCache)1