Search in sources :

Example 36 with RemotingException

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

the class FileGroup 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 37 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(), MILLISECONDS);
        if (ret && future.isSuccess()) {
            Channel newChannel = future.channel();
            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.cause() != null) {
            throw new RemotingException(this, "client(url: " + getUrl() + ") failed to connect to server " + getRemoteAddress() + ", error message is:" + future.cause().getMessage(), future.cause());
        } 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 {
        // just add new valid channel to NettyChannel's cache
        if (!isConnected()) {
        // future.cancel(true);
        }
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) SocketChannel(io.netty.channel.socket.SocketChannel) Channel(io.netty.channel.Channel) RemotingException(org.apache.dubbo.remoting.RemotingException)

Example 38 with RemotingException

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

the class RpcMessageHandler method reply.

public Object reply(ExchangeChannel channel, RpcMessage msg) throws RemotingException {
    String desc = msg.getMethodDesc();
    Object[] args = msg.getArguments();
    Object impl = mProvider.getImplementation(msg.getClassName());
    Wrapper wrap = Wrapper.getWrapper(impl.getClass());
    try {
        return new MockResult(wrap.invokeMethod(impl, desc, msg.getParameterTypes(), args));
    } catch (NoSuchMethodException e) {
        throw new RemotingException(channel, "Service method not found.");
    } catch (InvocationTargetException e) {
        return new MockResult(e.getTargetException());
    }
}
Also used : Wrapper(org.apache.dubbo.common.bytecode.Wrapper) RemotingException(org.apache.dubbo.remoting.RemotingException) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchMethodException(org.apache.dubbo.common.bytecode.NoSuchMethodException)

Example 39 with RemotingException

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

the class FileExchangeGroup method joinExchange.

public ExchangePeer joinExchange(URL url, ExchangeHandler handler) throws RemotingException {
    ExchangePeer 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 : ExchangePeer(org.apache.dubbo.remoting.p2p.exchange.ExchangePeer) InetSocketAddress(java.net.InetSocketAddress) RemotingException(org.apache.dubbo.remoting.RemotingException) IOException(java.io.IOException)

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