Search in sources :

Example 1 with RemotingException

use of org.apache.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")
@Disabled("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 {
            Assertions.assertTrue(((Response) message).isHeartbeat(), "response.heartbeat");
            count.incrementAndGet();
        }
    }, req);
    Assertions.assertEquals(1, count.get(), "channel.send must be invoke");
}
Also used : Response(org.apache.dubbo.remoting.exchange.Response) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RemotingException(org.apache.dubbo.remoting.RemotingException) Request(org.apache.dubbo.remoting.exchange.Request) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ConnectionOrderedChannelHandler(org.apache.dubbo.remoting.transport.dispatcher.connection.ConnectionOrderedChannelHandler) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with RemotingException

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

the class GrizzlyChannel method send.

@Override
@SuppressWarnings("rawtypes")
public void send(Object message, boolean sent) throws RemotingException {
    super.send(message, sent);
    int timeout = 0;
    try {
        GrizzlyFuture future = connection.write(message);
        if (sent) {
            timeout = getUrl().getPositiveParameter(TIMEOUT_KEY, DEFAULT_TIMEOUT);
            future.get(timeout, TimeUnit.MILLISECONDS);
        }
    } catch (TimeoutException e) {
        throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit", e);
    } catch (Throwable e) {
        throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e);
    }
}
Also used : RemotingException(org.apache.dubbo.remoting.RemotingException) GrizzlyFuture(org.glassfish.grizzly.GrizzlyFuture) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with RemotingException

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

the class MinaClient method doConnect.

@Override
protected void doConnect() throws Throwable {
    ConnectFuture future = connector.connect(getConnectAddress(), new MinaHandler(getUrl(), this));
    long start = System.currentTimeMillis();
    final AtomicReference<Throwable> exception = new AtomicReference<Throwable>();
    // resolve future.awaitUninterruptibly() dead lock
    final CountDownLatch finish = new CountDownLatch(1);
    future.addListener(new IoFutureListener() {

        @Override
        public void operationComplete(IoFuture future) {
            try {
                if (future.isReady()) {
                    IoSession newSession = future.getSession();
                    try {
                        // Close old channel
                        // copy reference
                        IoSession oldSession = MinaClient.this.session;
                        if (oldSession != null) {
                            try {
                                if (logger.isInfoEnabled()) {
                                    logger.info("Close old mina channel " + oldSession + " on create new mina channel " + newSession);
                                }
                                oldSession.close();
                            } finally {
                                MinaChannel.removeChannelIfDisconnected(oldSession);
                            }
                        }
                    } finally {
                        if (MinaClient.this.isClosed()) {
                            try {
                                if (logger.isInfoEnabled()) {
                                    logger.info("Close new mina channel " + newSession + ", because the client closed.");
                                }
                                newSession.close();
                            } finally {
                                MinaClient.this.session = null;
                                MinaChannel.removeChannelIfDisconnected(newSession);
                            }
                        } else {
                            MinaClient.this.session = newSession;
                        }
                    }
                }
            } catch (Exception e) {
                exception.set(e);
            } finally {
                finish.countDown();
            }
        }
    });
    try {
        finish.await(getConnectTimeout(), TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
        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() + ", cause: " + e.getMessage(), e);
    }
    Throwable e = exception.get();
    if (e != null) {
        throw e;
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) IoFuture(org.apache.mina.common.IoFuture) ConnectFuture(org.apache.mina.common.ConnectFuture) CountDownLatch(java.util.concurrent.CountDownLatch) RemotingException(org.apache.dubbo.remoting.RemotingException) IoFutureListener(org.apache.mina.common.IoFutureListener) RemotingException(org.apache.dubbo.remoting.RemotingException) IoSession(org.apache.mina.common.IoSession)

Example 4 with RemotingException

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

the class GrizzlyHandler method handleConnect.

@Override
public NextAction handleConnect(FilterChainContext ctx) throws IOException {
    Connection<?> connection = ctx.getConnection();
    GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
    try {
        handler.connected(channel);
    } catch (RemotingException e) {
        throw new IOException(StringUtils.toString(e));
    } finally {
        GrizzlyChannel.removeChannelIfDisconnected(connection);
    }
    return ctx.getInvokeAction();
}
Also used : RemotingException(org.apache.dubbo.remoting.RemotingException) IOException(java.io.IOException)

Example 5 with RemotingException

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

the class GrizzlyHandler method handleClose.

@Override
public NextAction handleClose(FilterChainContext ctx) throws IOException {
    Connection<?> connection = ctx.getConnection();
    GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
    try {
        handler.disconnected(channel);
    } catch (RemotingException e) {
        throw new IOException(StringUtils.toString(e));
    } finally {
        GrizzlyChannel.removeChannelIfDisconnected(connection);
    }
    return ctx.getInvokeAction();
}
Also used : 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