This commit is contained in:
@@ -44,7 +44,7 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
||||
}
|
||||
|
||||
public BsonWriter pollBsonWriter() {
|
||||
return writerPool.poll().setTiny(tiny);
|
||||
return writerPool.get().setTiny(tiny);
|
||||
}
|
||||
|
||||
public void offerBsonWriter(BsonWriter out) {
|
||||
@@ -52,7 +52,7 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
||||
}
|
||||
|
||||
public BsonReader pollBsonReader() {
|
||||
return readerPool.poll();
|
||||
return readerPool.get();
|
||||
}
|
||||
|
||||
public void offerBsonReader(BsonReader in) {
|
||||
@@ -66,7 +66,7 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
||||
|
||||
public <T> T convertFrom(final Type type, final byte[] bytes, int start, int len) {
|
||||
if (type == null) return null;
|
||||
final BsonReader in = readerPool.poll();
|
||||
final BsonReader in = readerPool.get();
|
||||
in.setBytes(bytes, start, len);
|
||||
@SuppressWarnings("unchecked")
|
||||
T rs = (T) factory.loadDecoder(type).convertFrom(in);
|
||||
@@ -83,7 +83,7 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
||||
|
||||
public byte[] convertTo(final Type type, Object value) {
|
||||
if (type == null) return null;
|
||||
final BsonWriter out = writerPool.poll().setTiny(tiny);
|
||||
final BsonWriter out = writerPool.get().setTiny(tiny);
|
||||
factory.loadEncoder(type).convertTo(out, value);
|
||||
byte[] result = out.toArray();
|
||||
writerPool.offer(out);
|
||||
@@ -105,7 +105,7 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
||||
|
||||
public byte[] convertTo(Object value) {
|
||||
if (value == null) {
|
||||
final BsonWriter out = writerPool.poll().setTiny(tiny);
|
||||
final BsonWriter out = writerPool.get().setTiny(tiny);
|
||||
out.writeNull();
|
||||
byte[] result = out.toArray();
|
||||
writerPool.offer(out);
|
||||
@@ -116,7 +116,7 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
||||
|
||||
public ByteBuffer convertToBuffer(final Type type, Object value) {
|
||||
if (type == null) return null;
|
||||
final BsonWriter out = writerPool.poll().setTiny(tiny);
|
||||
final BsonWriter out = writerPool.get().setTiny(tiny);
|
||||
factory.loadEncoder(type).convertTo(out, value);
|
||||
ByteBuffer result = out.toBuffer();
|
||||
writerPool.offer(out);
|
||||
@@ -125,7 +125,7 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
||||
|
||||
public ByteBuffer convertToBuffer(Object value) {
|
||||
if (value == null) {
|
||||
final BsonWriter out = writerPool.poll().setTiny(tiny);
|
||||
final BsonWriter out = writerPool.get().setTiny(tiny);
|
||||
out.writeNull();
|
||||
ByteBuffer result = out.toBuffer();
|
||||
writerPool.offer(out);
|
||||
@@ -136,7 +136,7 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
||||
|
||||
public BsonWriter convertToWriter(final Type type, Object value) {
|
||||
if (type == null) return null;
|
||||
final BsonWriter out = writerPool.poll().setTiny(tiny);
|
||||
final BsonWriter out = writerPool.get().setTiny(tiny);
|
||||
factory.loadEncoder(type).convertTo(out, value);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
||||
}
|
||||
|
||||
public JsonWriter pollJsonWriter() {
|
||||
return writerPool.poll().setTiny(tiny);
|
||||
return writerPool.get().setTiny(tiny);
|
||||
}
|
||||
|
||||
public void offerJsonWriter(JsonWriter out) {
|
||||
@@ -55,7 +55,7 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
||||
|
||||
public <T> T convertFrom(final Type type, final char[] text, int start, int len) {
|
||||
if (text == null || type == null) return null;
|
||||
final JsonReader in = readerPool.poll();
|
||||
final JsonReader in = readerPool.get();
|
||||
in.setText(text, start, len);
|
||||
T rs = (T) factory.loadDecoder(type).convertFrom(in);
|
||||
readerPool.offer(in);
|
||||
@@ -65,7 +65,7 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
||||
public String convertTo(final Type type, Object value) {
|
||||
if (type == null) return null;
|
||||
if (value == null) return "null";
|
||||
final JsonWriter out = writerPool.poll().setTiny(tiny);
|
||||
final JsonWriter out = writerPool.get().setTiny(tiny);
|
||||
factory.loadEncoder(type).convertTo(out, value);
|
||||
String result = out.toString();
|
||||
writerPool.offer(out);
|
||||
@@ -102,7 +102,7 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
||||
public byte[] convertToUTF8Bytes(final Type type, Object value) {
|
||||
if (type == null) return null;
|
||||
if (value == null) return new byte[]{110, 117, 108, 108};
|
||||
final JsonWriter out = writerPool.poll().setTiny(tiny);
|
||||
final JsonWriter out = writerPool.get().setTiny(tiny);
|
||||
factory.loadEncoder(type).convertTo(out, value);
|
||||
byte[] result = out.toUTF8Bytes();
|
||||
writerPool.offer(out);
|
||||
|
||||
@@ -90,7 +90,7 @@ public class Context {
|
||||
}
|
||||
|
||||
public ByteBuffer pollBuffer() {
|
||||
return bufferPool.poll();
|
||||
return bufferPool.get();
|
||||
}
|
||||
|
||||
public void offerBuffer(ByteBuffer buffer) {
|
||||
|
||||
@@ -34,7 +34,7 @@ public final class PrepareRunner implements Runnable {
|
||||
final PrepareServlet prepare = context.prepare;
|
||||
final ObjectPool<? extends Response> responsePool = context.responsePool;
|
||||
if (data != null) {
|
||||
final Response response = responsePool.poll();
|
||||
final Response response = responsePool.get();
|
||||
response.init(channel);
|
||||
try {
|
||||
prepare.prepare(data, response.request, response);
|
||||
@@ -65,7 +65,7 @@ public final class PrepareRunner implements Runnable {
|
||||
// System.println(new String(bs));
|
||||
// }
|
||||
buffer.flip();
|
||||
final Response response = responsePool.poll();
|
||||
final Response response = responsePool.get();
|
||||
response.init(channel);
|
||||
try {
|
||||
prepare.prepare(buffer, response.request, response);
|
||||
|
||||
@@ -112,7 +112,7 @@ public final class Transport {
|
||||
}
|
||||
|
||||
public ByteBuffer pollBuffer() {
|
||||
return bufferPool.poll();
|
||||
return bufferPool.get();
|
||||
}
|
||||
|
||||
public void offerBuffer(ByteBuffer buffer) {
|
||||
@@ -131,7 +131,6 @@ public final class Transport {
|
||||
final boolean rand = addr == null;
|
||||
try {
|
||||
if ("TCP".equalsIgnoreCase(protocol)) {
|
||||
Socket socket = null;
|
||||
AsynchronousSocketChannel channel = null;
|
||||
if (rand) { //随机取地址
|
||||
int p = 0;
|
||||
@@ -154,7 +153,6 @@ public final class Transport {
|
||||
iex.printStackTrace();
|
||||
if (i == remoteAddres.length - 1) {
|
||||
p = 0;
|
||||
socket = null;
|
||||
channel = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.util.logging.*;
|
||||
* @author zhangjx
|
||||
* @param <T>
|
||||
*/
|
||||
public final class ObjectPool<T> {
|
||||
public final class ObjectPool<T> implements Supplier<T> {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ObjectPool.class.getSimpleName());
|
||||
|
||||
@@ -63,7 +63,8 @@ public final class ObjectPool<T> {
|
||||
this.creator = creator;
|
||||
}
|
||||
|
||||
public T poll() {
|
||||
@Override
|
||||
public T get() {
|
||||
T result = queue.poll();
|
||||
if (result == null) {
|
||||
if (creatCounter != null) creatCounter.incrementAndGet();
|
||||
|
||||
Reference in New Issue
Block a user