Search in sources :

Example 36 with RemotingException

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

the class AbstractClient method connect.

protected void connect() throws RemotingException {
    connectLock.lock();
    try {
        if (isConnected()) {
            return;
        }
        initConnectStatusCheckCommand();
        doConnect();
        if (!isConnected()) {
            throw new RemotingException(this, "Failed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion() + ", cause: Connect wait timeout: " + getTimeout() + "ms.");
        } else {
            if (logger.isInfoEnabled()) {
                logger.info("Successed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion() + ", channel is " + this.getChannel());
            }
        }
        reconnect_count.set(0);
        reconnect_error_log_flag.set(false);
    } catch (RemotingException e) {
        throw e;
    } catch (Throwable e) {
        throw new RemotingException(this, "Failed connect to server " + getRemoteAddress() + " from " + getClass().getSimpleName() + " " + NetUtils.getLocalHost() + " using dubbo version " + Version.getVersion() + ", cause: " + e.getMessage(), e);
    } finally {
        connectLock.unlock();
    }
}
Also used : RemotingException(com.alibaba.dubbo.remoting.RemotingException)

Example 37 with RemotingException

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

the class DeprecatedTelnetCodec method decode.

@SuppressWarnings("unchecked")
protected Object decode(Channel channel, InputStream is, int readable, byte[] message) throws IOException {
    if (isClientSide(channel)) {
        return toString(message, getCharset(channel));
    }
    checkPayload(channel, readable);
    if (message == null || message.length == 0) {
        return NEED_MORE_INPUT;
    }
    if (message[message.length - 1] == '\b') {
        // Windows backspace echo
        try {
            // double byte char
            boolean doublechar = message.length >= 3 && message[message.length - 3] < 0;
            channel.send(new String(doublechar ? new byte[] { 32, 32, 8, 8 } : new byte[] { 32, 8 }, getCharset(channel).name()));
        } catch (RemotingException e) {
            throw new IOException(StringUtils.toString(e));
        }
        return NEED_MORE_INPUT;
    }
    for (Object command : EXIT) {
        if (isEquals(message, (byte[]) command)) {
            if (logger.isInfoEnabled()) {
                logger.info(new Exception("Close channel " + channel + " on exit command: " + Arrays.toString((byte[]) command)));
            }
            channel.close();
            return null;
        }
    }
    boolean up = endsWith(message, UP);
    boolean down = endsWith(message, DOWN);
    if (up || down) {
        LinkedList<String> history = (LinkedList<String>) channel.getAttribute(HISTORY_LIST_KEY);
        if (history == null || history.size() == 0) {
            return NEED_MORE_INPUT;
        }
        Integer index = (Integer) channel.getAttribute(HISTORY_INDEX_KEY);
        Integer old = index;
        if (index == null) {
            index = history.size() - 1;
        } else {
            if (up) {
                index = index - 1;
                if (index < 0) {
                    index = history.size() - 1;
                }
            } else {
                index = index + 1;
                if (index > history.size() - 1) {
                    index = 0;
                }
            }
        }
        if (old == null || !old.equals(index)) {
            channel.setAttribute(HISTORY_INDEX_KEY, index);
            String value = history.get(index);
            if (old != null && old >= 0 && old < history.size()) {
                String ov = history.get(old);
                StringBuilder buf = new StringBuilder();
                for (int i = 0; i < ov.length(); i++) {
                    buf.append("\b");
                }
                for (int i = 0; i < ov.length(); i++) {
                    buf.append(" ");
                }
                for (int i = 0; i < ov.length(); i++) {
                    buf.append("\b");
                }
                value = buf.toString() + value;
            }
            try {
                channel.send(value);
            } catch (RemotingException e) {
                throw new IOException(StringUtils.toString(e));
            }
        }
        return NEED_MORE_INPUT;
    }
    for (Object command : EXIT) {
        if (isEquals(message, (byte[]) command)) {
            if (logger.isInfoEnabled()) {
                logger.info(new Exception("Close channel " + channel + " on exit command " + command));
            }
            channel.close();
            return null;
        }
    }
    byte[] enter = null;
    for (Object command : ENTER) {
        if (endsWith(message, (byte[]) command)) {
            enter = (byte[]) command;
            break;
        }
    }
    if (enter == null) {
        return NEED_MORE_INPUT;
    }
    LinkedList<String> history = (LinkedList<String>) channel.getAttribute(HISTORY_LIST_KEY);
    Integer index = (Integer) channel.getAttribute(HISTORY_INDEX_KEY);
    channel.removeAttribute(HISTORY_INDEX_KEY);
    if (history != null && history.size() > 0 && index != null && index >= 0 && index < history.size()) {
        String value = history.get(index);
        if (value != null) {
            byte[] b1 = value.getBytes();
            if (message != null && message.length > 0) {
                byte[] b2 = new byte[b1.length + message.length];
                System.arraycopy(b1, 0, b2, 0, b1.length);
                System.arraycopy(message, 0, b2, b1.length, message.length);
                message = b2;
            } else {
                message = b1;
            }
        }
    }
    String result = toString(message, getCharset(channel));
    if (result != null && result.trim().length() > 0) {
        if (history == null) {
            history = new LinkedList<String>();
            channel.setAttribute(HISTORY_LIST_KEY, history);
        }
        if (history.size() == 0) {
            history.addLast(result);
        } else if (!result.equals(history.getLast())) {
            history.remove(result);
            history.addLast(result);
            if (history.size() > 10) {
                history.removeFirst();
            }
        }
    }
    return result;
}
Also used : RemotingException(com.alibaba.dubbo.remoting.RemotingException) IOException(java.io.IOException) IOException(java.io.IOException) RemotingException(com.alibaba.dubbo.remoting.RemotingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LinkedList(java.util.LinkedList)

Example 38 with RemotingException

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

the class GrizzlyChannel method send.

@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(Constants.TIMEOUT_KEY, Constants.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(com.alibaba.dubbo.remoting.RemotingException) GrizzlyFuture(org.glassfish.grizzly.GrizzlyFuture) TimeoutException(java.util.concurrent.TimeoutException)

Example 39 with RemotingException

use of com.alibaba.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.removeChannelIfDisconnectd(connection);
    }
    return ctx.getInvokeAction();
}
Also used : RemotingException(com.alibaba.dubbo.remoting.RemotingException) IOException(java.io.IOException)

Example 40 with RemotingException

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

the class AbstractBenchmarkServer method run.

public void run(String[] args) throws Exception {
    if (args == null || args.length != 5) {
        throw new IllegalArgumentException("must give three args: listenPort | maxThreads | responseSize | transporter | serialization");
    }
    int listenPort = Integer.parseInt(args[0]);
    int maxThreads = Integer.parseInt(args[1]);
    final int responseSize = Integer.parseInt(args[2]);
    String transporter = args[3];
    String serialization = args[4];
    System.out.println(dateFormat.format(new Date()) + " ready to start server,listenPort is: " + listenPort + ",maxThreads is:" + maxThreads + ",responseSize is:" + responseSize + " bytes,transporter is:" + transporter + ",serialization is:" + serialization);
    StringBuilder url = new StringBuilder();
    url.append("exchange://0.0.0.0:");
    url.append(listenPort);
    url.append("?transporter=");
    url.append(transporter);
    url.append("&serialization=");
    url.append(serialization);
    url.append("&threads=");
    url.append(maxThreads);
    Exchangers.bind(url.toString(), new ExchangeHandlerAdapter() {

        public Object reply(ExchangeChannel channel, Object message) throws RemotingException {
            // send response
            return new ResponseObject(responseSize);
        }
    });
}
Also used : ExchangeHandlerAdapter(com.alibaba.dubbo.remoting.exchange.support.ExchangeHandlerAdapter) RemotingException(com.alibaba.dubbo.remoting.RemotingException) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) Date(java.util.Date)

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