Rewritten toString() methods using String.format().

This commit is contained in:
Simone Bordet 2011-11-24 15:20:06 +01:00
parent 0b85184722
commit 59c111bde1
3 changed files with 28 additions and 16 deletions

View File

@ -149,7 +149,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection implemen
}
public abstract Connection handle() throws IOException;
public boolean isIdle()
{
@ -275,7 +275,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection implemen
_endp.close();
return;
}
switch(status)
{
case HttpStatus.CONTINUE_100:
@ -295,7 +295,7 @@ public abstract class AbstractHttpConnection extends AbstractConnection implemen
_status=status;
exchange.getEventListener().onResponseStatus(version,status,reason);
exchange.setStatus(HttpExchange.STATUS_PARSING_HEADERS);
}
@Override
@ -353,16 +353,19 @@ public abstract class AbstractHttpConnection extends AbstractConnection implemen
}
}
}
}
@Override
public String toString()
{
return "HttpConnection@" + hashCode() + "//" +
(_destination==null?"?.?.?.?:??":(_destination.getAddress().getHost() + ":" + _destination.getAddress().getPort()))+
",g="+_generator.getState()+",p="+_parser.getState();
return String.format("%s@%x//%s,g=%s,p=%s",
getClass().getSimpleName(),
hashCode(),
_destination == null ? "?.?.?.?:??" : _destination.getAddress(),
_generator,
_parser);
}
public String toDetailString()

View File

@ -11,14 +11,14 @@ public abstract class AbstractConnection implements Connection
private static final Logger LOG = Log.getLogger(AbstractConnection.class);
private final long _timeStamp;
protected final EndPoint _endp;
protected final EndPoint _endp;
public AbstractConnection(EndPoint endp)
{
_endp=(EndPoint)endp;
_timeStamp = System.currentTimeMillis();
}
public AbstractConnection(EndPoint endp,long timestamp)
{
_endp=(EndPoint)endp;
@ -29,7 +29,7 @@ public abstract class AbstractConnection implements Connection
{
return _timeStamp;
}
public EndPoint getEndPoint()
{
return _endp;
@ -52,13 +52,19 @@ public abstract class AbstractConnection implements Connection
catch(IOException e2)
{
LOG.ignore(e2);
}
}
}
public String toString()
{
return this.getClass().getSimpleName()+"@"+_endp.getLocalAddr()+":"+_endp.getLocalPort()+"<->"+_endp.getRemoteAddr()+":"+_endp.getRemotePort();
return String.format("%s@%x//%s:%d<->%s:%d",
getClass().getSimpleName(),
hashCode(),
_endp.getLocalAddr(),
_endp.getLocalPort(),
_endp.getRemoteAddr(),
_endp.getRemotePort());
}
}

View File

@ -55,7 +55,6 @@ import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.thread.Timeout;
/**
* <p>A HttpConnection represents the connection of a HTTP client to the server
@ -680,7 +679,11 @@ public abstract class AbstractHttpConnection extends AbstractConnection
/* ------------------------------------------------------------ */
public String toString()
{
return super.toString()+" "+_parser+" "+_generator+" "+_requests;
return String.format("%s,g=%s,p=%s,r=%d",
super.toString(),
_generator,
_parser,
_requests);
}
/* ------------------------------------------------------------ */