Add condition to log only if fine level is loggable
Even if FINE level is not loggable String.format() works every time and tries to format string with all the events. Sometimes it causes OutOfMemory exceptions.
This commit is contained in:
@@ -3,6 +3,7 @@ package io.socket.client;
|
||||
|
||||
import io.socket.parser.Parser;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.net.URI;
|
||||
@@ -72,11 +73,15 @@ public class IO {
|
||||
Manager io;
|
||||
|
||||
if (newConnection) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("ignoring socket cache for %s", source));
|
||||
}
|
||||
io = new Manager(source, opts);
|
||||
} else {
|
||||
if (!managers.containsKey(id)) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("new io instance for %s", source));
|
||||
}
|
||||
managers.putIfAbsent(id, new Manager(source, opts));
|
||||
}
|
||||
io = managers.get(id);
|
||||
|
||||
@@ -250,10 +250,14 @@ public class Manager extends Emitter {
|
||||
EventThread.exec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("readyState %s", Manager.this.readyState));
|
||||
}
|
||||
if (Manager.this.readyState == ReadyState.OPEN || Manager.this.readyState == ReadyState.OPENING) return;
|
||||
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("opening %s", Manager.this.uri));
|
||||
}
|
||||
Manager.this.engine = new Engine(Manager.this.uri, Manager.this.opts);
|
||||
final io.socket.engineio.client.Socket socket = Manager.this.engine;
|
||||
final Manager self = Manager.this;
|
||||
@@ -453,7 +457,9 @@ public class Manager extends Emitter {
|
||||
}
|
||||
|
||||
/*package*/ void packet(Packet packet) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("writing packet %s", packet));
|
||||
}
|
||||
final Manager self = this;
|
||||
|
||||
if (!self.encoding) {
|
||||
|
||||
@@ -273,7 +273,9 @@ public class Socket extends Emitter {
|
||||
}
|
||||
|
||||
private void onclose(String reason) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("close (%s)", reason));
|
||||
}
|
||||
this.connected = false;
|
||||
this.id = null;
|
||||
this.emit(EVENT_DISCONNECT, reason);
|
||||
@@ -327,7 +329,9 @@ public class Socket extends Emitter {
|
||||
|
||||
private void onevent(Packet<JSONArray> packet) {
|
||||
List<Object> args = new ArrayList<Object>(Arrays.asList(toArray(packet.data)));
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("emitting event %s", args));
|
||||
}
|
||||
|
||||
if (packet.id >= 0) {
|
||||
logger.fine("attaching ack callback to event");
|
||||
@@ -354,7 +358,9 @@ public class Socket extends Emitter {
|
||||
public void run() {
|
||||
if (sent[0]) return;
|
||||
sent[0] = true;
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("sending ack %s", args.length != 0 ? args : null));
|
||||
}
|
||||
|
||||
JSONArray jsonArgs = new JSONArray();
|
||||
for (Object arg : args) {
|
||||
@@ -375,12 +381,16 @@ public class Socket extends Emitter {
|
||||
private void onack(Packet<JSONArray> packet) {
|
||||
Ack fn = this.acks.remove(packet.id);
|
||||
if (fn != null) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("calling ack %s with %s", packet.id, packet.data));
|
||||
}
|
||||
fn.call(toArray(packet.data));
|
||||
} else {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("bad ack %s", packet.id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void onconnect() {
|
||||
this.connected = true;
|
||||
@@ -404,7 +414,9 @@ public class Socket extends Emitter {
|
||||
}
|
||||
|
||||
private void ondisconnect() {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("server disconnect (%s)", this.nsp));
|
||||
}
|
||||
this.destroy();
|
||||
this.onclose("io server disconnect");
|
||||
}
|
||||
@@ -431,7 +443,9 @@ public class Socket extends Emitter {
|
||||
@Override
|
||||
public void run() {
|
||||
if (Socket.this.connected) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("performing disconnect (%s)", Socket.this.nsp));
|
||||
}
|
||||
Socket.this.packet(new Packet(Parser.DISCONNECT));
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,9 @@ public class Parser {
|
||||
public Encoder() {}
|
||||
|
||||
public void encode(Packet obj, Callback callback) {
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("encoding packet %s", obj));
|
||||
}
|
||||
|
||||
if (BINARY_EVENT == obj.type || BINARY_ACK == obj.type) {
|
||||
encodeAsBinary(obj, callback);
|
||||
@@ -116,7 +118,9 @@ public class Parser {
|
||||
str.append(obj.data);
|
||||
}
|
||||
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("encoded %s as %s", obj, str));
|
||||
}
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
@@ -233,7 +237,9 @@ public class Parser {
|
||||
}
|
||||
}
|
||||
|
||||
if (logger.isLoggable(Level.FINE)) {
|
||||
logger.fine(String.format("decoded %s as %s", str, p));
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user