Search in sources :

Example 1 with RemotingException

use of com.alibaba.dubbo.remoting.RemotingException in project dubbo by alibaba.

the class CallbackServiceCodec method decodeInvocationArgument.

public static Object decodeInvocationArgument(Channel channel, RpcInvocation inv, Class<?>[] pts, int paraIndex, Object inObject) throws IOException {
    // if it's a callback, create proxy on client side, callback interface on client side can be invoked through channel
    // need get URL from channel and env when decode
    URL url = null;
    try {
        url = DubboProtocol.getDubboProtocol().getInvoker(channel, inv).getUrl();
    } catch (RemotingException e) {
        if (logger.isInfoEnabled()) {
            logger.info(e.getMessage(), e);
        }
        return inObject;
    }
    byte callbackstatus = isCallBack(url, inv.getMethodName(), paraIndex);
    switch(callbackstatus) {
        case CallbackServiceCodec.CALLBACK_NONE:
            return inObject;
        case CallbackServiceCodec.CALLBACK_CREATE:
            try {
                return referOrdestroyCallbackService(channel, url, pts[paraIndex], inv, Integer.parseInt(inv.getAttachment(INV_ATT_CALLBACK_KEY + paraIndex)), true);
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
                throw new IOException(StringUtils.toString(e));
            }
        case CallbackServiceCodec.CALLBACK_DESTROY:
            try {
                return referOrdestroyCallbackService(channel, url, pts[paraIndex], inv, Integer.parseInt(inv.getAttachment(INV_ATT_CALLBACK_KEY + paraIndex)), false);
            } catch (Exception e) {
                throw new IOException(StringUtils.toString(e));
            }
        default:
            return inObject;
    }
}
Also used : RemotingException(com.alibaba.dubbo.remoting.RemotingException) IOException(java.io.IOException) URL(com.alibaba.dubbo.common.URL) IOException(java.io.IOException) RemotingException(com.alibaba.dubbo.remoting.RemotingException)

Example 2 with RemotingException

use of com.alibaba.dubbo.remoting.RemotingException in project dubbo by alibaba.

the class ChannelWrappedInvoker method doInvoke.

@Override
protected Result doInvoke(Invocation invocation) throws Throwable {
    RpcInvocation inv = (RpcInvocation) invocation;
    // use interface's name as service path to export if it's not found on client side
    inv.setAttachment(Constants.PATH_KEY, getInterface().getName());
    inv.setAttachment(Constants.CALLBACK_SERVICE_KEY, serviceKey);
    try {
        if (getUrl().getMethodParameter(invocation.getMethodName(), Constants.ASYNC_KEY, false)) {
            // may have concurrency issue
            currentClient.send(inv, getUrl().getMethodParameter(invocation.getMethodName(), Constants.SENT_KEY, false));
            return new RpcResult();
        }
        int timeout = getUrl().getMethodParameter(invocation.getMethodName(), Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
        if (timeout > 0) {
            return (Result) currentClient.request(inv, timeout).get();
        } else {
            return (Result) currentClient.request(inv).get();
        }
    } catch (RpcException e) {
        throw e;
    } catch (TimeoutException e) {
        throw new RpcException(RpcException.TIMEOUT_EXCEPTION, e.getMessage(), e);
    } catch (RemotingException e) {
        throw new RpcException(RpcException.NETWORK_EXCEPTION, e.getMessage(), e);
    } catch (Throwable e) {
        // here is non-biz exception, wrap it.
        throw new RpcException(e.getMessage(), e);
    }
}
Also used : RpcInvocation(com.alibaba.dubbo.rpc.RpcInvocation) RpcException(com.alibaba.dubbo.rpc.RpcException) RemotingException(com.alibaba.dubbo.remoting.RemotingException) RpcResult(com.alibaba.dubbo.rpc.RpcResult) Result(com.alibaba.dubbo.rpc.Result) RpcResult(com.alibaba.dubbo.rpc.RpcResult) TimeoutException(com.alibaba.dubbo.remoting.TimeoutException)

Example 3 with RemotingException

use of com.alibaba.dubbo.remoting.RemotingException in project dubbo by alibaba.

the class MinaChannel method send.

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(Constants.TIMEOUT_KEY, Constants.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(com.alibaba.dubbo.remoting.RemotingException)

Example 4 with RemotingException

use of com.alibaba.dubbo.remoting.RemotingException in project dubbo by alibaba.

the class NettyClient method doConnect.

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(com.alibaba.dubbo.remoting.RemotingException)

Example 5 with RemotingException

use of com.alibaba.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(com.alibaba.dubbo.remoting.p2p.exchange.ExchangePeer) InetSocketAddress(java.net.InetSocketAddress) RemotingException(com.alibaba.dubbo.remoting.RemotingException) IOException(java.io.IOException)

Aggregations

RemotingException (com.alibaba.dubbo.remoting.RemotingException)40 IOException (java.io.IOException)13 Request (com.alibaba.dubbo.remoting.exchange.Request)7 RpcException (com.alibaba.dubbo.rpc.RpcException)7 ExchangeChannel (com.alibaba.dubbo.remoting.exchange.ExchangeChannel)5 Response (com.alibaba.dubbo.remoting.exchange.Response)5 Channel (com.alibaba.dubbo.remoting.Channel)4 ExchangeClient (com.alibaba.dubbo.remoting.exchange.ExchangeClient)4 InetSocketAddress (java.net.InetSocketAddress)4 TimeoutException (com.alibaba.dubbo.remoting.TimeoutException)3 Transporter (com.alibaba.dubbo.remoting.Transporter)3 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)3 Test (org.junit.Test)3 ObjectOutput (com.alibaba.dubbo.common.serialize.ObjectOutput)2 Serialization (com.alibaba.dubbo.common.serialize.Serialization)2 ExchangeServer (com.alibaba.dubbo.remoting.exchange.ExchangeServer)2 Result (com.alibaba.dubbo.rpc.Result)2 RpcResult (com.alibaba.dubbo.rpc.RpcResult)2 ChannelFuture (io.netty.channel.ChannelFuture)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2