refactor: make fields final when possible

This commit is contained in:
Damien Arrachequesne
2025-02-18 09:32:41 +01:00
parent 54852ce2a4
commit e2cdf7b99c
2 changed files with 15 additions and 20 deletions

View File

@@ -72,20 +72,20 @@ public class Manager extends Emitter {
private long _reconnectionDelay; private long _reconnectionDelay;
private long _reconnectionDelayMax; private long _reconnectionDelayMax;
private double _randomizationFactor; private double _randomizationFactor;
private Backoff backoff; private final Backoff backoff;
private long _timeout; private long _timeout;
private URI uri; private final URI uri;
private List<Packet> packetBuffer; private final List<Packet> packetBuffer = new ArrayList<>();
private Queue<On.Handle> subs; private final Queue<On.Handle> subs = new LinkedList<>();;
private Options opts; private final Options opts;
/*package*/ io.socket.engineio.client.Socket engine; /*package*/ io.socket.engineio.client.Socket engine;
private Parser.Encoder encoder; private final Parser.Encoder encoder;
private Parser.Decoder decoder; private final Parser.Decoder decoder;
/** /**
* This HashMap can be accessed from outside of EventThread. * This HashMap can be accessed from outside of EventThread.
*/ */
/*package*/ ConcurrentHashMap<String, Socket> nsps; /*package*/ final Map<String, Socket> nsps = new ConcurrentHashMap<>();
public Manager() { public Manager() {
@@ -114,8 +114,6 @@ public class Manager extends Emitter {
opts.callFactory = defaultCallFactory; opts.callFactory = defaultCallFactory;
} }
this.opts = opts; this.opts = opts;
this.nsps = new ConcurrentHashMap<>();
this.subs = new LinkedList<>();
this.reconnection(opts.reconnection); this.reconnection(opts.reconnection);
this.reconnectionAttempts(opts.reconnectionAttempts != 0 ? opts.reconnectionAttempts : Integer.MAX_VALUE); this.reconnectionAttempts(opts.reconnectionAttempts != 0 ? opts.reconnectionAttempts : Integer.MAX_VALUE);
this.reconnectionDelay(opts.reconnectionDelay != 0 ? opts.reconnectionDelay : 1000); this.reconnectionDelay(opts.reconnectionDelay != 0 ? opts.reconnectionDelay : 1000);
@@ -129,7 +127,6 @@ public class Manager extends Emitter {
this.readyState = ReadyState.CLOSED; this.readyState = ReadyState.CLOSED;
this.uri = uri; this.uri = uri;
this.encoding = false; this.encoding = false;
this.packetBuffer = new ArrayList<>();
this.encoder = opts.encoder != null ? opts.encoder : new IOParser.Encoder(); this.encoder = opts.encoder != null ? opts.encoder : new IOParser.Encoder();
this.decoder = opts.decoder != null ? opts.decoder : new IOParser.Decoder(); this.decoder = opts.decoder != null ? opts.decoder : new IOParser.Decoder();
} }

View File

@@ -57,23 +57,21 @@ public class Socket extends Emitter {
private volatile boolean connected; private volatile boolean connected;
private int ids; private int ids;
private String nsp; private final String nsp;
private Manager io; private final Manager io;
private Map<String, String> auth; private final Map<String, String> auth;
private Map<Integer, Ack> acks = new ConcurrentHashMap<>(); private final Map<Integer, Ack> acks = new ConcurrentHashMap<>();
private Queue<On.Handle> subs; private Queue<On.Handle> subs;
private final Queue<List<Object>> receiveBuffer = new ConcurrentLinkedQueue<>(); private final Queue<List<Object>> receiveBuffer = new ConcurrentLinkedQueue<>();
private final Queue<Packet<JSONArray>> sendBuffer = new ConcurrentLinkedQueue<>(); private final Queue<Packet<JSONArray>> sendBuffer = new ConcurrentLinkedQueue<>();
private ConcurrentLinkedQueue<Listener> onAnyIncomingListeners = new ConcurrentLinkedQueue<>(); private final ConcurrentLinkedQueue<Listener> onAnyIncomingListeners = new ConcurrentLinkedQueue<>();
private ConcurrentLinkedQueue<Listener> onAnyOutgoingListeners = new ConcurrentLinkedQueue<>(); private final ConcurrentLinkedQueue<Listener> onAnyOutgoingListeners = new ConcurrentLinkedQueue<>();
public Socket(Manager io, String nsp, Manager.Options opts) { public Socket(Manager io, String nsp, Manager.Options opts) {
this.io = io; this.io = io;
this.nsp = nsp; this.nsp = nsp;
if (opts != null) { this.auth = opts != null ? opts.auth : null;
this.auth = opts.auth;
}
} }
private void subEvents() { private void subEvents() {