This commit is contained in:
wentch
2016-01-06 14:22:43 +08:00
parent dbf1d60593
commit 8f34a96ded
3 changed files with 48 additions and 48 deletions

View File

@@ -115,10 +115,10 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
return (T) factory.loadDecoder(type).convertFrom(new BsonStreamReader(in)); return (T) factory.loadDecoder(type).convertFrom(new BsonStreamReader(in));
} }
public <T> T convertFrom(final BsonReader in, final Type type) { public <T> T convertFrom(final Type type, final BsonReader reader) {
if (type == null) return null; if (type == null) return null;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
T rs = (T) factory.loadDecoder(type).convertFrom(in); T rs = (T) factory.loadDecoder(type).convertFrom(reader);
return rs; return rs;
} }
@@ -143,19 +143,6 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
return result; return result;
} }
public void convertTo(final BsonWriter out, Object value) {
if (value == null) {
out.writeNull();
} else {
factory.loadEncoder(value.getClass()).convertTo(out, value);
}
}
public void convertTo(final BsonWriter out, final Type type, Object value) {
if (type == null) return;
factory.loadEncoder(type).convertTo(out, value);
}
public void convertTo(final OutputStream out, Object value) { public void convertTo(final OutputStream out, Object value) {
if (value == null) { if (value == null) {
new BsonStreamWriter(tiny, out).writeNull(); new BsonStreamWriter(tiny, out).writeNull();
@@ -195,6 +182,19 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
return out.toBuffers(); return out.toBuffers();
} }
public void convertTo(final BsonWriter writer, Object value) {
if (value == null) {
writer.writeNull();
} else {
factory.loadEncoder(value.getClass()).convertTo(writer, value);
}
}
public void convertTo(final BsonWriter writer, final Type type, Object value) {
if (type == null) return;
factory.loadEncoder(type).convertTo(writer, value);
}
public BsonWriter convertToWriter(Object value) { public BsonWriter convertToWriter(Object value) {
if (value == null) return null; if (value == null) return null;
return convertToWriter(value.getClass(), value); return convertToWriter(value.getClass(), value);

View File

@@ -110,10 +110,10 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
return (T) factory.loadDecoder(type).convertFrom(new JsonStreamReader(in)); return (T) factory.loadDecoder(type).convertFrom(new JsonStreamReader(in));
} }
public <T> T convertFrom(final JsonReader in, final Type type) { public <T> T convertFrom(final Type type, final JsonReader reader) {
if (type == null) return null; if (type == null) return null;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
T rs = (T) factory.loadDecoder(type).convertFrom(in); T rs = (T) factory.loadDecoder(type).convertFrom(reader);
return rs; return rs;
} }
@@ -133,23 +133,6 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
return result; return result;
} }
public void convertTo(final JsonWriter out, Object value) {
if (value == null) {
out.writeNull();
} else {
factory.loadEncoder(value.getClass()).convertTo(out, value);
}
}
public void convertTo(final JsonWriter out, final Type type, Object value) {
if (type == null) return;
if (value == null) {
out.writeNull();
} else {
factory.loadEncoder(type).convertTo(out, value);
}
}
public void convertTo(final OutputStream out, Object value) { public void convertTo(final OutputStream out, Object value) {
if (value == null) { if (value == null) {
new JsonStreamWriter(tiny, out).writeNull(); new JsonStreamWriter(tiny, out).writeNull();
@@ -189,6 +172,23 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
return out.toBuffers(); return out.toBuffers();
} }
public void convertTo(final JsonWriter writer, Object value) {
if (value == null) {
writer.writeNull();
} else {
factory.loadEncoder(value.getClass()).convertTo(writer, value);
}
}
public void convertTo(final JsonWriter writer, final Type type, Object value) {
if (type == null) return;
if (value == null) {
writer.writeNull();
} else {
factory.loadEncoder(type).convertTo(writer, value);
}
}
public JsonWriter convertToWriter(Object value) { public JsonWriter convertToWriter(Object value) {
if (value == null) return null; if (value == null) return null;
return convertToWriter(value.getClass(), value); return convertToWriter(value.getClass(), value);

View File

@@ -1,7 +1,7 @@
/* /*
* To change this license header, choose License Headers in Project Properties. * To change this license header, choose License Headers reader Project Properties.
* To change this template file, choose Tools | Templates * To change this template file, choose Tools | Templates
* and open the template in the editor. * and open the template reader the editor.
*/ */
package org.redkale.net.sncp; package org.redkale.net.sncp;
@@ -236,20 +236,20 @@ public final class SncpClient {
if (action.handlerFuncParamIndex >= 0) params[action.handlerFuncParamIndex] = null; if (action.handlerFuncParamIndex >= 0) params[action.handlerFuncParamIndex] = null;
Future<byte[]> future = remote0(handlerFunc, convert, transport, action, params); Future<byte[]> future = remote0(handlerFunc, convert, transport, action, params);
if (handlerFunc != null) return null; if (handlerFunc != null) return null;
final BsonReader in = convert.pollBsonReader(); final BsonReader reader = convert.pollBsonReader();
try { try {
in.setBytes(future.get(5, TimeUnit.SECONDS)); reader.setBytes(future.get(5, TimeUnit.SECONDS));
byte i; byte i;
while ((i = in.readByte()) != 0) { while ((i = reader.readByte()) != 0) {
final Attribute attr = action.paramAttrs[i]; final Attribute attr = action.paramAttrs[i];
attr.set(params[i - 1], convert.convertFrom(in, attr.type())); attr.set(params[i - 1], convert.convertFrom(attr.type(), reader));
} }
return convert.convertFrom(in, action.resultTypes); return convert.convertFrom(action.resultTypes, reader);
} catch (InterruptedException | ExecutionException | TimeoutException e) { } catch (InterruptedException | ExecutionException | TimeoutException e) {
logger.log(Level.SEVERE, actions[index].method + " sncp (params: " + jsonConvert.convertTo(params) + ") remote error", e); logger.log(Level.SEVERE, actions[index].method + " sncp (params: " + jsonConvert.convertTo(params) + ") remote error", e);
throw new RuntimeException(actions[index].method + " sncp remote error", e); throw new RuntimeException(actions[index].method + " sncp remote error", e);
} finally { } finally {
convert.offerBsonReader(in); convert.offerBsonReader(reader);
} }
} }
@@ -377,20 +377,20 @@ public final class SncpClient {
transport.offerConnection(false, conn); transport.offerConnection(false, conn);
if (handler != null) { if (handler != null) {
final Object handlerAttach = action.handlerAttachParamIndex >= 0 ? params[action.handlerAttachParamIndex] : null; final Object handlerAttach = action.handlerAttachParamIndex >= 0 ? params[action.handlerAttachParamIndex] : null;
final BsonReader in = convert.pollBsonReader(); final BsonReader reader = convert.pollBsonReader();
try { try {
in.setBytes(this.body); reader.setBytes(this.body);
byte i; byte i;
while ((i = in.readByte()) != 0) { while ((i = reader.readByte()) != 0) {
final Attribute attr = action.paramAttrs[i]; final Attribute attr = action.paramAttrs[i];
attr.set(params[i - 1], convert.convertFrom(in, attr.type())); attr.set(params[i - 1], convert.convertFrom(attr.type(), reader));
} }
Object rs = convert.convertFrom(in, action.resultTypes); Object rs = convert.convertFrom(action.resultTypes, reader);
handler.completed(rs, handlerAttach); handler.completed(rs, handlerAttach);
} catch (Exception e) { } catch (Exception e) {
handler.failed(e, handlerAttach); handler.failed(e, handlerAttach);
} finally { } finally {
convert.offerBsonReader(in); convert.offerBsonReader(reader);
} }
} }
} }