Search in sources :

Example 6 with RemotingException

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

the class GrizzlyHandler method handleWrite.

@Override
public NextAction handleWrite(FilterChainContext ctx) throws IOException {
    Connection<?> connection = ctx.getConnection();
    GrizzlyChannel channel = GrizzlyChannel.getOrAddChannel(connection, url, handler);
    try {
        handler.sent(channel, ctx.getMessage());
    } 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 7 with RemotingException

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

the class DubboProtocol method initClient.

/**
 * Create new connection
 *
 * @param url
 */
private ExchangeClient initClient(URL url) {
    // client type setting.
    String str = url.getParameter(CLIENT_KEY, url.getParameter(SERVER_KEY, DEFAULT_REMOTING_CLIENT));
    url = url.addParameter(CODEC_KEY, DubboCodec.NAME);
    // enable heartbeat by default
    url = url.addParameterIfAbsent(HEARTBEAT_KEY, String.valueOf(DEFAULT_HEARTBEAT));
    // BIO is not allowed since it has severe performance issue.
    if (str != null && str.length() > 0 && !ExtensionLoader.getExtensionLoader(Transporter.class).hasExtension(str)) {
        throw new RpcException("Unsupported client type: " + str + "," + " supported client type is " + StringUtils.join(ExtensionLoader.getExtensionLoader(Transporter.class).getSupportedExtensions(), " "));
    }
    ExchangeClient client;
    try {
        // connection should be lazy
        if (url.getParameter(LAZY_CONNECT_KEY, false)) {
            client = new LazyConnectExchangeClient(url, requestHandler);
        } else {
            client = Exchangers.connect(url, requestHandler);
        }
    } catch (RemotingException e) {
        throw new RpcException("Fail to create remoting client for service(" + url + "): " + e.getMessage(), e);
    }
    return client;
}
Also used : ExchangeClient(org.apache.dubbo.remoting.exchange.ExchangeClient) RpcException(org.apache.dubbo.rpc.RpcException) RemotingException(org.apache.dubbo.remoting.RemotingException) Transporter(org.apache.dubbo.remoting.Transporter)

Example 8 with RemotingException

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

the class DubboProtocol method createServer.

private ProtocolServer createServer(URL url) {
    url = URLBuilder.from(url).addParameterIfAbsent(CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString()).addParameterIfAbsent(HEARTBEAT_KEY, String.valueOf(DEFAULT_HEARTBEAT)).addParameter(CODEC_KEY, DubboCodec.NAME).build();
    String str = url.getParameter(SERVER_KEY, 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, requestHandler);
    } catch (RemotingException e) {
        throw new RpcException("Fail to start server(url: " + url + ") " + e.getMessage(), e);
    }
    str = url.getParameter(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 new DubboProtocolServer(server);
}
Also used : RpcException(org.apache.dubbo.rpc.RpcException) RemotingException(org.apache.dubbo.remoting.RemotingException) ExchangeServer(org.apache.dubbo.remoting.exchange.ExchangeServer) Transporter(org.apache.dubbo.remoting.Transporter)

Example 9 with RemotingException

use of org.apache.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(PATH_KEY, getInterface().getName());
    inv.setAttachment(CALLBACK_SERVICE_KEY, serviceKey);
    try {
        if (RpcUtils.isOneway(getUrl(), inv)) {
            // may have concurrency issue
            currentClient.send(inv, getUrl().getMethodParameter(invocation.getMethodName(), SENT_KEY, false));
            return AsyncRpcResult.newDefaultAsyncResult(invocation);
        } else {
            final String methodName = RpcUtils.getMethodName(invocation);
            final int timeout = (int) RpcUtils.getTimeout(getUrl(), methodName, RpcContext.getContext(), DEFAULT_TIMEOUT);
            CompletableFuture<AppResponse> appResponseFuture = currentClient.request(inv, timeout, null).thenApply(obj -> (AppResponse) obj);
            return new AsyncRpcResult(appResponseFuture, inv);
        }
    } 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(org.apache.dubbo.rpc.RpcInvocation) AppResponse(org.apache.dubbo.rpc.AppResponse) RpcException(org.apache.dubbo.rpc.RpcException) RemotingException(org.apache.dubbo.remoting.RemotingException) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) TimeoutException(org.apache.dubbo.remoting.TimeoutException)

Example 10 with RemotingException

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

the class ThriftInvoker method doInvoke.

@Override
protected Result doInvoke(Invocation invocation) throws Throwable {
    RpcInvocation inv = (RpcInvocation) invocation;
    final String methodName;
    methodName = invocation.getMethodName();
    inv.setAttachment(PATH_KEY, getUrl().getPath());
    // for thrift codec
    inv.setAttachment(ThriftCodec.PARAMETER_CLASS_NAME_GENERATOR, getUrl().getParameter(ThriftCodec.PARAMETER_CLASS_NAME_GENERATOR, DubboClassNameGenerator.NAME));
    ExchangeClient currentClient;
    if (clients.length == 1) {
        currentClient = clients[0];
    } else {
        currentClient = clients[index.getAndIncrement() % clients.length];
    }
    try {
        int timeout = getUrl().getMethodParameter(methodName, TIMEOUT_KEY, DEFAULT_TIMEOUT);
        ExecutorService executor = getCallbackExecutor(getUrl(), inv);
        CompletableFuture<AppResponse> appResponseFuture = currentClient.request(inv, timeout, executor).thenApply(obj -> (AppResponse) obj);
        // save for 2.6.x compatibility, for example, TraceFilter in Zipkin uses com.alibaba.xxx.FutureAdapter
        FutureContext.getContext().setCompatibleFuture(appResponseFuture);
        AsyncRpcResult result = new AsyncRpcResult(appResponseFuture, invocation);
        result.setExecutor(executor);
        return result;
    } catch (TimeoutException e) {
        throw new RpcException(RpcException.TIMEOUT_EXCEPTION, e.getMessage(), e);
    } catch (RemotingException e) {
        throw new RpcException(RpcException.NETWORK_EXCEPTION, e.getMessage(), e);
    }
}
Also used : RpcInvocation(org.apache.dubbo.rpc.RpcInvocation) ExchangeClient(org.apache.dubbo.remoting.exchange.ExchangeClient) AppResponse(org.apache.dubbo.rpc.AppResponse) RpcException(org.apache.dubbo.rpc.RpcException) RemotingException(org.apache.dubbo.remoting.RemotingException) ExecutorService(java.util.concurrent.ExecutorService) AsyncRpcResult(org.apache.dubbo.rpc.AsyncRpcResult) TimeoutException(org.apache.dubbo.remoting.TimeoutException)

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