Merge pull request #3245 from eclipse/jetty-9.4.x-issue-3242-websocket-dump-cleanup
Issue #3242 - WebSocket dump cleanup
This commit is contained in:
commit
aa7f3bd071
|
@ -620,6 +620,16 @@ public class ProxyConnectionFactory extends AbstractConnectionFactory
|
|||
return _remote;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s@%x[remote=%s,local=%s,endpoint=%s]",
|
||||
getClass().getSimpleName(),
|
||||
hashCode(),
|
||||
_remote,
|
||||
_local,
|
||||
_endp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOpen()
|
||||
{
|
||||
|
|
|
@ -70,6 +70,15 @@ public interface Dumpable
|
|||
return b.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* The description of this/self found in the dump.
|
||||
* Allows for alternative representation of Object other then .toString()
|
||||
* where the long form output of toString() is represented in a cleaner way
|
||||
* within the dump infrastructure.
|
||||
*
|
||||
* @return the representation of self
|
||||
*/
|
||||
default String dumpSelf() { return toString(); }
|
||||
|
||||
/**
|
||||
* Dump just an Object (but not it's contained items) to an Appendable.
|
||||
|
@ -90,6 +99,8 @@ public interface Dumpable
|
|||
s = String.format("%s@%x[size=%d]",o.getClass().getComponentType(),o.hashCode(), Array.getLength(o));
|
||||
else if (o instanceof Map)
|
||||
s = String.format("%s@%x{size=%d}",o.getClass().getName(),o.hashCode(),((Map<?,?>)o).size());
|
||||
else if (o instanceof Dumpable)
|
||||
s = ((Dumpable)o).dumpSelf().replace("\r\n","|").replace("\n","|");
|
||||
else
|
||||
s = String.valueOf(o).replace("\r\n","|").replace("\n","|");
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.eclipse.jetty.util.Callback;
|
|||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.component.Dumpable;
|
||||
import org.eclipse.jetty.util.component.DumpableCollection;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
@ -277,11 +278,13 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Rem
|
|||
}
|
||||
|
||||
@Override
|
||||
public void dump(Appendable out, String indent) throws IOException
|
||||
{
|
||||
dumpObjects(out,indent,
|
||||
DumpableCollection.from("incoming", incomingHandler),
|
||||
DumpableCollection.from("outgoing", outgoingHandler));
|
||||
public String dumpSelf() {
|
||||
return String.format("%s@%x[behavior=%s,batchMode=%s,idleTimeout=%d,requestURI=%s]",
|
||||
this.getClass().getSimpleName(), hashCode(),
|
||||
getPolicy().getBehavior(),
|
||||
getBatchMode(),
|
||||
getIdleTimeout(),
|
||||
getRequestURI());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -39,7 +39,7 @@ import org.eclipse.jetty.websocket.common.LogicalConnection;
|
|||
import org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope;
|
||||
|
||||
@ManagedObject("Abstract Extension")
|
||||
public abstract class AbstractExtension extends AbstractLifeCycle implements Dumpable, Extension
|
||||
public abstract class AbstractExtension extends AbstractLifeCycle implements Extension
|
||||
{
|
||||
private final Logger log;
|
||||
private WebSocketPolicy policy;
|
||||
|
@ -54,27 +54,6 @@ public abstract class AbstractExtension extends AbstractLifeCycle implements Dum
|
|||
log = Log.getLogger(this.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String dump()
|
||||
{
|
||||
return Dumpable.dump(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dump(Appendable out, String indent) throws IOException
|
||||
{
|
||||
// incoming
|
||||
dumpWithHeading(out, indent, "incoming", this.nextIncoming);
|
||||
dumpWithHeading(out, indent, "outgoing", this.nextOutgoing);
|
||||
}
|
||||
|
||||
protected void dumpWithHeading(Appendable out, String indent, String heading, Object bean) throws IOException
|
||||
{
|
||||
out.append(indent).append(" +- ");
|
||||
out.append(heading).append(" : ");
|
||||
out.append(bean.toString());
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void init(WebSocketContainerScope container)
|
||||
{
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.eclipse.jetty.util.IteratingCallback;
|
|||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.component.ContainerLifeCycle;
|
||||
import org.eclipse.jetty.util.component.DumpableCollection;
|
||||
import org.eclipse.jetty.util.component.LifeCycle;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
@ -108,20 +109,8 @@ public class ExtensionStack extends ContainerLifeCycle implements IncomingFrames
|
|||
}
|
||||
|
||||
@Override
|
||||
public void dump(Appendable out, String indent) throws IOException
|
||||
{
|
||||
super.dump(out,indent);
|
||||
|
||||
IncomingFrames websocket = getLastIncoming();
|
||||
OutgoingFrames network = getLastOutgoing();
|
||||
|
||||
out.append(indent).append(" +- Stack").append(System.lineSeparator());
|
||||
out.append(indent).append(" +- Network : ").append(network.toString()).append(System.lineSeparator());
|
||||
for (Extension ext : extensions)
|
||||
{
|
||||
out.append(indent).append(" +- Extension: ").append(ext.toString()).append(System.lineSeparator());
|
||||
}
|
||||
out.append(indent).append(" +- Websocket: ").append(websocket.toString()).append(System.lineSeparator());
|
||||
public String dumpSelf() {
|
||||
return String.format("%s@%x[size=%d,queueSize=%d]", getClass().getSimpleName(), hashCode(), extensions.size(), getQueueSize());
|
||||
}
|
||||
|
||||
@ManagedAttribute(name = "Extension List", readonly = true)
|
||||
|
|
|
@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.eclipse.jetty.io.AbstractConnection;
|
||||
import org.eclipse.jetty.io.AbstractEndPoint;
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.io.Connection;
|
||||
import org.eclipse.jetty.io.EndPoint;
|
||||
|
@ -631,15 +632,16 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp
|
|||
}
|
||||
|
||||
@Override
|
||||
public String dump()
|
||||
{
|
||||
return Dumpable.dump(this);
|
||||
public String dumpSelf() {
|
||||
return String.format("%s@%x", this.getClass().getSimpleName(), hashCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dump(Appendable out, String indent) throws IOException
|
||||
{
|
||||
out.append(toString()).append(System.lineSeparator());
|
||||
public void dump(Appendable out, String indent) throws IOException {
|
||||
EndPoint endp = getEndPoint();
|
||||
Object endpRef = endp.toString();
|
||||
if(endp instanceof AbstractEndPoint)
|
||||
endpRef = ((AbstractEndPoint) endp).toEndPointString();
|
||||
Dumpable.dumpObjects(out, indent, this, endpRef, ioState, flusher, generator, parser);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -337,9 +337,8 @@ public class FrameFlusher extends IteratingCallback
|
|||
ByteBuffer agg = aggregate;
|
||||
if (agg != null)
|
||||
aggSize = agg.position();
|
||||
return String.format("%s@%x[queueSize=%d,aggregateSize=%d,terminated=%s]",
|
||||
getClass().getSimpleName(),
|
||||
hashCode(),
|
||||
return String.format("%s[queueSize=%d,aggregateSize=%d,terminated=%s]",
|
||||
super.toString(),
|
||||
getQueueSize(),
|
||||
aggSize,
|
||||
terminated);
|
||||
|
|
|
@ -18,14 +18,22 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.server.browser;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.handler.ResourceHandler;
|
||||
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.PathResource;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
|
||||
import org.eclipse.jetty.websocket.common.extensions.FrameCaptureExtension;
|
||||
import org.eclipse.jetty.websocket.server.WebSocketHandler;
|
||||
|
@ -120,8 +128,7 @@ public class BrowserDebugTool implements WebSocketCreator
|
|||
return connector.getLocalPort();
|
||||
}
|
||||
|
||||
public void prepare(int port)
|
||||
{
|
||||
public void prepare(int port) throws IOException, URISyntaxException {
|
||||
server = new Server();
|
||||
connector = new ServerConnector(server);
|
||||
connector.setPort(port);
|
||||
|
@ -150,16 +157,22 @@ public class BrowserDebugTool implements WebSocketCreator
|
|||
|
||||
server.setHandler(wsHandler);
|
||||
|
||||
String resourceBase = "src/test/resources/browser-debug-tool";
|
||||
Resource staticResourceBase = findStaticResources();
|
||||
|
||||
ResourceHandler rHandler = new ResourceHandler();
|
||||
rHandler.setDirectoriesListed(true);
|
||||
rHandler.setResourceBase(resourceBase);
|
||||
rHandler.setBaseResource(staticResourceBase);
|
||||
wsHandler.setHandler(rHandler);
|
||||
|
||||
LOG.info("{} setup on port {}",this.getClass().getName(),port);
|
||||
}
|
||||
|
||||
private Resource findStaticResources() throws FileNotFoundException, URISyntaxException, MalformedURLException {
|
||||
Path path = MavenTestingUtils.getTestResourcePathDir("browser-debug-tool");
|
||||
LOG.info("Static Resources: {}", path);
|
||||
return new PathResource(path);
|
||||
}
|
||||
|
||||
public void start() throws Exception
|
||||
{
|
||||
server.start();
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
|
|||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
|
||||
import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
|
||||
import org.eclipse.jetty.websocket.api.annotations.WebSocket;
|
||||
import org.eclipse.jetty.websocket.common.WebSocketSession;
|
||||
|
||||
@WebSocket
|
||||
public class BrowserSocket
|
||||
|
@ -226,6 +227,11 @@ public class BrowserSocket
|
|||
writeMessage("Server time: %s",sdf.format(now.getTime()));
|
||||
break;
|
||||
}
|
||||
case "dump":
|
||||
{
|
||||
((WebSocketSession)session).dumpStdErr();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
writeMessage("key[%s] val[%s]",key,val);
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
<input id="manythreads" class="button" type="submit" name="many" value="manythreads" disabled="disabled"/>
|
||||
<input id="hello" class="button" type="submit" name="hello" value="hello" disabled="disabled"/>
|
||||
<input id="there" class="button" type="submit" name="there" value="there" disabled="disabled"/>
|
||||
<input id="dump" class="button" type="submit" name="dump" value="dump" disabled="disabled"/>
|
||||
<input id="json" class="button" type="submit" name="json" value="json" disabled="disabled"/>
|
||||
<input id="twain" class="button" type="submit" name="twain" value="twain" disabled="disabled"/>
|
||||
<input id="send10k" class="button" type="submit" name="send10k" value="send10k" disabled="disabled"/>
|
||||
<input id="send100k" class="button" type="submit" name="send100k" value="send100k" disabled="disabled"/>
|
||||
<input id="send1000k" class="button" type="submit" name="send1000k" value="send1000k" disabled="disabled"/>
|
||||
|
@ -32,7 +32,7 @@
|
|||
$("manythreads").onclick = function(event) {wstool.write("manythreads:20,25,60"); return false; }
|
||||
$("hello").onclick = function(event) {wstool.write("Hello"); return false; }
|
||||
$("there").onclick = function(event) {wstool.write("There"); return false; }
|
||||
$("twain").onclick = function(event) {wstool.write("@twain.txt"); return false; }
|
||||
$("dump").onclick = function(event) {wstool.write("dump:"); return false; }
|
||||
$("json").onclick = function(event) {wstool.write("[{\"channel\":\"/meta/subscribe\",\"subscription\":\"/chat/demo\",\"id\":\"2\",\"clientId\":\"81dwnxwbgs0h0bq8968b0a0gyl\",\"timestamp\":\"Thu,"
|
||||
+ " 12 Sep 2013 19:42:30 GMT\"},{\"channel\":\"/meta/subscribe\",\"subscription\":\"/members/demo\",\"id\":\"3\",\"clientId\":\"81dwnxwbgs0h0bq8968b0a0gyl\",\"timestamp\":\"Thu,"
|
||||
+ " 12 Sep 2013 19:42:30 GMT\"},{\"channel\":\"/chat/demo\",\"data\":{\"user\":\"ch\",\"membership\":\"join\",\"chat\":\"ch"
|
||||
|
|
|
@ -84,8 +84,8 @@ var wstool = {
|
|||
$('manythreads').disabled = !enabled;
|
||||
$('hello').disabled = !enabled;
|
||||
$('there').disabled = !enabled;
|
||||
$('dump').disabled = !enabled;
|
||||
$('json').disabled = !enabled;
|
||||
$('twain').disabled = !enabled;
|
||||
$('send10k').disabled = !enabled;
|
||||
$('send100k').disabled = !enabled;
|
||||
$('send1000k').disabled = !enabled;
|
||||
|
|
Loading…
Reference in New Issue