This commit is contained in:
@@ -115,10 +115,10 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
||||
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;
|
||||
@SuppressWarnings("unchecked")
|
||||
T rs = (T) factory.loadDecoder(type).convertFrom(in);
|
||||
T rs = (T) factory.loadDecoder(type).convertFrom(reader);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@@ -143,19 +143,6 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
||||
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) {
|
||||
if (value == null) {
|
||||
new BsonStreamWriter(tiny, out).writeNull();
|
||||
@@ -195,6 +182,19 @@ public final class BsonConvert extends Convert<BsonReader, BsonWriter> {
|
||||
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) {
|
||||
if (value == null) return null;
|
||||
return convertToWriter(value.getClass(), value);
|
||||
|
||||
@@ -110,10 +110,10 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
||||
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;
|
||||
@SuppressWarnings("unchecked")
|
||||
T rs = (T) factory.loadDecoder(type).convertFrom(in);
|
||||
T rs = (T) factory.loadDecoder(type).convertFrom(reader);
|
||||
return rs;
|
||||
}
|
||||
|
||||
@@ -133,23 +133,6 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
||||
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) {
|
||||
if (value == null) {
|
||||
new JsonStreamWriter(tiny, out).writeNull();
|
||||
@@ -189,6 +172,23 @@ public final class JsonConvert extends Convert<JsonReader, JsonWriter> {
|
||||
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) {
|
||||
if (value == null) return null;
|
||||
return convertToWriter(value.getClass(), value);
|
||||
|
||||
@@ -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
|
||||
* and open the template in the editor.
|
||||
* and open the template reader the editor.
|
||||
*/
|
||||
package org.redkale.net.sncp;
|
||||
|
||||
@@ -236,20 +236,20 @@ public final class SncpClient {
|
||||
if (action.handlerFuncParamIndex >= 0) params[action.handlerFuncParamIndex] = null;
|
||||
Future<byte[]> future = remote0(handlerFunc, convert, transport, action, params);
|
||||
if (handlerFunc != null) return null;
|
||||
final BsonReader in = convert.pollBsonReader();
|
||||
final BsonReader reader = convert.pollBsonReader();
|
||||
try {
|
||||
in.setBytes(future.get(5, TimeUnit.SECONDS));
|
||||
reader.setBytes(future.get(5, TimeUnit.SECONDS));
|
||||
byte i;
|
||||
while ((i = in.readByte()) != 0) {
|
||||
while ((i = reader.readByte()) != 0) {
|
||||
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) {
|
||||
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);
|
||||
} finally {
|
||||
convert.offerBsonReader(in);
|
||||
convert.offerBsonReader(reader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,20 +377,20 @@ public final class SncpClient {
|
||||
transport.offerConnection(false, conn);
|
||||
if (handler != null) {
|
||||
final Object handlerAttach = action.handlerAttachParamIndex >= 0 ? params[action.handlerAttachParamIndex] : null;
|
||||
final BsonReader in = convert.pollBsonReader();
|
||||
final BsonReader reader = convert.pollBsonReader();
|
||||
try {
|
||||
in.setBytes(this.body);
|
||||
reader.setBytes(this.body);
|
||||
byte i;
|
||||
while ((i = in.readByte()) != 0) {
|
||||
while ((i = reader.readByte()) != 0) {
|
||||
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);
|
||||
} catch (Exception e) {
|
||||
handler.failed(e, handlerAttach);
|
||||
} finally {
|
||||
convert.offerBsonReader(in);
|
||||
convert.offerBsonReader(reader);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user