Class AbstractWebSocketServer


  • public abstract class AbstractWebSocketServer
    extends java.lang.Object
    The abstract websocket server handles websocket requests from clients like browsers. Is the base class for specific impls like nano or jetty.
    • Field Detail

      • incalls

        protected java.util.Map<java.lang.String,​IFuture<?>> incalls
        The ongoing future calls from client.
      • outcalls

        protected java.util.Map<java.lang.String,​Future<?>> outcalls
        The ongoing future calls to the client.
      • partials

        protected java.util.Map<java.lang.String,​java.util.Map<java.lang.Integer,​java.lang.String>> partials
        The partial messages. todo: cleanup per timeout
      • basicconverters

        protected BasicTypeConverter basicconverters
        The basic type converters.
      • mappings

        protected MultiCollection<java.lang.String,​java.lang.String> mappings
        The interface -> impl file mappings.
      • serviceinfos

        protected java.util.Map<ClassInfo,​MethodInfo[]> serviceinfos
        The methodinfos per service interface.
    • Constructor Detail

      • AbstractWebSocketServer

        public AbstractWebSocketServer​(IExternalAccess agent)
        Creates the server.
    • Method Detail

      • getPlatform

        public IExternalAccess getPlatform()
        Get the platform.
        Returns:
        The platform.
      • handleSearchServiceMessage

        protected IFuture<java.lang.String> handleSearchServiceMessage​(java.lang.Object session,
                                                                       ServiceSearchMessage ssc)
        Handle a search service method.
        Parameters:
        session - The session.
      • handleServiceInvocationMessage

        protected IFuture<java.lang.String> handleServiceInvocationMessage​(java.lang.Object session,
                                                                           ServiceInvocationMessage sim)
        Handle a service invocation method.
        Parameters:
        session - The session.
        sim - The message.
      • findModelName

        protected IFuture<java.lang.String> findModelName​(java.lang.String typename)
        Find the component model name for a type/interface name.
        Parameters:
        typename - The service type name.
        Returns:
        The model name.
      • getMappings

        protected IFuture<MultiCollection<java.lang.String,​java.lang.String>> getMappings()
        Generate a map of service interfaces and components. Helps to find a component that implements a service interface.
      • handleServiceProvideMessage

        protected IFuture<java.lang.String> handleServiceProvideMessage​(java.lang.Object session,
                                                                        ServiceProvideMessage spm)
        Handle a provide service method. Create or get the minimal agent that publishes the service using a proxy.
        Parameters:
        session - The session of the provider.
        sim - The message.
      • handleServiceUnprovideMessage

        protected IFuture<java.lang.String> handleServiceUnprovideMessage​(java.lang.Object session,
                                                                          ServiceUnprovideMessage sum)
        Handle a provide service method. Create or get the minimal agent that publishes the service using a proxy.
        Parameters:
        session - The session of the provider.
        sim - The message.
      • handleTerminateInvocationMessage

        protected IFuture<java.lang.String> handleTerminateInvocationMessage​(java.lang.Object session,
                                                                             ServiceTerminateInvocationMessage stim)
        Handle a terminate invocation method.
        Parameters:
        session - The session.
        sim - The message.
      • handleResultMessage

        protected IFuture<java.lang.String> handleResultMessage​(java.lang.Object session,
                                                                ResultMessage rm)
        Handle a result message from a call to the client.
        Parameters:
        session - The session.
        rm - The message.
      • handlePullResultMessage

        protected IFuture<java.lang.String> handlePullResultMessage​(java.lang.Object session,
                                                                    PullResultMessage prm)
        Handle a pull result method.
        Parameters:
        session - The session.
        prm - The message.
      • sendResult

        protected IFuture<java.lang.String> sendResult​(java.lang.Object res,
                                                       java.lang.String callid,
                                                       java.lang.Object session,
                                                       boolean finished)
        Send a result message back to the client.
      • getMethodNames

        protected java.util.Set<java.lang.String> getMethodNames​(MethodInfo[] mis)
        Get the method names.
        Parameters:
        mis - The method infos.
        Returns:
        The method names.
      • sendException

        protected IFuture<java.lang.String> sendException​(java.lang.Exception ex,
                                                          java.lang.String callid,
                                                          java.lang.Object session)
        Send an exception message back to the client.
      • sendMessage

        protected IFuture<java.lang.String> sendMessage​(BaseMessage message,
                                                        java.lang.Object session)
        Send an message back to the client.
      • convertToString

        protected java.lang.String convertToString​(java.lang.Object val)
        Convert an object to the json string representation.
        Parameters:
        val - The value.
        Returns:
        The string representation.
      • convertToObject

        protected java.lang.Object convertToObject​(java.lang.String val,
                                                   java.lang.Class<?> type)
        Convert json to object representation.
        Parameters:
        val - The json value.
        Returns:
        The object.
      • getOrCreateSessionComponent

        protected IFuture<IExternalAccess> getOrCreateSessionComponent​(java.lang.String key,
                                                                       java.lang.Object session,
                                                                       java.lang.String filename,
                                                                       boolean create)
        Get or create a session component under the given key. // todo: create session component on other than gateway platform?!
      • handlePartialMessage

        protected IFuture<java.lang.String> handlePartialMessage​(java.lang.Object session,
                                                                 PartialMessage msg)
        Handle a partial mesage.
      • cleanSessionComponents

        public void cleanSessionComponents​(java.lang.Object session)
        Cleanup the (created) session platform components.
        Parameters:
        session - The session.
      • onMessage

        public void onMessage​(java.lang.Object session,
                              java.lang.String txt)
        Parameters:
        session -
        txt -
      • onClose

        public void onClose​(java.lang.Object session)
        Called on close of a session
        Parameters:
        session - The session.
      • sendWebSocketData

        public abstract void sendWebSocketData​(java.lang.Object session,
                                               java.lang.String data)
        Abstract send message method. Must be implemented by concrete web socket impl.
        Parameters:
        session - The web socket session.
        data - The data to send.
      • getSessionProperties

        public abstract java.util.Map<java.lang.String,​java.lang.Object> getSessionProperties​(java.lang.Object ws)
        Get the properties belonging to a web socket session.
        Parameters:
        session - The session.
        Returns:
        The properties.