Search in sources :

Example 6 with RemotingException

use of com.alibaba.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(com.alibaba.dubbo.remoting.RemotingException) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 7 with RemotingException

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

the class ThriftProtocol method getServer.

private ExchangeServer getServer(URL url) {
    // enable sending readonly event when server closes by default
    url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString());
    String str = url.getParameter(Constants.SERVER_KEY, Constants.DEFAULT_REMOTING_SERVER);
    if (str != null && str.length() > 0 && !ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str))
        throw new RpcException("Unsupported server type: " + str + ", url: " + url);
    ExchangeServer server;
    try {
        server = Exchangers.bind(url, handler);
    } catch (RemotingException e) {
        throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e);
    }
    str = url.getParameter(Constants.CLIENT_KEY);
    if (str != null && str.length() > 0) {
        Set<String> supportedTypes = ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions();
        if (!supportedTypes.contains(str)) {
            throw new RpcException("Unsupported client type: " + str);
        }
    }
    return server;
}
Also used : RpcException(com.alibaba.dubbo.rpc.RpcException) RemotingException(com.alibaba.dubbo.remoting.RemotingException) ExchangeServer(com.alibaba.dubbo.remoting.exchange.ExchangeServer) Transporter(com.alibaba.dubbo.remoting.Transporter)

Example 8 with RemotingException

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

the class ThriftProtocol method initClient.

private ExchangeClient initClient(URL url) {
    ExchangeClient client;
    url = url.addParameter(Constants.CODEC_KEY, ThriftCodec.NAME);
    try {
        client = Exchangers.connect(url);
    } catch (RemotingException e) {
        throw new RpcException("Fail to create remoting client for service(" + url + "): " + e.getMessage(), e);
    }
    return client;
}
Also used : ExchangeClient(com.alibaba.dubbo.remoting.exchange.ExchangeClient) RemotingException(com.alibaba.dubbo.remoting.RemotingException) RpcException(com.alibaba.dubbo.rpc.RpcException)

Example 9 with RemotingException

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

the class ConnectChannelHandlerTest method test_Received_Event_invoke_direct.

/**
 * Events do not pass through the thread pool and execute directly on the IO
 */
@SuppressWarnings("deprecation")
@Ignore("Heartbeat is processed in HeartbeatHandler not WrappedChannelHandler.")
@Test
public void test_Received_Event_invoke_direct() throws RemotingException {
    handler = new ConnectionOrderedChannelHandler(new BizChannelHander(false), url);
    ThreadPoolExecutor executor = (ThreadPoolExecutor) getField(handler, "SHARED_EXECUTOR", 1);
    executor.shutdown();
    executor = (ThreadPoolExecutor) getField(handler, "executor", 1);
    executor.shutdown();
    Request req = new Request();
    req.setHeartbeat(true);
    final AtomicInteger count = new AtomicInteger(0);
    handler.received(new MockedChannel() {

        @Override
        public void send(Object message) throws RemotingException {
            Assert.assertEquals("response.heartbeat", true, ((Response) message).isHeartbeat());
            count.incrementAndGet();
        }
    }, req);
    Assert.assertEquals("channel.send must be invoke", 1, count.get());
}
Also used : Response(com.alibaba.dubbo.remoting.exchange.Response) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RemotingException(com.alibaba.dubbo.remoting.RemotingException) Request(com.alibaba.dubbo.remoting.exchange.Request) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ConnectionOrderedChannelHandler(com.alibaba.dubbo.remoting.transport.dispatcher.connection.ConnectionOrderedChannelHandler) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with RemotingException

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

the class HeaderExchangeHandlerTest method test_received_request_event_other_discard.

@Test
public void test_received_request_event_other_discard() throws RemotingException {
    final Request request = new Request();
    request.setTwoWay(true);
    request.setEvent("my event");
    final Channel mchannel = new MockedChannel() {

        @Override
        public void send(Object message) throws RemotingException {
            Assert.fail();
        }
    };
    HeaderExchangeHandler hexhandler = new HeaderExchangeHandler(new MockedExchangeHandler() {

        @Override
        public Object reply(ExchangeChannel channel, Object request) throws RemotingException {
            Assert.fail();
            throw new RemotingException(channel, "");
        }

        @Override
        public void received(Channel channel, Object message) throws RemotingException {
            Assert.fail();
            throw new RemotingException(channel, "");
        }
    });
    hexhandler.received(mchannel, request);
}
Also used : ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) Channel(com.alibaba.dubbo.remoting.Channel) HeaderExchangeHandler(com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchangeHandler) RemotingException(com.alibaba.dubbo.remoting.RemotingException) Request(com.alibaba.dubbo.remoting.exchange.Request) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) Test(org.junit.Test)

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