[Java] Fix incorrect visibility and some minor cleanup (#3112)

This commit is contained in:
BrennanConroy 2018-10-10 16:31:14 -07:00 committed by GitHub
parent 2ee351786f
commit 6861e89c8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 32 additions and 32 deletions

View File

@ -7,7 +7,7 @@ import java.util.*;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
class CallbackMap { class CallbackMap {
private Map<String, List<InvocationHandler>> handlers = new ConcurrentHashMap<>(); private final Map<String, List<InvocationHandler>> handlers = new ConcurrentHashMap<>();
public InvocationHandler put(String target, ActionBase action, Class<?>... classes) { public InvocationHandler put(String target, ActionBase action, Class<?>... classes) {
InvocationHandler handler = new InvocationHandler(action, classes); InvocationHandler handler = new InvocationHandler(action, classes);

View File

@ -22,8 +22,8 @@ import okhttp3.RequestBody;
import okhttp3.Response; import okhttp3.Response;
import okhttp3.ResponseBody; import okhttp3.ResponseBody;
class DefaultHttpClient extends HttpClient { final class DefaultHttpClient extends HttpClient {
private OkHttpClient client; private final OkHttpClient client;
private Logger logger; private Logger logger;
public DefaultHttpClient(Logger logger) { public DefaultHttpClient(Logger logger) {

View File

@ -5,7 +5,7 @@ package com.microsoft.signalr;
import com.google.gson.Gson; import com.google.gson.Gson;
class HandshakeProtocol { final class HandshakeProtocol {
private static final Gson gson = new Gson(); private static final Gson gson = new Gson();
private static final String RECORD_SEPARATOR = "\u001e"; private static final String RECORD_SEPARATOR = "\u001e";

View File

@ -8,7 +8,7 @@ import java.time.Duration;
import io.reactivex.Single; import io.reactivex.Single;
public class HttpHubConnectionBuilder { public class HttpHubConnectionBuilder {
private String url; private final String url;
private Transport transport; private Transport transport;
private Logger logger; private Logger logger;
private HttpClient httpClient; private HttpClient httpClient;
@ -56,7 +56,7 @@ public class HttpHubConnectionBuilder {
return this; return this;
} }
HttpHubConnectionBuilder withHandshakeResponseTimeout(Duration timeout) { public HttpHubConnectionBuilder withHandshakeResponseTimeout(Duration timeout) {
this.handshakeResponseTimeout = timeout; this.handshakeResponseTimeout = timeout;
return this; return this;
} }

View File

@ -24,28 +24,28 @@ import io.reactivex.Single;
public class HubConnection { public class HubConnection {
private static final String RECORD_SEPARATOR = "\u001e"; private static final String RECORD_SEPARATOR = "\u001e";
private static List<Class<?>> emptyArray = new ArrayList<>(); private static final List<Class<?>> emptyArray = new ArrayList<>();
private static int MAX_NEGOTIATE_ATTEMPTS = 100; private static final int MAX_NEGOTIATE_ATTEMPTS = 100;
private String baseUrl; private final String baseUrl;
private Transport transport; private Transport transport;
private OnReceiveCallBack callback; private OnReceiveCallBack callback;
private CallbackMap handlers = new CallbackMap(); private final CallbackMap handlers = new CallbackMap();
private HubProtocol protocol; private HubProtocol protocol;
private Boolean handshakeReceived = false; private Boolean handshakeReceived = false;
private HubConnectionState hubConnectionState = HubConnectionState.DISCONNECTED; private HubConnectionState hubConnectionState = HubConnectionState.DISCONNECTED;
private Lock hubConnectionStateLock = new ReentrantLock(); private final Lock hubConnectionStateLock = new ReentrantLock();
private Logger logger; private Logger logger;
private List<Consumer<Exception>> onClosedCallbackList; private List<Consumer<Exception>> onClosedCallbackList;
private boolean skipNegotiate; private final boolean skipNegotiate;
private Single<String> accessTokenProvider; private Single<String> accessTokenProvider;
private Map<String, String> headers = new HashMap<>(); private final Map<String, String> headers = new HashMap<>();
private ConnectionState connectionState = null; private ConnectionState connectionState = null;
private HttpClient httpClient; private final HttpClient httpClient;
private String stopError; private String stopError;
private Timer pingTimer = null; private Timer pingTimer = null;
private AtomicLong nextServerTimeout = new AtomicLong(); private final AtomicLong nextServerTimeout = new AtomicLong();
private AtomicLong nextPingActivation = new AtomicLong(); private final AtomicLong nextPingActivation = new AtomicLong();
private Duration keepAliveInterval = Duration.ofSeconds(15); private Duration keepAliveInterval = Duration.ofSeconds(15);
private Duration serverTimeout = Duration.ofSeconds(30); private Duration serverTimeout = Duration.ofSeconds(30);
private Duration tickRate = Duration.ofSeconds(1); private Duration tickRate = Duration.ofSeconds(1);

View File

@ -4,12 +4,11 @@
package com.microsoft.signalr; package com.microsoft.signalr;
public abstract class HubConnectionBuilder { public abstract class HubConnectionBuilder {
public static HttpHubConnectionBuilder create(String url) { public static HttpHubConnectionBuilder create(String url) {
if (url == null || url.isEmpty()) { if (url == null || url.isEmpty()) {
throw new IllegalArgumentException("A valid url is required."); throw new IllegalArgumentException("A valid url is required.");
} }
return new HttpHubConnectionBuilder(url); return new HttpHubConnectionBuilder(url);
} }
public abstract HubConnection build(); public abstract HubConnection build();

View File

@ -4,6 +4,8 @@
package com.microsoft.signalr; package com.microsoft.signalr;
public class HubException extends Exception { public class HubException extends Exception {
private static final long serialVersionUID = -572019264269821519L;
public HubException() { public HubException() {
} }

View File

@ -7,8 +7,8 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
class InvocationHandler { class InvocationHandler {
private List<Class<?>> classes; private final List<Class<?>> classes;
private ActionBase action; private final ActionBase action;
InvocationHandler(ActionBase action, Class<?>... classes) { InvocationHandler(ActionBase action, Class<?>... classes) {
this.action = action; this.action = action;

View File

@ -6,9 +6,9 @@ package com.microsoft.signalr;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
class InvocationRequest { class InvocationRequest {
private Class<?> returnType; private final Class<?> returnType;
private CompletableFuture<Object> pendingCall = new CompletableFuture<>(); private final CompletableFuture<Object> pendingCall = new CompletableFuture<>();
private String invocationId; private final String invocationId;
InvocationRequest(Class<?> returnType, String invocationId) { InvocationRequest(Class<?> returnType, String invocationId) {
this.returnType = returnType; this.returnType = returnType;

View File

@ -5,7 +5,7 @@ package com.microsoft.signalr;
class PingMessage extends HubMessage class PingMessage extends HubMessage
{ {
int type = HubMessageType.PING.value; private final int type = HubMessageType.PING.value;
private static PingMessage instance = new PingMessage(); private static PingMessage instance = new PingMessage();

View File

@ -4,8 +4,7 @@
package com.microsoft.signalr; package com.microsoft.signalr;
class StreamInvocationMessage extends InvocationMessage { class StreamInvocationMessage extends InvocationMessage {
private final int type = HubMessageType.STREAM_INVOCATION.value;
int type = HubMessageType.STREAM_INVOCATION.value;
public StreamInvocationMessage(String invocationId, String target, Object[] arguments) { public StreamInvocationMessage(String invocationId, String target, Object[] arguments) {
super(invocationId, target, arguments); super(invocationId, target, arguments);

View File

@ -6,9 +6,9 @@ package com.microsoft.signalr;
import java.util.List; import java.util.List;
public class Subscription { public class Subscription {
private CallbackMap handlers; private final CallbackMap handlers;
private InvocationHandler handler; private final InvocationHandler handler;
private String target; private final String target;
public Subscription(CallbackMap handlers, InvocationHandler handler, String target) { public Subscription(CallbackMap handlers, InvocationHandler handler, String target) {
this.handlers = handlers; this.handlers = handlers;

View File

@ -3,7 +3,7 @@
package com.microsoft.signalr; package com.microsoft.signalr;
public enum TransferFormat { enum TransferFormat {
TEXT, TEXT,
BINARY BINARY
} }

View File

@ -13,8 +13,8 @@ class WebSocketTransport implements Transport {
private Consumer<String> onClose; private Consumer<String> onClose;
private String url; private String url;
private Logger logger; private Logger logger;
private HttpClient client; private final HttpClient client;
private Map<String, String> headers; private final Map<String, String> headers;
private static final String HTTP = "http"; private static final String HTTP = "http";
private static final String HTTPS = "https"; private static final String HTTPS = "https";