Search in sources :

Example 16 with RemotingException

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

the class HeaderExchangeChannel method request.

public ResponseFuture request(Object request, int timeout) throws RemotingException {
    if (closed) {
        throw new RemotingException(this.getLocalAddress(), null, "Failed to send request " + request + ", cause: The channel " + this + " is closed!");
    }
    // create request.
    Request req = new Request();
    req.setVersion("2.0.0");
    req.setTwoWay(true);
    req.setData(request);
    DefaultFuture future = new DefaultFuture(channel, req, timeout);
    try {
        channel.send(req);
    } catch (RemotingException e) {
        future.cancel();
        throw e;
    }
    return future;
}
Also used : RemotingException(com.alibaba.dubbo.remoting.RemotingException) Request(com.alibaba.dubbo.remoting.exchange.Request) DefaultFuture(com.alibaba.dubbo.remoting.exchange.support.DefaultFuture)

Example 17 with RemotingException

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

the class HeaderExchangeChannel method send.

public void send(Object message, boolean sent) throws RemotingException {
    if (closed) {
        throw new RemotingException(this.getLocalAddress(), null, "Failed to send message " + message + ", cause: The channel " + this + " is closed!");
    }
    if (message instanceof Request || message instanceof Response || message instanceof String) {
        channel.send(message, sent);
    } else {
        Request request = new Request();
        request.setVersion("2.0.0");
        request.setTwoWay(false);
        request.setData(message);
        channel.send(request, sent);
    }
}
Also used : Response(com.alibaba.dubbo.remoting.exchange.Response) RemotingException(com.alibaba.dubbo.remoting.RemotingException) Request(com.alibaba.dubbo.remoting.exchange.Request)

Example 18 with RemotingException

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

the class HeaderExchangeHandler method sent.

public void sent(Channel channel, Object message) throws RemotingException {
    Throwable exception = null;
    try {
        channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
        ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
        try {
            handler.sent(exchangeChannel, message);
        } finally {
            HeaderExchangeChannel.removeChannelIfDisconnected(channel);
        }
    } catch (Throwable t) {
        exception = t;
    }
    if (message instanceof Request) {
        Request request = (Request) message;
        DefaultFuture.sent(channel, request);
    }
    if (exception != null) {
        if (exception instanceof RuntimeException) {
            throw (RuntimeException) exception;
        } else if (exception instanceof RemotingException) {
            throw (RemotingException) exception;
        } else {
            throw new RemotingException(channel.getLocalAddress(), channel.getRemoteAddress(), exception.getMessage(), exception);
        }
    }
}
Also used : RemotingException(com.alibaba.dubbo.remoting.RemotingException) Request(com.alibaba.dubbo.remoting.exchange.Request) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel)

Example 19 with RemotingException

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

the class HeaderExchangeServer method sendChannelReadOnlyEvent.

private void sendChannelReadOnlyEvent() {
    Request request = new Request();
    request.setEvent(Request.READONLY_EVENT);
    request.setTwoWay(false);
    request.setVersion(Version.getVersion());
    Collection<Channel> channels = getChannels();
    for (Channel channel : channels) {
        try {
            if (channel.isConnected())
                channel.send(request, getUrl().getParameter(Constants.CHANNEL_READONLYEVENT_SENT_KEY, true));
        } catch (RemotingException e) {
            logger.warn("send connot write messge error.", e);
        }
    }
}
Also used : ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) Channel(com.alibaba.dubbo.remoting.Channel) RemotingException(com.alibaba.dubbo.remoting.RemotingException) Request(com.alibaba.dubbo.remoting.exchange.Request)

Example 20 with RemotingException

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

the class AbstractClient method send.

public void send(Object message, boolean sent) throws RemotingException {
    if (send_reconnect && !isConnected()) {
        connect();
    }
    Channel channel = getChannel();
    // TODO Can the value returned by getChannel() be null? need improvement.
    if (channel == null || !channel.isConnected()) {
        throw new RemotingException(this, "message can not send, because channel is closed . url:" + getUrl());
    }
    channel.send(message, sent);
}
Also used : Channel(com.alibaba.dubbo.remoting.Channel) RemotingException(com.alibaba.dubbo.remoting.RemotingException)

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