diff --git a/clients/java/signalr/src/main/java/HubConnection.java b/clients/java/signalr/src/main/java/HubConnection.java index 1edab69e18..e3eb1bec97 100644 --- a/clients/java/signalr/src/main/java/HubConnection.java +++ b/clients/java/signalr/src/main/java/HubConnection.java @@ -90,22 +90,44 @@ public class HubConnection { } } + /** + * Initializes a new instance of the {@link HubConnection} class. + * @param url The url of the SignalR server to connect to. + * @param transport The {@link Transport} that the client will use to communicate with the server. + */ public HubConnection(String url, Transport transport) { this(url, transport, new NullLogger()); } + /** + * Initializes a new instance of the {@link HubConnection} class. + * @param url The url of the SignalR server to connect to. + */ public HubConnection(String url) { this(url, null, new NullLogger()); } + /** + * Initializes a new instance of the {@link HubConnection} class. + * @param url The url of the SignalR server to connect to. + * @param logLevel The minimum level of messages to log. + */ public HubConnection(String url, LogLevel logLevel){ this(url, null, new ConsoleLogger(logLevel)); } + /** + * Indicates the state of the {@link HubConnection} to the server. + * @return HubConnection state enum. + */ public HubConnectionState getConnectionState() { return connectionState; } + /** + * Starts a connection to the server. + * @throws Exception An error occurred while connecting. + */ public void start() throws Exception { logger.log(LogLevel.Debug, "Starting HubConnection"); transport.setOnReceive(this.callback); @@ -116,6 +138,9 @@ public class HubConnection { logger.log(LogLevel.Information, "HubConnected started"); } + /** + * Stops a connection to the server. + */ public void stop(){ logger.log(LogLevel.Debug, "Stopping HubConnection"); transport.stop(); @@ -123,6 +148,13 @@ public class HubConnection { logger.log(LogLevel.Information, "HubConnection stopped"); } + /** + * Invokes a hub method on the server using the specified method name. + * Does not wait for a response from the receiver. + * @param method The name of the server method to invoke. + * @param args The arguments to be passed to the method. + * @throws Exception If there was an error while sending. + */ public void send(String method, Object... args) throws Exception { InvocationMessage invocationMessage = new InvocationMessage(method, args); String message = protocol.writeMessage(invocationMessage); @@ -130,6 +162,12 @@ public class HubConnection { transport.send(message); } + /** + * Registers a handler that will be invoked when the hub method with the specified method name is invoked. + * @param target The name of the hub method to define. + * @param callback The handler that will be raised when the hub method is invoked. + * @return A {@link Subscription} that can be disposed to unsubscribe from the hub method. + */ public Subscription on(String target, Action callback) { ActionBase action = args -> callback.invoke(); handlers.put(target, action); @@ -137,6 +175,14 @@ public class HubConnection { return new Subscription(handlers, action, target); } + /** + * Registers a handler that will be invoked when the hub method with the specified method name is invoked. + * @param target The name of the hub method to define. + * @param callback The handler that will be raised when the hub method is invoked. + * @param param1 The first parameter. + * @param The first argument type. + * @return A {@link Subscription} that can be disposed to unsubscribe from the hub method. + */ public Subscription on(String target, Action1 callback, Class param1) { ActionBase action = params -> callback.invoke(param1.cast(params[0])); handlers.put(target, action); @@ -144,6 +190,16 @@ public class HubConnection { return new Subscription(handlers, action, target); } + /** + * Registers a handler that will be invoked when the hub method with the specified method name is invoked. + * @param target The name of the hub method to define. + * @param callback The handler that will be raised when the hub method is invoked. + * @param param1 The first parameter. + * @param param2 The second parameter. + * @param The first parameter type. + * @param The second parameter type. + * @return A {@link Subscription} that can be disposed to unsubscribe from the hub method. + */ public Subscription on(String target, Action2 callback, Class param1, Class param2) { ActionBase action = params -> { callback.invoke(param1.cast(params[0]), param2.cast(params[1])); @@ -153,6 +209,18 @@ public class HubConnection { return new Subscription(handlers, action, target); } + /** + * Registers a handler that will be invoked when the hub method with the specified method name is invoked. + * @param target The name of the hub method to define. + * @param callback The handler that will be raised when the hub method is invoked. + * @param param1 The first parameter. + * @param param2 The second parameter. + * @param param3 The third parameter. + * @param The first parameter type. + * @param The second parameter type. + * @param The third parameter type. + * @return A {@link Subscription} that can be disposed to unsubscribe from the hub method. + */ public Subscription on(String target, Action3 callback, Class param1, Class param2, Class param3) { ActionBase action = params -> { @@ -163,6 +231,20 @@ public class HubConnection { return new Subscription(handlers, action, target); } + /** + * Registers a handler that will be invoked when the hub method with the specified method name is invoked. + * @param target The name of the hub method to define. + * @param callback The handler that will be raised when the hub method is invoked. + * @param param1 The first parameter. + * @param param2 The second parameter. + * @param param3 The third parameter. + * @param param4 The fourth parameter. + * @param The first parameter type. + * @param The second parameter type. + * @param The third parameter type. + * @param The fourth parameter type. + * @return A {@link Subscription} that can be disposed to unsubscribe from the hub method. + */ public Subscription on(String target, Action4 callback, Class param1, Class param2, Class param3, Class param4) { ActionBase action = params -> { @@ -173,6 +255,22 @@ public class HubConnection { return new Subscription(handlers, action, target); } + /** + * Registers a handler that will be invoked when the hub method with the specified method name is invoked. + * @param target The name of the hub method to define. + * @param callback The handler that will be raised when the hub method is invoked. + * @param param1 The first parameter. + * @param param2 The second parameter. + * @param param3 The third parameter. + * @param param4 The fourth parameter. + * @param param5 The fifth parameter. + * @param The first parameter type. + * @param The second parameter type. + * @param The third parameter type. + * @param The fourth parameter type. + * @param The fifth parameter type. + * @return A {@link Subscription} that can be disposed to unsubscribe from the hub method. + */ public Subscription on(String target, Action5 callback, Class param1, Class param2, Class param3, Class param4, Class param5) { ActionBase action = params -> { @@ -184,6 +282,24 @@ public class HubConnection { return new Subscription(handlers, action, target); } + /** + * Registers a handler that will be invoked when the hub method with the specified method name is invoked. + * @param target The name of the hub method to define. + * @param callback The handler that will be raised when the hub method is invoked. + * @param param1 The first parameter. + * @param param2 The second parameter. + * @param param3 The third parameter. + * @param param4 The fourth parameter. + * @param param5 The fifth parameter. + * @param param6 The sixth parameter. + * @param The first parameter type. + * @param The second parameter type. + * @param The third parameter type. + * @param The fourth parameter type. + * @param The fifth parameter type. + * @param The sixth parameter type. + * @return A {@link Subscription} that can be disposed to unsubscribe from the hub method. + */ public Subscription on(String target, Action6 callback, Class param1, Class param2, Class param3, Class param4, Class param5, Class param6) { ActionBase action = params -> { @@ -195,6 +311,26 @@ public class HubConnection { return new Subscription(handlers, action, target); } + /** + * Registers a handler that will be invoked when the hub method with the specified method name is invoked. + * @param target The name of the hub method to define. + * @param callback The handler that will be raised when the hub method is invoked. + * @param param1 The first parameter. + * @param param2 The second parameter. + * @param param3 The third parameter. + * @param param4 The fourth parameter. + * @param param5 The fifth parameter. + * @param param6 The sixth parameter. + * @param param7 The seventh parameter. + * @param The first parameter type. + * @param The second parameter type. + * @param The third parameter type. + * @param The fourth parameter type. + * @param The fifth parameter type. + * @param The sixth parameter type. + * @param The seventh parameter type. + * @return A {@link Subscription} that can be disposed to unsubscribe from the hub method. + */ public Subscription on(String target, Action7 callback, Class param1, Class param2, Class param3, Class param4, Class param5, Class param6, Class param7) { ActionBase action = params -> { @@ -206,6 +342,28 @@ public class HubConnection { return new Subscription(handlers, action, target); } + /** + * Registers a handler that will be invoked when the hub method with the specified method name is invoked. + * @param target The name of the hub method to define. + * @param callback The handler that will be raised when the hub method is invoked. + * @param param1 The first parameter. + * @param param2 The second parameter. + * @param param3 The third parameter. + * @param param4 The fourth parameter. + * @param param5 The fifth parameter. + * @param param6 The sixth parameter. + * @param param7 The seventh parameter. + * @param param8 The eighth parameter + * @param The first parameter type. + * @param The second parameter type. + * @param The third parameter type. + * @param The fourth parameter type. + * @param The fifth parameter type. + * @param The sixth parameter type. + * @param The seventh parameter type. + * @param The eighth parameter type. + * @return A {@link Subscription} that can be disposed to unsubscribe from the hub method. + */ public Subscription on(String target, Action8 callback, Class param1, Class param2, Class param3, Class param4, Class param5, Class param6, Class param7, Class param8) { ActionBase action = params -> { @@ -217,6 +375,10 @@ public class HubConnection { return new Subscription(handlers, action, target); } + /** + * Removes all handlers associated with the method with the specified method name. + * @param name The name of the hub method from which handlers are being removed. + */ public void remove(String name) { handlers.remove(name); logger.log(LogLevel.Trace, "Removing handlers for client method %s" , name); diff --git a/clients/java/signalr/src/main/java/HubMessage.java b/clients/java/signalr/src/main/java/HubMessage.java index 2c5e20175f..ca4b9a788f 100644 --- a/clients/java/signalr/src/main/java/HubMessage.java +++ b/clients/java/signalr/src/main/java/HubMessage.java @@ -1,6 +1,9 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +/** + * A base class for hub messages. + */ public abstract class HubMessage { abstract HubMessageType getMessageType(); } diff --git a/clients/java/signalr/src/main/java/HubProtocol.java b/clients/java/signalr/src/main/java/HubProtocol.java index cdb1355758..2869d9ac4a 100644 --- a/clients/java/signalr/src/main/java/HubProtocol.java +++ b/clients/java/signalr/src/main/java/HubProtocol.java @@ -1,11 +1,26 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +/** + * A protocol abstraction for communicating with SignalR hubs. + */ public interface HubProtocol { String getName(); int getVersion(); TransferFormat getTransferFormat(); + + /** + * Creates a new list of {@link HubMessage}s. + * @param message A string representation of one or more {@link HubMessage}s. + * @return A list of {@link HubMessage}s. + */ HubMessage[] parseMessages(String message); + + /** + * Writes the specified {@link HubMessage} to a String. + * @param message The message to write. + * @return A string representation of the message. + */ String writeMessage(HubMessage message); }