Adding Javadocs (#2745)

This commit is contained in:
Mikael Mengistu 2018-08-07 15:10:22 -06:00 committed by GitHub
parent d8741d1b0f
commit 02d1d4b1aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 180 additions and 0 deletions

View File

@ -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 <T1> The first argument type.
* @return A {@link Subscription} that can be disposed to unsubscribe from the hub method.
*/
public <T1> Subscription on(String target, Action1<T1> callback, Class<T1> 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 <T1> The first parameter type.
* @param <T2> The second parameter type.
* @return A {@link Subscription} that can be disposed to unsubscribe from the hub method.
*/
public <T1, T2> Subscription on(String target, Action2<T1, T2> callback, Class<T1> param1, Class<T2> 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 <T1> The first parameter type.
* @param <T2> The second parameter type.
* @param <T3> The third parameter type.
* @return A {@link Subscription} that can be disposed to unsubscribe from the hub method.
*/
public <T1, T2, T3> Subscription on(String target, Action3<T1, T2, T3> callback,
Class<T1> param1, Class<T2> param2, Class<T3> 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 <T1> The first parameter type.
* @param <T2> The second parameter type.
* @param <T3> The third parameter type.
* @param <T4> The fourth parameter type.
* @return A {@link Subscription} that can be disposed to unsubscribe from the hub method.
*/
public <T1, T2, T3, T4> Subscription on(String target, Action4<T1, T2, T3, T4> callback,
Class<T1> param1, Class<T2> param2, Class<T3> param3, Class<T4> 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 <T1> The first parameter type.
* @param <T2> The second parameter type.
* @param <T3> The third parameter type.
* @param <T4> The fourth parameter type.
* @param <T5> The fifth parameter type.
* @return A {@link Subscription} that can be disposed to unsubscribe from the hub method.
*/
public <T1, T2, T3, T4, T5> Subscription 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) {
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 <T1> The first parameter type.
* @param <T2> The second parameter type.
* @param <T3> The third parameter type.
* @param <T4> The fourth parameter type.
* @param <T5> The fifth parameter type.
* @param <T6> The sixth parameter type.
* @return A {@link Subscription} that can be disposed to unsubscribe from the hub method.
*/
public <T1, T2, T3, T4, T5, T6> Subscription 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) {
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 <T1> The first parameter type.
* @param <T2> The second parameter type.
* @param <T3> The third parameter type.
* @param <T4> The fourth parameter type.
* @param <T5> The fifth parameter type.
* @param <T6> The sixth parameter type.
* @param <T7> The seventh parameter type.
* @return A {@link Subscription} that can be disposed to unsubscribe from the hub method.
*/
public <T1, T2, T3, T4, T5, T6, T7> Subscription 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) {
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 <T1> The first parameter type.
* @param <T2> The second parameter type.
* @param <T3> The third parameter type.
* @param <T4> The fourth parameter type.
* @param <T5> The fifth parameter type.
* @param <T6> The sixth parameter type.
* @param <T7> The seventh parameter type.
* @param <T8> The eighth parameter type.
* @return A {@link Subscription} that can be disposed to unsubscribe from the hub method.
*/
public <T1, T2, T3, T4, T5, T6, T7, T8> Subscription 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) {
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);

View File

@ -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();
}

View File

@ -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);
}