Class MessageProtocolDispatcher

  • Direct Known Subclasses:
    PageModel.Handlers

    public class MessageProtocolDispatcher
    extends java.lang.Object
    Handles some boilerplate for classes that can handle receiving messages from a websocket channel. Basically just a fancy wrapper around a map of protocol handling messages.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Map<java.lang.String,​com.inductiveautomation.perspective.gateway.session.MessageProtocolDispatcher.MessageHandler> handlers  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean handles​(java.lang.String protocol)  
      protected void onFatalError​(MessageChannel channel, java.lang.String message)  
      protected void onFatalError​(MessageChannel channel, java.lang.String message, java.lang.Throwable t)  
      void receive​(MessageChannel channel, java.lang.String protocol, java.io.Reader payload)  
      <T> void register​(java.lang.String protocol, java.util.function.BiConsumer<MessageChannel,​T> handler, java.lang.Class<T> clazz)  
      void trySend​(MessageChannel channel, java.lang.String protocol, com.inductiveautomation.ignition.common.gson.JsonObject payload)
      Handy wrapper around MessageChannel.send that logs a warning upon failure.
      void trySend​(MessageChannel channel, java.lang.String protocol, java.lang.Object payload)
      Handy wrapper around MessageChannel.send that logs a warning upon failure.
      void trySendInternal​(MessageChannel channel, java.lang.String protocol, java.lang.String payload)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • handlers

        protected final java.util.Map<java.lang.String,​com.inductiveautomation.perspective.gateway.session.MessageProtocolDispatcher.MessageHandler> handlers
    • Constructor Detail

      • MessageProtocolDispatcher

        public MessageProtocolDispatcher​(com.inductiveautomation.ignition.common.gson.Gson gson,
                                         LoggerEx log)
    • Method Detail

      • receive

        public void receive​(MessageChannel channel,
                            java.lang.String protocol,
                            java.io.Reader payload)
      • register

        public <T> void register​(java.lang.String protocol,
                                 java.util.function.BiConsumer<MessageChannel,​T> handler,
                                 java.lang.Class<T> clazz)
      • handles

        public boolean handles​(java.lang.String protocol)
      • onFatalError

        protected void onFatalError​(MessageChannel channel,
                                    java.lang.String message)
      • onFatalError

        protected void onFatalError​(MessageChannel channel,
                                    java.lang.String message,
                                    java.lang.Throwable t)
      • trySend

        public void trySend​(MessageChannel channel,
                            java.lang.String protocol,
                            com.inductiveautomation.ignition.common.gson.JsonObject payload)
        Handy wrapper around MessageChannel.send that logs a warning upon failure.
      • trySend

        public void trySend​(MessageChannel channel,
                            java.lang.String protocol,
                            java.lang.Object payload)
        Handy wrapper around MessageChannel.send that logs a warning upon failure.
        Parameters:
        payload - An object that will be gson-serialized automatically.
      • trySendInternal

        public void trySendInternal​(MessageChannel channel,
                                    java.lang.String protocol,
                                    java.lang.String payload)