Updated toString() implementations.

This commit is contained in:
Simone Bordet 2011-12-16 20:53:15 +01:00
parent 300157fb2d
commit a88e2c5ebb
8 changed files with 79 additions and 56 deletions

View File

@ -355,9 +355,8 @@ public abstract class AbstractHttpConnection extends AbstractConnection implemen
@Override
public String toString()
{
return String.format("%s@%x//%s,g=%s,p=%s",
getClass().getSimpleName(),
hashCode(),
return String.format("%s %s g=%s p=%s",
super.toString(),
_destination == null ? "?.?.?.?:??" : _destination.getAddress(),
_generator,
_parser);

View File

@ -62,12 +62,6 @@ public abstract class AbstractConnection implements Connection
public String toString()
{
return String.format("%s@%x//%s:%d<->%s:%d",
getClass().getSimpleName(),
hashCode(),
_endp.getLocalAddr(),
_endp.getLocalPort(),
_endp.getRemoteAddr(),
_endp.getRemotePort());
return String.format("%s@%x", getClass().getSimpleName(), hashCode());
}
}

View File

@ -280,7 +280,7 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
public void checkIdleTimestamp(long now)
{
long idleTimestamp=_idleTimestamp;
if (idleTimestamp!=0 && _maxIdleTime>0)
{
long idleForMs=now-idleTimestamp;
@ -709,24 +709,43 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
@Override
public String toString()
{
synchronized(this)
// Do NOT use synchronized (this)
// because it's very easy to deadlock when debugging is enabled.
// We do a best effort to print the right toString() and that's it.
SelectionKey key = _key;
String keyString = "";
if (key != null)
{
return String.format("SCEP@%x{%s->%s,d=%b,open=%b,ishut=%b,oshut=%b,rb=%b,wb=%b,w=%b,i=%d%s%s%s}",
hashCode(),
_socket.getRemoteSocketAddress(),
_socket.getLocalSocketAddress(),
_dispatched,
isOpen(),
isInputShutdown(),
isOutputShutdown(),
_readBlocked,
_writeBlocked,
_writable,
_interestOps,
_key != null && _key.isValid() ? "" : "!",
_key != null && _key.isValid() && _key.isReadable() ? "r" : "",
_key != null && _key.isValid() && _key.isWritable() ? "w" : "");
if (key.isValid())
{
if (key.isReadable())
keyString += "r";
if (key.isWritable())
keyString += "w";
}
else
{
keyString += "!";
}
}
else
{
keyString += "-";
}
return String.format("SCEP@%x{l(%s)<->r(%s),d=%b,open=%b,ishut=%b,oshut=%b,rb=%b,wb=%b,w=%b,i=%d%s}-{%s}",
hashCode(),
_socket.getRemoteSocketAddress(),
_socket.getLocalSocketAddress(),
_dispatched,
isOpen(),
isInputShutdown(),
isOutputShutdown(),
_readBlocked,
_writeBlocked,
_writable,
_interestOps,
keyString,
_connection);
}
/* ------------------------------------------------------------ */

View File

@ -571,7 +571,7 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
public String toString()
{
return String.format("%s | %s", super.toString(), _sslEndPoint);
return String.format("%s %s", super.toString(), _sslEndPoint);
}
/* ------------------------------------------------------------ */
@ -793,20 +793,20 @@ public class SslConnection extends AbstractConnection implements AsyncConnection
public String toString()
{
int i;
int o;
int u;
synchronized(SslConnection.this)
{
i=_inbound==null?-1:_inbound.length();
o=_outbound==null?-1:_outbound.length();
u=_unwrapBuf==null?-1:_unwrapBuf.length();
}
return String.format("SSL:%s %s i/u/o=%d/%d/%d ishut=%b oshut=%b",
_endp,
// Do NOT use synchronized (SslConnection.this)
// because it's very easy to deadlock when debugging is enabled.
// We do a best effort to print the right toString() and that's it.
Buffer inbound = _inbound;
Buffer outbound = _outbound;
Buffer unwrap = _unwrapBuf;
int i = inbound == null? -1 : inbound.length();
int o = outbound == null ? -1 : outbound.length();
int u = unwrap == null ? -1 : unwrap.length();
return String.format("SSL %s i/o/u=%d/%d/%d ishut=%b oshut=%b {%s}",
_engine.getHandshakeStatus(),
i, u, o,
_ishut, _oshut);
i, o, u,
_ishut, _oshut,
_connection);
}
}
}

View File

@ -18,7 +18,6 @@ import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -28,7 +27,6 @@ import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.nio.SelectChannelEndPoint;
import org.eclipse.jetty.util.B64Code;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.Utf8StringBuilder;
@ -840,6 +838,6 @@ public class WebSocketConnectionD08 extends AbstractConnection implements WebSoc
@Override
public String toString()
{
return "WS/D"+_draft+"-"+_endp;
return String.format("WS/D%d p=%s g=%s", _draft, _parser, _generator);
}
}

View File

@ -18,7 +18,6 @@ import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -28,7 +27,6 @@ import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.io.nio.SelectChannelEndPoint;
import org.eclipse.jetty.util.B64Code;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.Utf8Appendable;
@ -916,7 +914,7 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
return WebSocketConnectionD13.this.toString()+"FH";
}
}
/* ------------------------------------------------------------ */
public void handshake(HttpServletRequest request, HttpServletResponse response, String subprotocol) throws IOException
{
@ -958,6 +956,6 @@ public class WebSocketConnectionD13 extends AbstractConnection implements WebSoc
@Override
public String toString()
{
return "WS/D"+_draft+"-"+_endp;
return String.format("WS/D%d p=%s g=%s", _draft, _parser, _generator);
}
}

View File

@ -65,7 +65,7 @@ public class WebSocketGeneratorD13 implements WebSocketGenerator
throw new EofException("Closed");
if (opcode==WebSocketConnectionD13.OP_CLOSE)
_closed=true;
boolean mask=_maskGen!=null;
if (_buffer==null)
@ -240,4 +240,17 @@ public class WebSocketGeneratorD13 implements WebSocketGenerator
}
}
@Override
public String toString()
{
// Do NOT use synchronized (this)
// because it's very easy to deadlock when debugging is enabled.
// We do a best effort to print the right toString() and that's it.
Buffer buffer = _buffer;
return String.format("%s@%x closed=%b buffer=%d",
getClass().getSimpleName(),
hashCode(),
_closed,
buffer == null ? -1 : buffer.length());
}
}

View File

@ -125,7 +125,7 @@ public class WebSocketParserD13 implements WebSocketParser
{
if (_buffer==null)
_buffer=_buffers.getBuffer();
boolean progress=false;
int filled=-1;
@ -189,7 +189,7 @@ public class WebSocketParserD13 implements WebSocketParser
// Did we get enough?
if (available<(_state==State.SKIP?1:_bytesNeeded))
break;
// if we are here, then we have sufficient bytes to process the current state.
// Parse the buffer byte by byte (unless it is STATE_DATA)
byte b;
@ -307,7 +307,7 @@ public class WebSocketParserD13 implements WebSocketParser
if (_bytesNeeded==0)
_state=State.START;
break;
case SEEK_EOF:
progress=true;
_buffer.skip(available);
@ -349,7 +349,7 @@ public class WebSocketParserD13 implements WebSocketParser
break;
}
}
return progress?1:filled;
}
@ -380,8 +380,10 @@ public class WebSocketParserD13 implements WebSocketParser
@Override
public String toString()
{
Buffer buffer=_buffer;
return WebSocketParserD13.class.getSimpleName()+"@"+ Integer.toHexString(hashCode())+"|"+_state+"|"+(buffer==null?"<>":buffer.toDetailString());
return String.format("%s@%x state=%s buffer=%s",
getClass().getSimpleName(),
hashCode(),
_state,
_buffer);
}
}