Search in sources :

Example 16 with RemotingException

use of org.apache.dubbo.remoting.RemotingException in project dubbo by alibaba.

the class FileGroup method join.

@Override
public Peer join(URL url, ChannelHandler handler) throws RemotingException {
    Peer peer = super.join(url, handler);
    try {
        String full = url.toFullString();
        String[] lines = IOUtils.readLines(file);
        for (String line : lines) {
            if (full.equals(line)) {
                return peer;
            }
        }
        IOUtils.appendLines(file, new String[] { full });
    } catch (IOException e) {
        throw new RemotingException(new InetSocketAddress(NetUtils.getLocalHost(), 0), getUrl().toInetSocketAddress(), e.getMessage(), e);
    }
    return peer;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Peer(org.apache.dubbo.remoting.p2p.Peer) RemotingException(org.apache.dubbo.remoting.RemotingException) IOException(java.io.IOException)

Example 17 with RemotingException

use of org.apache.dubbo.remoting.RemotingException in project dubbo by alibaba.

the class NettyChannel method send.

/**
 * Send message by netty and whether to wait the completion of the send.
 *
 * @param message message that need send.
 * @param sent    whether to ack async-sent
 * @throws RemotingException throw RemotingException if wait until timeout or any exception thrown by method body that surrounded by try-catch.
 */
@Override
public void send(Object message, boolean sent) throws RemotingException {
    // whether the channel is closed
    super.send(message, sent);
    boolean success = true;
    int timeout = 0;
    try {
        ChannelFuture future = channel.writeAndFlush(message);
        if (sent) {
            // wait timeout ms
            timeout = getUrl().getPositiveParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT);
            success = future.await(timeout);
        }
        Throwable cause = future.cause();
        if (cause != null) {
            throw cause;
        }
    } catch (Throwable e) {
        removeChannelIfDisconnected(channel);
        throw new RemotingException(this, "Failed to send message " + PayloadDropper.getRequestWithoutData(message) + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e);
    }
    if (!success) {
        throw new RemotingException(this, "Failed to send message " + PayloadDropper.getRequestWithoutData(message) + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit");
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) RemotingException(org.apache.dubbo.remoting.RemotingException)

Example 18 with RemotingException

use of org.apache.dubbo.remoting.RemotingException in project dubbo by alibaba.

the class FileExchangeGroup method leave.

@Override
public void leave(URL url) throws RemotingException {
    super.leave(url);
    try {
        String full = url.toFullString();
        String[] lines = IOUtils.readLines(file);
        List<String> saves = new ArrayList<String>();
        for (String line : lines) {
            if (full.equals(line)) {
                return;
            }
            saves.add(line);
        }
        IOUtils.appendLines(file, saves.toArray(new String[0]));
    } catch (IOException e) {
        throw new RemotingException(new InetSocketAddress(NetUtils.getLocalHost(), 0), getUrl().toInetSocketAddress(), e.getMessage(), e);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) RemotingException(org.apache.dubbo.remoting.RemotingException) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 19 with RemotingException

use of org.apache.dubbo.remoting.RemotingException in project dubbo by alibaba.

the class MinaChannel method send.

@Override
public void send(Object message, boolean sent) throws RemotingException {
    super.send(message, sent);
    boolean success = true;
    int timeout = 0;
    try {
        WriteFuture future = session.write(message);
        if (sent) {
            timeout = getUrl().getPositiveParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT);
            success = future.join(timeout);
        }
    } catch (Throwable e) {
        throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e);
    }
    if (!success) {
        throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit");
    }
}
Also used : WriteFuture(org.apache.mina.common.WriteFuture) RemotingException(org.apache.dubbo.remoting.RemotingException)

Example 20 with RemotingException

use of org.apache.dubbo.remoting.RemotingException in project dubbo by alibaba.

the class NettyClient method doConnect.

@Override
protected void doConnect() throws Throwable {
    long start = System.currentTimeMillis();
    ChannelFuture future = bootstrap.connect(getConnectAddress());
    try {
        boolean ret = future.awaitUninterruptibly(getConnectTimeout(), TimeUnit.MILLISECONDS);
        if (ret && future.isSuccess()) {
            Channel newChannel = future.getChannel();
            newChannel.setInterestOps(Channel.OP_READ_WRITE);
            try {
                // Close old channel
                // copy reference
                Channel oldChannel = NettyClient.this.channel;
                if (oldChannel != null) {
                    try {
                        if (logger.isInfoEnabled()) {
                            logger.info("Close old netty channel " + oldChannel + " on create new netty channel " + newChannel);
                        }
                        oldChannel.close();
                    } finally {
                        NettyChannel.removeChannelIfDisconnected(oldChannel);
                    }
                }
            } finally {
                if (NettyClient.this.isClosed()) {
                    try {
                        if (logger.isInfoEnabled()) {
                            logger.info("Close new netty channel " + newChannel + ", because the client closed.");
                        }
                        newChannel.close();
                    } finally {
                        NettyClient.this.channel = null;
                        NettyChannel.removeChannelIfDisconnected(newChannel);
                    }
                } else {
                    NettyClient.this.channel = newChannel;
                }
            }
        } else if (future.getCause() != null) {
            throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + ", error message is:" + future.getCause().getMessage(), future.getCause());
        } else {
            throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + " client-side timeout " + getConnectTimeout() + "ms (elapsed: " + (System.currentTimeMillis() - start) + "ms) from netty client " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion());
        }
    } finally {
        if (!isConnected()) {
            future.cancel();
        }
    }
}
Also used : ChannelFuture(org.jboss.netty.channel.ChannelFuture) Channel(org.jboss.netty.channel.Channel) RemotingException(org.apache.dubbo.remoting.RemotingException)

Aggregations

RemotingException (org.apache.dubbo.remoting.RemotingException)39 IOException (java.io.IOException)13 Request (org.apache.dubbo.remoting.exchange.Request)7 Response (org.apache.dubbo.remoting.exchange.Response)6 RpcException (org.apache.dubbo.rpc.RpcException)6 Channel (org.apache.dubbo.remoting.Channel)5 ExchangeChannel (org.apache.dubbo.remoting.exchange.ExchangeChannel)5 Test (org.junit.jupiter.api.Test)5 InetSocketAddress (java.net.InetSocketAddress)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 TimeoutException (org.apache.dubbo.remoting.TimeoutException)3 Transporter (org.apache.dubbo.remoting.Transporter)3 ExchangeClient (org.apache.dubbo.remoting.exchange.ExchangeClient)3 AppResponse (org.apache.dubbo.rpc.AppResponse)3 AsyncRpcResult (org.apache.dubbo.rpc.AsyncRpcResult)3 RpcInvocation (org.apache.dubbo.rpc.RpcInvocation)3 ChannelFuture (io.netty.channel.ChannelFuture)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2