This commit is contained in:
@@ -296,7 +296,7 @@ public final class SncpClient {
|
|||||||
if (action.handlerFuncParamIndex >= 0) params[action.handlerFuncParamIndex] = null;
|
if (action.handlerFuncParamIndex >= 0) params[action.handlerFuncParamIndex] = null;
|
||||||
final BsonReader reader = bsonConvert.pollBsonReader();
|
final BsonReader reader = bsonConvert.pollBsonReader();
|
||||||
CompletableFuture<byte[]> future = remote0(handlerFunc, remoteGroupTransport, null, action, params);
|
CompletableFuture<byte[]> future = remote0(handlerFunc, remoteGroupTransport, null, action, params);
|
||||||
if (action.boolReturnTypeFuture) {
|
if (action.boolReturnTypeFuture) { //与handlerFuncIndex互斥
|
||||||
CompletableFuture result = action.futureCreator.create();
|
CompletableFuture result = action.futureCreator.create();
|
||||||
future.whenComplete((v, e) -> {
|
future.whenComplete((v, e) -> {
|
||||||
try {
|
try {
|
||||||
@@ -355,7 +355,12 @@ public final class SncpClient {
|
|||||||
CompletableFuture<AsyncConnection> connFuture = transport.pollConnection(addr);
|
CompletableFuture<AsyncConnection> connFuture = transport.pollConnection(addr);
|
||||||
return connFuture.thenCompose(conn0 -> {
|
return connFuture.thenCompose(conn0 -> {
|
||||||
final CompletableFuture<byte[]> future = new CompletableFuture();
|
final CompletableFuture<byte[]> future = new CompletableFuture();
|
||||||
if (conn0 == null || !conn0.isOpen()) {
|
if (conn0 == null) {
|
||||||
|
future.completeExceptionally(new RuntimeException("sncp " + (conn0 == null ? addr : conn0.getRemoteAddress()) + " cannot connect"));
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
if (!conn0.isOpen()) {
|
||||||
|
conn0.dispose();
|
||||||
future.completeExceptionally(new RuntimeException("sncp " + (conn0 == null ? addr : conn0.getRemoteAddress()) + " cannot connect"));
|
future.completeExceptionally(new RuntimeException("sncp " + (conn0 == null ? addr : conn0.getRemoteAddress()) + " cannot connect"));
|
||||||
return future;
|
return future;
|
||||||
}
|
}
|
||||||
@@ -396,6 +401,7 @@ public final class SncpClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void completed(Integer count, Void attachment2) {
|
public void completed(Integer count, Void attachment2) {
|
||||||
|
try {
|
||||||
if (count < 1 && buffer.remaining() == buffer.limit()) { //没有数据可读
|
if (count < 1 && buffer.remaining() == buffer.limit()) { //没有数据可读
|
||||||
future.completeExceptionally(new RuntimeException(action.method + " sncp[" + conn.getRemoteAddress() + "] remote no response data"));
|
future.completeExceptionally(new RuntimeException(action.method + " sncp[" + conn.getRemoteAddress() + "] remote no response data"));
|
||||||
transport.offerBuffer(buffer);
|
transport.offerBuffer(buffer);
|
||||||
@@ -439,6 +445,15 @@ public final class SncpClient {
|
|||||||
buffer.get(body, 0, respBodyLength);
|
buffer.get(body, 0, respBodyLength);
|
||||||
success();
|
success();
|
||||||
}
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
future.completeExceptionally(new RuntimeException(action.method + " sncp[" + conn.getRemoteAddress() + "] remote response error"));
|
||||||
|
transport.offerConnection(true, conn);
|
||||||
|
if (handler != null) {
|
||||||
|
final Object handlerAttach = action.handlerAttachParamIndex >= 0 ? params[action.handlerAttachParamIndex] : null;
|
||||||
|
handler.failed(e, handlerAttach);
|
||||||
|
}
|
||||||
|
logger.log(Level.SEVERE, action.method + " sncp (params: " + convert.convertTo(params) + ") deal error", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -468,7 +483,6 @@ public final class SncpClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void failed(Throwable exc, Void attachment2) {
|
public void failed(Throwable exc, Void attachment2) {
|
||||||
logger.log(Level.SEVERE, action.method + " sncp (params: " + convert.convertTo(params) + ") remote read exec failed", exc);
|
|
||||||
future.completeExceptionally(new RuntimeException(action.method + " sncp remote exec failed"));
|
future.completeExceptionally(new RuntimeException(action.method + " sncp remote exec failed"));
|
||||||
transport.offerBuffer(buffer);
|
transport.offerBuffer(buffer);
|
||||||
transport.offerConnection(true, conn);
|
transport.offerConnection(true, conn);
|
||||||
@@ -476,15 +490,21 @@ public final class SncpClient {
|
|||||||
final Object handlerAttach = action.handlerAttachParamIndex >= 0 ? params[action.handlerAttachParamIndex] : null;
|
final Object handlerAttach = action.handlerAttachParamIndex >= 0 ? params[action.handlerAttachParamIndex] : null;
|
||||||
handler.failed(exc, handlerAttach);
|
handler.failed(exc, handlerAttach);
|
||||||
}
|
}
|
||||||
|
logger.log(Level.SEVERE, action.method + " sncp (params: " + convert.convertTo(params) + ") remote read exec failed", exc);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void failed(Throwable exc, ByteBuffer[] attachment) {
|
public void failed(Throwable exc, ByteBuffer[] attachment) {
|
||||||
logger.log(Level.SEVERE, action.method + " sncp (params: " + convert.convertTo(params) + ") remote write exec failed", exc);
|
future.completeExceptionally(new RuntimeException(action.method + " sncp remote exec failed"));
|
||||||
transport.offerBuffer(buffer);
|
transport.offerBuffer(buffer);
|
||||||
transport.offerConnection(true, conn);
|
transport.offerConnection(true, conn);
|
||||||
|
if (handler != null) {
|
||||||
|
final Object handlerAttach = action.handlerAttachParamIndex >= 0 ? params[action.handlerAttachParamIndex] : null;
|
||||||
|
handler.failed(exc, handlerAttach);
|
||||||
|
}
|
||||||
|
logger.log(Level.SEVERE, action.method + " sncp (params: " + convert.convertTo(params) + ") remote write exec failed", exc);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return future;
|
return future;
|
||||||
|
|||||||
Reference in New Issue
Block a user