Class HubConnection


  • public class HubConnection
    extends java.lang.Object
    A connection used to invoke hub methods on a SignalR Server.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getConnectionId()
      Gets the connections connectionId.
      HubConnectionState getConnectionState()
      Indicates the state of the HubConnection to the server.
      long getKeepAliveInterval()
      Gets the keep alive interval.
      long getServerTimeout()
      Gets the server timeout duration.
      <T> io.reactivex.Single<T> invoke​(java.lang.Class<T> returnType, java.lang.String method, java.lang.Object... args)
      Invokes a hub method on the server using the specified method name and arguments.
      io.reactivex.Completable invoke​(java.lang.String method, java.lang.Object... args)
      Invokes a hub method on the server using the specified method name and arguments.
      Subscription on​(java.lang.String target, Action callback)
      Registers a handler that will be invoked when the hub method with the specified method name is invoked.
      <T1> Subscription on​(java.lang.String target, Action1<T1> callback, java.lang.Class<T1> param1)
      Registers a handler that will be invoked when the hub method with the specified method name is invoked.
      <T1,​T2>
      Subscription
      on​(java.lang.String target, Action2<T1,​T2> callback, java.lang.Class<T1> param1, java.lang.Class<T2> param2)
      Registers a handler that will be invoked when the hub method with the specified method name is invoked.
      <T1,​T2,​T3>
      Subscription
      on​(java.lang.String target, Action3<T1,​T2,​T3> callback, java.lang.Class<T1> param1, java.lang.Class<T2> param2, java.lang.Class<T3> param3)
      Registers a handler that will be invoked when the hub method with the specified method name is invoked.
      <T1,​T2,​T3,​T4>
      Subscription
      on​(java.lang.String target, Action4<T1,​T2,​T3,​T4> callback, java.lang.Class<T1> param1, java.lang.Class<T2> param2, java.lang.Class<T3> param3, java.lang.Class<T4> param4)
      Registers a handler that will be invoked when the hub method with the specified method name is invoked.
      <T1,​T2,​T3,​T4,​T5>
      Subscription
      on​(java.lang.String target, Action5<T1,​T2,​T3,​T4,​T5> callback, java.lang.Class<T1> param1, java.lang.Class<T2> param2, java.lang.Class<T3> param3, java.lang.Class<T4> param4, java.lang.Class<T5> param5)
      Registers a handler that will be invoked when the hub method with the specified method name is invoked.
      <T1,​T2,​T3,​T4,​T5,​T6>
      Subscription
      on​(java.lang.String target, Action6<T1,​T2,​T3,​T4,​T5,​T6> callback, java.lang.Class<T1> param1, java.lang.Class<T2> param2, java.lang.Class<T3> param3, java.lang.Class<T4> param4, java.lang.Class<T5> param5, java.lang.Class<T6> param6)
      Registers a handler that will be invoked when the hub method with the specified method name is invoked.
      <T1,​T2,​T3,​T4,​T5,​T6,​T7>
      Subscription
      on​(java.lang.String target, Action7<T1,​T2,​T3,​T4,​T5,​T6,​T7> callback, java.lang.Class<T1> param1, java.lang.Class<T2> param2, java.lang.Class<T3> param3, java.lang.Class<T4> param4, java.lang.Class<T5> param5, java.lang.Class<T6> param6, java.lang.Class<T7> param7)
      Registers a handler that will be invoked when the hub method with the specified method name is invoked.
      <T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8>
      Subscription
      on​(java.lang.String target, Action8<T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8> callback, java.lang.Class<T1> param1, java.lang.Class<T2> param2, java.lang.Class<T3> param3, java.lang.Class<T4> param4, java.lang.Class<T5> param5, java.lang.Class<T6> param6, java.lang.Class<T7> param7, java.lang.Class<T8> param8)
      Registers a handler that will be invoked when the hub method with the specified method name is invoked.
      void onClosed​(OnClosedCallback callback)
      Registers a callback to run when the connection is closed.
      void remove​(java.lang.String name)
      Removes all handlers associated with the method with the specified method name.
      void send​(java.lang.String method, java.lang.Object... args)
      Invokes a hub method on the server using the specified method name.
      void setBaseUrl​(java.lang.String url)
      Sets a new url for the HubConnection.
      void setKeepAliveInterval​(long keepAliveIntervalInMilliseconds)
      Sets the keep alive interval duration.
      void setServerTimeout​(long serverTimeoutInMilliseconds)
      Sets the server timeout interval for the connection.
      io.reactivex.Completable start()
      Starts a connection to the server.
      io.reactivex.Completable stop()
      Stops a connection to the server.
      <T> io.reactivex.Observable<T> stream​(java.lang.Class<T> returnType, java.lang.String method, java.lang.Object... args)
      Invokes a streaming hub method on the server using the specified name and arguments.
      • Methods inherited from class java.lang.Object

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

      • setServerTimeout

        public void setServerTimeout​(long serverTimeoutInMilliseconds)
        Sets the server timeout interval for the connection.
        Parameters:
        serverTimeoutInMilliseconds - The server timeout duration (specified in milliseconds).
      • getServerTimeout

        public long getServerTimeout()
        Gets the server timeout duration.
        Returns:
        The server timeout duration (specified in milliseconds).
      • setKeepAliveInterval

        public void setKeepAliveInterval​(long keepAliveIntervalInMilliseconds)
        Sets the keep alive interval duration.
        Parameters:
        keepAliveIntervalInMilliseconds - The interval (specified in milliseconds) at which the connection should send keep alive messages.
      • getKeepAliveInterval

        public long getKeepAliveInterval()
        Gets the keep alive interval.
        Returns:
        The interval (specified in milliseconds) between keep alive messages.
      • getConnectionId

        public java.lang.String getConnectionId()
        Gets the connections connectionId. This value will be cleared when the connection is stopped and will have a new value every time the connection is successfully started.
        Returns:
        A string representing the the client's connectionId.
      • getConnectionState

        public HubConnectionState getConnectionState()
        Indicates the state of the HubConnection to the server.
        Returns:
        HubConnection state enum.
      • setBaseUrl

        public void setBaseUrl​(java.lang.String url)
        Sets a new url for the HubConnection.
        Parameters:
        url - The url to connect to.
      • start

        public io.reactivex.Completable start()
        Starts a connection to the server.
        Returns:
        A Completable that completes when the connection has been established.
      • stop

        public io.reactivex.Completable stop()
        Stops a connection to the server.
        Returns:
        A Completable that completes when the connection has been stopped.
      • send

        public void send​(java.lang.String method,
                         java.lang.Object... args)
        Invokes a hub method on the server using the specified method name. Does not wait for a response from the receiver.
        Parameters:
        method - The name of the server method to invoke.
        args - The arguments to be passed to the method.
      • invoke

        public io.reactivex.Completable invoke​(java.lang.String method,
                                               java.lang.Object... args)
        Invokes a hub method on the server using the specified method name and arguments.
        Parameters:
        method - The name of the server method to invoke.
        args - The arguments used to invoke the server method.
        Returns:
        A Completable that indicates when the invocation has completed.
      • invoke

        public <T> io.reactivex.Single<T> invoke​(java.lang.Class<T> returnType,
                                                 java.lang.String method,
                                                 java.lang.Object... args)
        Invokes a hub method on the server using the specified method name and arguments.
        Type Parameters:
        T - The expected return type.
        Parameters:
        returnType - The expected return type.
        method - The name of the server method to invoke.
        args - The arguments used to invoke the server method.
        Returns:
        A Single that yields the return value when the invocation has completed.
      • stream

        public <T> io.reactivex.Observable<T> stream​(java.lang.Class<T> returnType,
                                                     java.lang.String method,
                                                     java.lang.Object... args)
        Invokes a streaming hub method on the server using the specified name and arguments.
        Type Parameters:
        T - The expected return type.
        Parameters:
        returnType - The expected return type of the stream items.
        method - The name of the server method to invoke.
        args - The arguments used to invoke the server method.
        Returns:
        An observable that yields the streaming results from the server.
      • remove

        public void remove​(java.lang.String name)
        Removes all handlers associated with the method with the specified method name.
        Parameters:
        name - The name of the hub method from which handlers are being removed.
      • onClosed

        public void onClosed​(OnClosedCallback callback)
        Registers a callback to run when the connection is closed.
        Parameters:
        callback - A callback to run when the connection closes.
      • on

        public Subscription on​(java.lang.String target,
                               Action callback)
        Registers a handler that will be invoked when the hub method with the specified method name is invoked.
        Parameters:
        target - The name of the hub method to define.
        callback - The handler that will be raised when the hub method is invoked.
        Returns:
        A Subscription that can be disposed to unsubscribe from the hub method.
      • on

        public <T1> Subscription on​(java.lang.String target,
                                    Action1<T1> callback,
                                    java.lang.Class<T1> param1)
        Registers a handler that will be invoked when the hub method with the specified method name is invoked.
        Type Parameters:
        T1 - The first argument type.
        Parameters:
        target - The name of the hub method to define.
        callback - The handler that will be raised when the hub method is invoked.
        param1 - The first parameter.
        Returns:
        A Subscription that can be disposed to unsubscribe from the hub method.
      • on

        public <T1,​T2> Subscription on​(java.lang.String target,
                                             Action2<T1,​T2> callback,
                                             java.lang.Class<T1> param1,
                                             java.lang.Class<T2> param2)
        Registers a handler that will be invoked when the hub method with the specified method name is invoked.
        Type Parameters:
        T1 - The first parameter type.
        T2 - The second parameter type.
        Parameters:
        target - The name of the hub method to define.
        callback - The handler that will be raised when the hub method is invoked.
        param1 - The first parameter.
        param2 - The second parameter.
        Returns:
        A Subscription that can be disposed to unsubscribe from the hub method.
      • on

        public <T1,​T2,​T3> Subscription on​(java.lang.String target,
                                                      Action3<T1,​T2,​T3> callback,
                                                      java.lang.Class<T1> param1,
                                                      java.lang.Class<T2> param2,
                                                      java.lang.Class<T3> param3)
        Registers a handler that will be invoked when the hub method with the specified method name is invoked.
        Type Parameters:
        T1 - The first parameter type.
        T2 - The second parameter type.
        T3 - The third parameter type.
        Parameters:
        target - The name of the hub method to define.
        callback - The handler that will be raised when the hub method is invoked.
        param1 - The first parameter.
        param2 - The second parameter.
        param3 - The third parameter.
        Returns:
        A Subscription that can be disposed to unsubscribe from the hub method.
      • on

        public <T1,​T2,​T3,​T4> Subscription on​(java.lang.String target,
                                                               Action4<T1,​T2,​T3,​T4> callback,
                                                               java.lang.Class<T1> param1,
                                                               java.lang.Class<T2> param2,
                                                               java.lang.Class<T3> param3,
                                                               java.lang.Class<T4> param4)
        Registers a handler that will be invoked when the hub method with the specified method name is invoked.
        Type Parameters:
        T1 - The first parameter type.
        T2 - The second parameter type.
        T3 - The third parameter type.
        T4 - The fourth parameter type.
        Parameters:
        target - The name of the hub method to define.
        callback - The handler that will be raised when the hub method is invoked.
        param1 - The first parameter.
        param2 - The second parameter.
        param3 - The third parameter.
        param4 - The fourth parameter.
        Returns:
        A Subscription that can be disposed to unsubscribe from the hub method.
      • on

        public <T1,​T2,​T3,​T4,​T5> Subscription on​(java.lang.String target,
                                                                        Action5<T1,​T2,​T3,​T4,​T5> callback,
                                                                        java.lang.Class<T1> param1,
                                                                        java.lang.Class<T2> param2,
                                                                        java.lang.Class<T3> param3,
                                                                        java.lang.Class<T4> param4,
                                                                        java.lang.Class<T5> param5)
        Registers a handler that will be invoked when the hub method with the specified method name is invoked.
        Type Parameters:
        T1 - The first parameter type.
        T2 - The second parameter type.
        T3 - The third parameter type.
        T4 - The fourth parameter type.
        T5 - The fifth parameter type.
        Parameters:
        target - The name of the hub method to define.
        callback - The handler that will be raised when the hub method is invoked.
        param1 - The first parameter.
        param2 - The second parameter.
        param3 - The third parameter.
        param4 - The fourth parameter.
        param5 - The fifth parameter.
        Returns:
        A Subscription that can be disposed to unsubscribe from the hub method.
      • on

        public <T1,​T2,​T3,​T4,​T5,​T6> Subscription on​(java.lang.String target,
                                                                                 Action6<T1,​T2,​T3,​T4,​T5,​T6> callback,
                                                                                 java.lang.Class<T1> param1,
                                                                                 java.lang.Class<T2> param2,
                                                                                 java.lang.Class<T3> param3,
                                                                                 java.lang.Class<T4> param4,
                                                                                 java.lang.Class<T5> param5,
                                                                                 java.lang.Class<T6> param6)
        Registers a handler that will be invoked when the hub method with the specified method name is invoked.
        Type Parameters:
        T1 - The first parameter type.
        T2 - The second parameter type.
        T3 - The third parameter type.
        T4 - The fourth parameter type.
        T5 - The fifth parameter type.
        T6 - The sixth parameter type.
        Parameters:
        target - The name of the hub method to define.
        callback - The handler that will be raised when the hub method is invoked.
        param1 - The first parameter.
        param2 - The second parameter.
        param3 - The third parameter.
        param4 - The fourth parameter.
        param5 - The fifth parameter.
        param6 - The sixth parameter.
        Returns:
        A Subscription that can be disposed to unsubscribe from the hub method.
      • on

        public <T1,​T2,​T3,​T4,​T5,​T6,​T7> Subscription on​(java.lang.String target,
                                                                                          Action7<T1,​T2,​T3,​T4,​T5,​T6,​T7> callback,
                                                                                          java.lang.Class<T1> param1,
                                                                                          java.lang.Class<T2> param2,
                                                                                          java.lang.Class<T3> param3,
                                                                                          java.lang.Class<T4> param4,
                                                                                          java.lang.Class<T5> param5,
                                                                                          java.lang.Class<T6> param6,
                                                                                          java.lang.Class<T7> param7)
        Registers a handler that will be invoked when the hub method with the specified method name is invoked.
        Type Parameters:
        T1 - The first parameter type.
        T2 - The second parameter type.
        T3 - The third parameter type.
        T4 - The fourth parameter type.
        T5 - The fifth parameter type.
        T6 - The sixth parameter type.
        T7 - The seventh parameter type.
        Parameters:
        target - The name of the hub method to define.
        callback - The handler that will be raised when the hub method is invoked.
        param1 - The first parameter.
        param2 - The second parameter.
        param3 - The third parameter.
        param4 - The fourth parameter.
        param5 - The fifth parameter.
        param6 - The sixth parameter.
        param7 - The seventh parameter.
        Returns:
        A Subscription that can be disposed to unsubscribe from the hub method.
      • on

        public <T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8> Subscription on​(java.lang.String target,
                                                                                                   Action8<T1,​T2,​T3,​T4,​T5,​T6,​T7,​T8> callback,
                                                                                                   java.lang.Class<T1> param1,
                                                                                                   java.lang.Class<T2> param2,
                                                                                                   java.lang.Class<T3> param3,
                                                                                                   java.lang.Class<T4> param4,
                                                                                                   java.lang.Class<T5> param5,
                                                                                                   java.lang.Class<T6> param6,
                                                                                                   java.lang.Class<T7> param7,
                                                                                                   java.lang.Class<T8> param8)
        Registers a handler that will be invoked when the hub method with the specified method name is invoked.
        Type Parameters:
        T1 - The first parameter type.
        T2 - The second parameter type.
        T3 - The third parameter type.
        T4 - The fourth parameter type.
        T5 - The fifth parameter type.
        T6 - The sixth parameter type.
        T7 - The seventh parameter type.
        T8 - The eighth parameter type.
        Parameters:
        target - The name of the hub method to define.
        callback - The handler that will be raised when the hub method is invoked.
        param1 - The first parameter.
        param2 - The second parameter.
        param3 - The third parameter.
        param4 - The fourth parameter.
        param5 - The fifth parameter.
        param6 - The sixth parameter.
        param7 - The seventh parameter.
        param8 - The eighth parameter
        Returns:
        A Subscription that can be disposed to unsubscribe from the hub method.