This commit is contained in:
地平线
2015-10-21 08:59:41 +08:00
parent 631d5f2f7a
commit e05b6f713a
3 changed files with 19 additions and 3 deletions

View File

@@ -60,9 +60,7 @@ public final class PrepareRunner implements Runnable {
}
// { //测试
// buffer.flip();
// byte[] bytes = new byte[buffer.remaining()];
// buffer.get(bytes);
// System.println(new String(bytes));
// System.println(new String(buffer.array(), 0, buffer.remaining()));
// }
buffer.flip();
final Response response = responsePool.poll();

View File

@@ -90,4 +90,9 @@ public abstract class Request {
public Context getContext() {
return this.context;
}
public long getCreatetime() {
return createtime;
}
}

View File

@@ -24,6 +24,8 @@ public abstract class Response<R extends Request> {
private boolean inited = true;
protected Runnable recycleListener;
private final CompletionHandler finishHandler = new CompletionHandler<Integer, ByteBuffer>() {
@Override
@@ -96,6 +98,13 @@ public abstract class Response<R extends Request> {
protected boolean recycle() {
if (!inited) return false;
boolean keepAlive = request.keepAlive;
if (recycleListener != null) {
try {
recycleListener.run();
} catch (Exception e) {
}
recycleListener = null;
}
request.recycle();
if (channel != null) {
if (keepAlive) {
@@ -122,6 +131,10 @@ public abstract class Response<R extends Request> {
this.request.createtime = System.currentTimeMillis();
}
public void setRecycleListener(Runnable recycleListener) {
this.recycleListener = recycleListener;
}
public void finish() {
this.finish(false);
}