This commit is contained in:
kamhung
2015-11-10 17:44:49 +08:00
parent e3e6897fad
commit 247256bd6f
4 changed files with 13 additions and 12 deletions

View File

@@ -11,6 +11,7 @@ import java.net.*;
import java.nio.*;
import java.nio.charset.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.logging.*;
/**
@@ -89,6 +90,10 @@ public class Context {
return bufferCapacity;
}
public Supplier<ByteBuffer> getBufferSupplier() {
return bufferPool;
}
public ByteBuffer pollBuffer() {
return bufferPool.get();
}

View File

@@ -13,6 +13,7 @@ import java.nio.channels.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.*;
import java.util.function.*;
/**
* 传输客户端
@@ -115,6 +116,10 @@ public final class Transport {
return bufferPool.get();
}
public Supplier<ByteBuffer> getBufferSupplier() {
return bufferPool;
}
public void offerBuffer(ByteBuffer buffer) {
bufferPool.offer(buffer);
}

View File

@@ -60,10 +60,6 @@ public final class HttpContext extends Context {
return responsePool;
}
protected ObjectPool<ByteBuffer> getBufferPool() {
return bufferPool;
}
public JsonConvert getJsonConvert() {
return jsonFactory.getConvert();
}

View File

@@ -18,7 +18,6 @@ import java.nio.file.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.atomic.*;
import java.util.function.*;
/**
*
@@ -148,10 +147,6 @@ public class HttpResponse<R extends HttpRequest> extends Response<R> {
return v == null ? defValue : v;
}
protected Supplier<ByteBuffer> getByteBufferSupplier() {
return ((HttpContext) context).getBufferPool();
}
@Override
public HttpContext getContext() {
return (HttpContext) context;
@@ -170,17 +165,17 @@ public class HttpResponse<R extends HttpRequest> extends Response<R> {
public void finishJson(Object obj) {
this.contentType = "text/plain; charset=utf-8";
finish(request.convert.convertTo(context.getCharset(), getByteBufferSupplier(), obj));
finish(request.convert.convertTo(context.getCharset(), context.getBufferSupplier(), obj));
}
public void finishJson(Type type, Object obj) {
this.contentType = "text/plain; charset=utf-8";
finish(request.convert.convertTo(context.getCharset(), getByteBufferSupplier(), type, obj));
finish(request.convert.convertTo(context.getCharset(), context.getBufferSupplier(), type, obj));
}
public void finishJson(Object... objs) {
this.contentType = "text/plain; charset=utf-8";
finish(request.convert.convertTo(context.getCharset(), getByteBufferSupplier(), objs));
finish(request.convert.convertTo(context.getCharset(), context.getBufferSupplier(), objs));
}
public void finish(String obj) {