Skip to content

Commit

Permalink
mainly added some tracing in the sockjs stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
purplefox committed May 14, 2012
1 parent 16473db commit 0c21efc
Show file tree
Hide file tree
Showing 13 changed files with 42 additions and 17 deletions.
4 changes: 2 additions & 2 deletions conf/logging.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

handlers=java.util.logging.ConsoleHandler,java.util.logging.FileHandler
java.util.logging.ConsoleHandler.formatter=org.vertx.java.core.logging.VertxLoggerFormatter
java.util.logging.ConsoleHandler.level=FINE
java.util.logging.FileHandler.level=FINE
java.util.logging.ConsoleHandler.level=INFO
java.util.logging.FileHandler.level=INFO
java.util.logging.FileHandler.formatter=org.vertx.java.core.logging.VertxLoggerFormatter

# Put the log in the system temporary directory
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/vertx/java/core/Vertx.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package org.vertx.java.core;

import java.util.ServiceLoader;

import org.vertx.java.core.eventbus.EventBus;
import org.vertx.java.core.file.FileSystem;
import org.vertx.java.core.http.HttpClient;
Expand All @@ -27,6 +25,8 @@
import org.vertx.java.core.shareddata.SharedData;
import org.vertx.java.core.sockjs.SockJSServer;

import java.util.ServiceLoader;

/**
* The control centre of vert.x<p>
* You should normally only use a single instance of this class throughout your application. If you are running in the
Expand All @@ -49,15 +49,15 @@ private static VertxFactory loadFactory() {
* Create a non clustered Vertx instance
*/
public static Vertx newVertx() {
return loadFactory().createVertx();
return loadFactory().createVertx();
}

/**
* Create a clustered Vertx instance listening for cluster connections on the default port 25500
* @param hostname The hostname or ip address to listen for cluster connections
*/
public static Vertx newVertx(String hostname) {
return loadFactory().createVertx(hostname);
return loadFactory().createVertx(hostname);
}

/**
Expand All @@ -66,7 +66,7 @@ public static Vertx newVertx(String hostname) {
* @param hostname The hostname or ip address to listen for cluster connections
*/
public static Vertx newVertx(int port, String hostname) {
return loadFactory().createVertx(port, hostname);
return loadFactory().createVertx(port, hostname);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,11 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Ex
Object msg = e.getMessage();
ServerConnection conn = connectionMap.get(ch);
if (msg instanceof HttpRequest) {

final HttpRequest request = (HttpRequest) msg;

if (log.isTraceEnabled()) log.trace("Server received request: " + request.getUri());

if (HttpHeaders.is100ContinueExpected(request)) {
ch.write(new DefaultHttpResponse(HTTP_1_1, CONTINUE));
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/vertx/java/core/impl/DefaultVertx.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ protected Session getSession(final long timeout, final long heartbeatPeriod, fin
}

protected void sendInvalidJSON(HttpServerResponse response) {
if (log.isTraceEnabled()) log.trace("Broken JSON");
response.statusCode = 500;
response.end("Broken JSON encoding.");
}
Expand All @@ -84,6 +85,7 @@ protected static abstract class BaseListener implements TransportListener {
protected void addCloseHandler(HttpServerResponse resp, final Session session) {
resp.closeHandler(new SimpleHandler() {
public void handle() {
if (log.isTraceEnabled()) log.trace("Connection closed (from client?), closing session");
// Connection has been closed fron the client or network error so
// we remove the session
session.shutdown();
Expand Down Expand Up @@ -135,6 +137,7 @@ static Handler<HttpServerRequest> createInfoHandler(final JsonObject config) {
return new Handler<HttpServerRequest>() {
boolean websocket = !config.getArray("disabled_transports").contains(Transport.WEBSOCKET.toString());
public void handle(HttpServerRequest req) {
if (log.isTraceEnabled()) log.trace("In Info handler");
req.response.headers().put("Content-Type", "application/json; charset=UTF-8");
req.response.headers().put("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
JsonObject json = new JsonObject();
Expand All @@ -153,6 +156,7 @@ public void handle(HttpServerRequest req) {
static Handler<HttpServerRequest> createCORSOptionsHandler(final JsonObject config, final String methods) {
return new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest req) {
if (log.isTraceEnabled()) log.trace("In CORS options handler");
req.response.headers().put("Cache-Control", "public,max-age=31536000");
long oneYearSeconds = 365 * 24 * 60 * 60;
long oneYearms = oneYearSeconds * 1000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public void installApp(JsonObject config,

rm.getWithRegEx(prefix + "\\/?", new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest req) {
if (log.isTraceEnabled()) log.trace("Returning welcome response");
req.response.headers().put("Content-Type", "text/plain; charset=UTF-8");
req.response.end("Welcome to SockJS!\n");
}
Expand Down Expand Up @@ -148,7 +149,7 @@ public void handle(HttpServerRequest req) {
enabledTransports.add(Transport.WEBSOCKET.toString());
enabledTransports.add(Transport.XHR.toString());
for (Object tr : config.getArray("disabled_transports", new JsonArray())) {
enabledTransports.remove((String)tr);
enabledTransports.remove(tr);
}

if (enabledTransports.contains(Transport.XHR.toString())) {
Expand All @@ -171,6 +172,7 @@ public void handle(HttpServerRequest req) {

rm.getWithRegEx(prefix + "\\/.+", new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest req) {
if (log.isTraceEnabled()) log.trace("Request: " + req.uri + " does not match, returning 404");
req.response.statusCode = 404;
req.response.end();
}
Expand Down Expand Up @@ -262,6 +264,7 @@ private Handler<HttpServerRequest> createIFrameHandler(final String iframeHTML)
return new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest req) {
try {
if (log.isTraceEnabled()) log.trace("In Iframe handler");
String etag = getMD5String(iframeHTML);
if (etag.equals(req.headers().get("If-None-Match"))) {
req.response.statusCode = 304;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class EventSourceTransport extends BaseTransport {

rm.getWithRegEx(eventSourceRE, new Handler<HttpServerRequest>() {
public void handle(final HttpServerRequest req) {
if (log.isTraceEnabled()) log.trace("EventSource transport, get: " + req.uri);
String sessionID = req.params().get("param0");
Session session = getSession((Long)config.getNumber("session_timeout"), (Long)config.getNumber("heartbeat_period"), sessionID, sockHandler);
session.register(new EventSourceListener((Integer)config.getNumber("max_bytes_streaming"), req, session));
Expand All @@ -68,6 +69,7 @@ private class EventSourceListener extends BaseListener {
}

public void sendFrame(String body) {
if (log.isTraceEnabled()) log.trace("EventSource, sending frame");
if (!headersWritten) {
req.response.headers().put("Content-Type", "text/event-stream; charset=UTF-8");
req.response.headers().put("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
Expand All @@ -84,6 +86,7 @@ public void sendFrame(String body) {
req.response.write(buff);
bytesSent += buff.length();
if (bytesSent >= maxBytesStreaming) {
if (log.isTraceEnabled()) log.trace("More than maxBytes sent so closing connection");
// Reset and close the connection
close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class HtmlFileTransport extends BaseTransport {

rm.getWithRegEx(htmlFileRE, new Handler<HttpServerRequest>() {
public void handle(final HttpServerRequest req) {

if (log.isTraceEnabled()) log.trace("HtmlFile, get: " + req.uri);
String callback = req.params().get("callback");
if (callback == null) {
callback = req.params().get("c");
Expand Down Expand Up @@ -106,6 +106,7 @@ private class HtmlFileListener extends BaseListener {
}

public void sendFrame(String body) {
if (log.isTraceEnabled()) log.trace("HtmlFile, sending frame");
if (!headersWritten) {
String htmlFile = HTML_FILE_TEMPLATE.replace("{{ callback }}", callback);
req.response.headers().put("Content-Type", "text/html; charset=UTF-8");
Expand All @@ -124,6 +125,7 @@ public void sendFrame(String body) {
req.response.write(buff);
bytesSent += buff.length();
if (bytesSent >= maxBytesStreaming) {
if (log.isTraceEnabled()) log.trace("More than maxBytes sent so closing connection");
// Reset and close the connection
close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class JsonPTransport extends BaseTransport {

rm.getWithRegEx(jsonpRE, new Handler<HttpServerRequest>() {
public void handle(final HttpServerRequest req) {

if (log.isTraceEnabled()) log.trace("JsonP, get: " + req.uri);
String callback = req.params().get("callback");
if (callback == null) {
callback = req.params().get("c");
Expand All @@ -66,6 +66,7 @@ public void handle(final HttpServerRequest req) {

rm.postWithRegEx(jsonpSendRE, new Handler<HttpServerRequest>() {
public void handle(final HttpServerRequest req) {
if (log.isTraceEnabled()) log.trace("JsonP, post: " + req.uri);
String sessionID = req.params().get("param0");
final Session session = sessions.get(sessionID);
if (session != null) {
Expand Down Expand Up @@ -118,6 +119,7 @@ public void handle(Buffer buff) {
setJSESSIONID(config, req);
req.response.headers().put("Content-Type", "text/plain; charset=UTF-8");
req.response.end("ok");
if (log.isTraceEnabled()) log.trace("send handled ok");
}
}
});
Expand All @@ -141,6 +143,8 @@ private class JsonPListener extends BaseListener {

public void sendFrame(String body) {

if (log.isTraceEnabled()) log.trace("JsonP, sending frame");

if (!headersWritten) {
req.response.setChunked(true);
req.response.headers().put("Content-Type", "application/javascript; charset=UTF-8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
*
* @author <a href="http://tfox.org">Tim Fox</a>
*/
public class SockJSBridgeHandler implements Handler<SockJSSocket> {
class SockJSBridgeHandler implements Handler<SockJSSocket> {

private static final Logger log = LoggerFactory.getLogger(SockJSBridgeHandler.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,23 @@ class WebSocketTransport extends BaseTransport {
wsMatcher.addRegEx(wsRE, new Handler<WebSocketMatcher.Match>() {

public void handle(final WebSocketMatcher.Match match) {
if (log.isTraceEnabled()) log.trace("WS, handler");
final Session session = new Session(vertx, sessions, (Long)config.getNumber("heartbeat_period"), sockHandler);
session.register(new WebSocketListener(match.ws, session));
}
});

rm.getWithRegEx(wsRE, new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest request) {
if (log.isTraceEnabled()) log.trace("WS, get: " + request.uri);
request.response.statusCode = 400;
request.response.end("Can \"Upgrade\" only to \"WebSocket\".");
}
});

rm.allWithRegEx(wsRE, new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest request) {
if (log.isTraceEnabled()) log.trace("WS, all: " + request.uri);
request.response.headers().put("Allow", "GET");
request.response.statusCode = 405;
request.response.end();
Expand Down Expand Up @@ -103,6 +106,7 @@ public void handle() {
}

public void sendFrame(final String body) {
if (log.isTraceEnabled()) log.trace("WS, sending frame");
if (!closed) {
ws.writeTextFrame(body);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class XhrTransport extends BaseTransport {

rm.postWithRegEx(xhrSendRE, new Handler<HttpServerRequest>() {
public void handle(final HttpServerRequest req) {

if (log.isTraceEnabled()) log.trace("XHR send, post, " + req.uri);
String sessionID = req.params().get("param0");

final Session session = sessions.get(sessionID);
Expand All @@ -89,7 +89,7 @@ private void registerHandler(RouteMatcher rm, final Handler<SockJSSocket> sockHa
final boolean streaming, final JsonObject config) {
rm.postWithRegEx(re, new Handler<HttpServerRequest>() {
public void handle(final HttpServerRequest req) {

if (log.isTraceEnabled()) log.trace("XHR, post, " + req.uri);
String sessionID = req.params().get("param0");
Session session = getSession((Long)config.getNumber("session_timeout"), (Long)config.getNumber("heartbeat_period"), sessionID, sockHandler);

Expand Down Expand Up @@ -119,6 +119,7 @@ public void handle(Buffer buff) {
req.response.statusCode = 204;
req.response.end();
}
if (log.isTraceEnabled()) log.trace("XHR send processed ok");
}
});
}
Expand All @@ -135,6 +136,7 @@ private abstract class BaseXhrListener extends BaseListener {
}

public void sendFrame(String body) {
if (log.isTraceEnabled()) log.trace("XHR sending frame");
if (!headersWritten) {
req.response.headers().put("Content-Type", "application/javascript; charset=UTF-8");
setJSESSIONID(config, req);
Expand Down Expand Up @@ -164,6 +166,7 @@ public void sendFrame(String body) {
}

public void close() {
if (log.isTraceEnabled()) log.trace("XHR poll closing listener");
if (!closed) {
try {
session.resetListener();
Expand Down Expand Up @@ -205,6 +208,7 @@ public void sendFrame(String body) {
}

public void close() {
if (log.isTraceEnabled()) log.trace("XHR stream closing listener");
if (!closed) {
session.resetListener();
try {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/vertx/java/deploy/VerticleFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

package org.vertx.java.deploy;

import java.util.ServiceLoader;

import org.vertx.java.deploy.impl.VerticleManager;

import java.util.ServiceLoader;

/**
* @author <a href="http://tfox.org">Tim Fox</a>
*/
Expand Down

0 comments on commit 0c21efc

Please sign in to comment.