Skip to content

Commit 738f3f8

Browse files
author
Roland Schuller
committed
Timing Info
1 parent 8532778 commit 738f3f8

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/main/java/at/itopen/simplerest/RestHttpRequestDispatchHandler.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
6262
ctx.write(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE));
6363
}
6464

65-
Conversion conversion = connections.get(ctx.channel().id().asLongText());
66-
conversion.parse(msg);
65+
getConn(ctx).parse(msg);
6766

6867
} catch (Exception ex) {
6968
ReferenceCountUtil.release(msg);
@@ -96,13 +95,14 @@ public ResponseWrapper(int code, String message, String info, long generationNan
9695
@Override
9796
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
9897

99-
Conversion conversion = connections.get(ctx.channel().id().asLongText());
98+
Conversion conversion = getConn(ctx);
10099
if (conversion.getRequest().getHttpDecoder() != null) {
101100
if ((conversion.getRequest().getHttpDecoder().isMultipart()) && (!conversion.getRequest().getHttpDecoder().hasNext())) {
102101
return;
103102
}
104103
}
105104
process(conversion, ctx);
105+
connections.remove(ctx.channel().id().asLongText());
106106

107107
ctx.flush();
108108
}
@@ -193,6 +193,18 @@ public static void process(Conversion conversion, ChannelHandlerContext ctx) thr
193193
writeJSON(ctx, HttpResponseStatus.valueOf(conversion.getResponse().getStatus().getCode()), bb, conversion.getResponse());
194194

195195
}
196+
197+
}
198+
199+
public Conversion getConn(ChannelHandlerContext ctx) {
200+
String key = ctx.channel().id().asLongText();
201+
if (connections.containsKey(key)) {
202+
return connections.get(key);
203+
} else {
204+
Conversion c = new Conversion(ctx, server);
205+
connections.put(key, c);
206+
return c;
207+
}
196208
}
197209

198210
/**
@@ -204,7 +216,7 @@ public static void process(Conversion conversion, ChannelHandlerContext ctx) thr
204216
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
205217
super.channelRegistered(ctx); //To change body of generated methods, choose Tools | Templates.
206218

207-
connections.put(ctx.channel().id().asLongText(), new Conversion(ctx, server));
219+
getConn(ctx);
208220
}
209221

210222
/**

src/main/java/at/itopen/simplerest/conversion/Conversion.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class Conversion {
2323
private final Response response;
2424
private final ChannelHandlerContext ctx;
2525
private Exception exception;
26-
private long startTime = System.currentTimeMillis();
26+
private long startTime;
2727
private RestHttpServer server;
2828
private Map<String, Object> data = new HashMap<>();
2929

0 commit comments

Comments
 (0)