428232 - Rework batch mode / buffering in websocket.

Improved logging by wrapping LOG.debug() calls in a
if (LOG.isDebugEnabled()) statement to avoid boxing of primitive
values.
This commit is contained in:
Simone Bordet 2014-02-18 14:01:21 +01:00
parent 0786da6cd0
commit 3240e7383b
2 changed files with 11 additions and 13 deletions

View File

@ -97,10 +97,8 @@ public class Parser
private void assertSanePayloadLength(long len) private void assertSanePayloadLength(long len)
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
{
LOG.debug("Payload Length: {} - {}",len,this); LOG.debug("Payload Length: {} - {}",len,this);
}
// Since we use ByteBuffer so often, having lengths over Integer.MAX_VALUE is really impossible. // Since we use ByteBuffer so often, having lengths over Integer.MAX_VALUE is really impossible.
if (len > Integer.MAX_VALUE) if (len > Integer.MAX_VALUE)
{ {
@ -184,9 +182,7 @@ public class Parser
protected void notifyFrame(final Frame f) protected void notifyFrame(final Frame f)
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
{
LOG.debug("{} Notify {}",policy.getBehavior(),getIncomingFramesHandler()); LOG.debug("{} Notify {}",policy.getBehavior(),getIncomingFramesHandler());
}
if (policy.getBehavior() == WebSocketBehavior.SERVER) if (policy.getBehavior() == WebSocketBehavior.SERVER)
{ {
@ -256,7 +252,8 @@ public class Parser
// parse through all the frames in the buffer // parse through all the frames in the buffer
while (parseFrame(buffer)) while (parseFrame(buffer))
{ {
LOG.debug("{} Parsed Frame: {}",policy.getBehavior(),frame); if (LOG.isDebugEnabled())
LOG.debug("{} Parsed Frame: {}",policy.getBehavior(),frame);
notifyFrame(frame); notifyFrame(frame);
if (frame.isDataFrame()) if (frame.isDataFrame())
{ {
@ -301,7 +298,8 @@ public class Parser
*/ */
private boolean parseFrame(ByteBuffer buffer) private boolean parseFrame(ByteBuffer buffer)
{ {
LOG.debug("{} Parsing {} bytes",policy.getBehavior(),buffer.remaining()); if (LOG.isDebugEnabled())
LOG.debug("{} Parsing {} bytes",policy.getBehavior(),buffer.remaining());
while (buffer.hasRemaining()) while (buffer.hasRemaining())
{ {
switch (state) switch (state)
@ -320,14 +318,12 @@ public class Parser
} }
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
{
LOG.debug("OpCode {}, fin={} rsv={}{}{}", LOG.debug("OpCode {}, fin={} rsv={}{}{}",
OpCode.name(opcode), OpCode.name(opcode),
fin, fin,
(isRsv1InUse()?'1':'.'), (isRsv1InUse()?'1':'.'),
(isRsv2InUse()?'1':'.'), (isRsv2InUse()?'1':'.'),
(isRsv3InUse()?'1':'.')); (isRsv3InUse()?'1':'.'));
}
// base framing flags // base framing flags
switch(opcode) switch(opcode)
@ -419,9 +415,7 @@ public class Parser
else else
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
{
LOG.debug("OpCode {}, fin={} rsv=000",OpCode.name(opcode),fin); LOG.debug("OpCode {}, fin={} rsv=000",OpCode.name(opcode),fin);
}
} }
state = State.PAYLOAD_LEN; state = State.PAYLOAD_LEN;
@ -598,9 +592,7 @@ public class Parser
buffer.position(buffer.position() + window.remaining()); buffer.position(buffer.position() + window.remaining());
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
{
LOG.debug("Window: {}",BufferUtil.toDetailString(window)); LOG.debug("Window: {}",BufferUtil.toDetailString(window));
}
maskProcessor.process(window); maskProcessor.process(window);

View File

@ -452,4 +452,10 @@ public class WebSocketRemoteEndpoint implements RemoteEndpoint
unlockMsg(MsgType.ASYNC); unlockMsg(MsgType.ASYNC);
} }
} }
@Override
public String toString()
{
return String.format("%s@%x[batching=%b]", getClass().getSimpleName(), hashCode(), isBatching());
}
} }