use of com.baidu.hugegraph.computer.core.common.exception.TransportException in project hugegraph-computer by hugegraph.
the class DataClientManager method connect.
public void connect(int workerId, String hostname, int dataPort) {
try {
TransportClient client = this.connManager.getOrCreateClient(hostname, dataPort);
LOG.info("Successfully connect to worker: {}({}:{})", workerId, hostname, dataPort);
this.sender.addWorkerClient(workerId, client);
} catch (TransportException e) {
throw new ComputerException("Failed to connect to worker: %s(%s:%s)", workerId, hostname, dataPort);
}
}
use of com.baidu.hugegraph.computer.core.common.exception.TransportException in project hugegraph-computer by hugegraph.
the class AbstractNettyHandler method processFailMessage.
protected void processFailMessage(ChannelHandlerContext ctx, Channel channel, FailMessage failMessage) {
int errorCode = failMessage.errorCode();
TransportException exception = new TransportException(errorCode, "Remote error from '%s', cause: %s", TransportUtil.remoteAddress(channel), failMessage.message());
ConnectionId connectionId = TransportUtil.remoteConnectionId(channel);
this.transportHandler().exceptionCaught(exception, connectionId);
}
use of com.baidu.hugegraph.computer.core.common.exception.TransportException in project hugegraph-computer by hugegraph.
the class ChannelFutureListenerOnWrite method onFailure.
public void onFailure(Channel channel, Throwable cause) {
TransportException exception;
if (cause instanceof TransportException) {
exception = (TransportException) cause;
} else {
exception = new TransportException("Failed to send data to '%s': %s", cause, TransportUtil.remoteAddress(channel), cause.getMessage());
}
ConnectionId connectionId = TransportUtil.remoteConnectionId(channel);
this.handler.exceptionCaught(exception, connectionId);
}
use of com.baidu.hugegraph.computer.core.common.exception.TransportException in project hugegraph-computer by hugegraph.
the class MessageEncoder method writeMessage.
private void writeMessage(ChannelHandlerContext ctx, Message message, ChannelPromise promise, ByteBufAllocator allocator) throws TransportException {
ByteBuf bufHeader = null;
try {
PromiseCombiner combiner = new PromiseCombiner(ctx.executor());
bufHeader = allocator.directBuffer(AbstractMessage.HEADER_LENGTH);
NetworkBuffer bodyBuffer = message.encode(bufHeader);
ChannelFuture headerWriteFuture = ctx.write(bufHeader);
/*
* Released bufHeader after in ctx.write(), set bufHeader = null
* to not release again
*/
bufHeader = null;
combiner.add(headerWriteFuture);
if (bodyBuffer != null) {
ByteBuf bodyBuf = bodyBuffer.nettyByteBuf();
// Will call bodyBuf.release() in ctx.write(), retain() first
bodyBuffer.retain();
combiner.add(ctx.write(bodyBuf));
}
combiner.finish(promise);
} catch (Throwable e) {
throw new TransportException("Failed to encode message, " + "message type: %s", e, message.type());
} finally {
if (bufHeader != null) {
bufHeader.release();
}
message.release();
}
}
use of com.baidu.hugegraph.computer.core.common.exception.TransportException in project hugegraph-computer by hugegraph.
the class ClientSession method start.
public synchronized void start(long timeout) throws TransportException {
CompletableFuture<Void> startFuture = this.startAsync();
try {
startFuture.get(timeout, TimeUnit.MILLISECONDS);
} catch (Throwable e) {
this.stateReady();
if (e instanceof TimeoutException) {
throw new TransportException("Timeout(%sms) to wait start-response", timeout);
} else {
throw new TransportException("Failed to wait start-response", e);
}
} finally {
startFuture.cancel(false);
this.startedFutureRef.compareAndSet(startFuture, null);
}
}
Aggregations