HubConnection Class

  • java.lang.Object
    • com.microsoft.signalr.HubConnection

Implements

java.lang.AutoCloseable

public class HubConnection implements AutoCloseable

A connection used to invoke hub methods on a SignalR Server.

Method Summary

Modifier and Type Method and Description
Subscription <T1,T2,T3,T4,T5,T6,T7,T8>on(String target, Action8<T1,T2,T3,T4,T5,T6,T7,T8> callback, Class<T1> param1, Class<T2> param2, Class<T3> param3, Class<T4> param4, Class<T5> param5, Class<T6> param6, Class<T7> param7, Class<T8> param8)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Subscription <T1,T2,T3,T4,T5,T6,T7,T8>on(String target, Action8<T1,T2,T3,T4,T5,T6,T7,T8> callback, Type param1, Type param2, Type param3, Type param4, Type param5, Type param6, Type param7, Type param8)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Subscription <T1,T2,T3,T4,T5,T6,T7>on(String target, Action7<T1,T2,T3,T4,T5,T6,T7> callback, Class<T1> param1, Class<T2> param2, Class<T3> param3, Class<T4> param4, Class<T5> param5, Class<T6> param6, Class<T7> param7)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Subscription <T1,T2,T3,T4,T5,T6,T7>on(String target, Action7<T1,T2,T3,T4,T5,T6,T7> callback, Type param1, Type param2, Type param3, Type param4, Type param5, Type param6, Type param7)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Subscription <T1,T2,T3,T4,T5,T6>on(String target, Action6<T1,T2,T3,T4,T5,T6> callback, Class<T1> param1, Class<T2> param2, Class<T3> param3, Class<T4> param4, Class<T5> param5, Class<T6> param6)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Subscription <T1,T2,T3,T4,T5,T6>on(String target, Action6<T1,T2,T3,T4,T5,T6> callback, Type param1, Type param2, Type param3, Type param4, Type param5, Type param6)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Subscription <T1,T2,T3,T4,T5>on(String target, Action5<T1,T2,T3,T4,T5> callback, Class<T1> param1, Class<T2> param2, Class<T3> param3, Class<T4> param4, Class<T5> param5)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Subscription <T1,T2,T3,T4,T5>on(String target, Action5<T1,T2,T3,T4,T5> callback, Type param1, Type param2, Type param3, Type param4, Type param5)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Subscription <T1,T2,T3,T4>on(String target, Action4<T1,T2,T3,T4> callback, Class<T1> param1, Class<T2> param2, Class<T3> param3, Class<T4> param4)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Subscription <T1,T2,T3,T4>on(String target, Action4<T1,T2,T3,T4> callback, Type param1, Type param2, Type param3, Type param4)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Subscription <T1,T2,T3>on(String target, Action3<T1,T2,T3> callback, Class<T1> param1, Class<T2> param2, Class<T3> param3)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Subscription <T1,T2,T3>on(String target, Action3<T1,T2,T3> callback, Type param1, Type param2, Type param3)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Subscription <T1,T2>on(String target, Action2<T1,T2> callback, Class<T1> param1, Class<T2> param2)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Subscription <T1,T2>on(String target, Action2<T1,T2> callback, Type param1, Type param2)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Subscription <T1>on(String target, Action1<T1> callback, Class<T1> param1)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

Subscription <T1>on(String target, Action1<T1> callback, Type param1)

Registers a handler that will be invoked when the hub method with the specified method name is invoked.

io.reactivex.Single<T> <T>invoke(Class<T> returnType, String method, Object[] args)

Invokes a hub method on the server using the specified method name and arguments.

io.reactivex.Single<T> <T>invoke(Type returnType, String method, Object[] args)

Invokes a hub method on the server using the specified method name and arguments.

io.reactivex.Observable<T> <T>stream(Class<T> returnType, String method, Object[] args)

Invokes a streaming hub method on the server using the specified name and arguments.

io.reactivex.Observable<T> <T>stream(Type returnType, String method, Object[] args)

Invokes a streaming hub method on the server using the specified name and arguments.

void close()
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.

io.reactivex.Completable invoke(String method, Object[] args)

Invokes a hub method on the server using the specified method name and arguments.

Subscription on(String target, Action callback)

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(String name)

Removes all handlers associated with the method with the specified method name.

void send(String method, Object[] args)

Invokes a hub method on the server using the specified method name.

void setBaseUrl(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.

Inherited Members

java.lang.Object.clone() java.lang.Object.equals(java.lang.Object) java.lang.Object.finalize() java.lang.Object.getClass() java.lang.Object.hashCode() java.lang.Object.notify() java.lang.Object.notifyAll() java.lang.Object.toString() java.lang.Object.wait() java.lang.Object.wait(long) java.lang.Object.wait(long,int)

Method Details

<T1,T2,T3,T4,T5,T6,T7,T8>on

public Subscription on(String target, Action8 callback, Class param1, Class param2, Class param3, Class param4, Class param5, Class param6, Class param7, Class param8)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for primitives and non-generic classes.

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.

<T1,T2,T3,T4,T5,T6,T7,T8>on

public Subscription on(String target, Action8 callback, Type param1, Type param2, Type param3, Type param4, Type param5, Type param6, Type param7, Type param8)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for generic classes and Parameterized Collections, like List or Map. A Type can be retrieved using TypeReference<T>

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.

<T1,T2,T3,T4,T5,T6,T7>on

public Subscription on(String target, Action7 callback, Class param1, Class param2, Class param3, Class param4, Class param5, Class param6, Class param7)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for primitives and non-generic classes.

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.

<T1,T2,T3,T4,T5,T6,T7>on

public Subscription on(String target, Action7 callback, Type param1, Type param2, Type param3, Type param4, Type param5, Type param6, Type param7)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for generic classes and Parameterized Collections, like List or Map. A Type can be retrieved using TypeReference<T>

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.

<T1,T2,T3,T4,T5,T6>on

public Subscription on(String target, Action6 callback, Class param1, Class param2, Class param3, Class param4, Class param5, Class param6)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for primitives and non-generic classes.

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.

<T1,T2,T3,T4,T5,T6>on

public Subscription on(String target, Action6 callback, Type param1, Type param2, Type param3, Type param4, Type param5, Type param6)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for generic classes and Parameterized Collections, like List or Map. A Type can be retrieved using TypeReference<T>

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.

<T1,T2,T3,T4,T5>on

public Subscription on(String target, Action5 callback, Class param1, Class param2, Class param3, Class param4, Class param5)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for primitives and non-generic classes.

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.

<T1,T2,T3,T4,T5>on

public Subscription on(String target, Action5 callback, Type param1, Type param2, Type param3, Type param4, Type param5)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for generic classes and Parameterized Collections, like List or Map. A Type can be retrieved using TypeReference<T>

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.

<T1,T2,T3,T4>on

public Subscription on(String target, Action4 callback, Class param1, Class param2, Class param3, Class param4)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for primitives and non-generic classes.

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.

<T1,T2,T3,T4>on

public Subscription on(String target, Action4 callback, Type param1, Type param2, Type param3, Type param4)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for generic classes and Parameterized Collections, like List or Map. A Type can be retrieved using TypeReference<T>

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.

<T1,T2,T3>on

public Subscription on(String target, Action3 callback, Class param1, Class param2, Class param3)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for primitives and non-generic classes.

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.

<T1,T2,T3>on

public Subscription on(String target, Action3 callback, Type param1, Type param2, Type param3)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for generic classes and Parameterized Collections, like List or Map. A Type can be retrieved using TypeReference<T>

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.

<T1,T2>on

public Subscription on(String target, Action2 callback, Class param1, Class param2)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for primitives and non-generic classes.

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.

<T1,T2>on

public Subscription on(String target, Action2 callback, Type param1, Type param2)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for generic classes and Parameterized Collections, like List or Map. A Type can be retrieved using TypeReference<T>

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.

<T1>on

public Subscription on(String target, Action1 callback, Class param1)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for primitives and non-generic classes.

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.

<T1>on

public Subscription on(String target, Action1 callback, Type param1)

Registers a handler that will be invoked when the hub method with the specified method name is invoked. Should be used for generic classes and Parameterized Collections, like List or Map. A Type can be retrieved using TypeReference<T>

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.

<T>invoke

public Single invoke(Class returnType, String method, Object[] args)

Invokes a hub method on the server using the specified method name and arguments.

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.

<T>invoke

public Single invoke(Type returnType, String method, Object[] args)

Invokes a hub method on the server using the specified method name and arguments. A Type can be retrieved using TypeReference<T>

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.

<T>stream

public Observable stream(Class returnType, String method, Object[] args)

Invokes a streaming hub method on the server using the specified name and arguments.

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.

<T>stream

public Observable stream(Type returnType, String method, Object[] args)

Invokes a streaming hub method on the server using the specified name and arguments.

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.

close

public void close()

getConnectionId

public 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.

getKeepAliveInterval

public long getKeepAliveInterval()

Gets the keep alive interval.

Returns:

The interval (specified in milliseconds) between keep alive messages.

getServerTimeout

public long getServerTimeout()

Gets the server timeout duration.

Returns:

The server timeout duration (specified in milliseconds).

invoke

public Completable invoke(String method, 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.

on

public Subscription on(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.

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.

remove

public void remove(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.

send

public void send(String method, 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.

setBaseUrl

public void setBaseUrl(String url)

Sets a new url for the HubConnection.

Parameters:

url - The url to connect to.

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.

setServerTimeout

public void setServerTimeout(long serverTimeoutInMilliseconds)

Sets the server timeout interval for the connection.

Parameters:

serverTimeoutInMilliseconds - The server timeout duration (specified in milliseconds).

start

public Completable start()

Starts a connection to the server.

Returns:

A Completable that completes when the connection has been established.

stop

public Completable stop()

Stops a connection to the server.

Returns:

A Completable that completes when the connection has been stopped.

Applies to