Search in sources :

Example 11 with ExchangeServer

use of com.alibaba.dubbo.remoting.exchange.ExchangeServer in project dubbo by alibaba.

the class DubboProtocol method createServer.

private ExchangeServer createServer(URL url) {
    // send readonly event when server closes, it's enabled by default
    url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString());
    // enable heartbeat by default
    url = url.addParameterIfAbsent(Constants.HEARTBEAT_KEY, String.valueOf(Constants.DEFAULT_HEARTBEAT));
    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);
    url = url.addParameter(Constants.CODEC_KEY, DubboCodec.NAME);
    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(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 12 with ExchangeServer

use of com.alibaba.dubbo.remoting.exchange.ExchangeServer in project dubbo by alibaba.

the class PortTelnetHandler method telnet.

public String telnet(Channel channel, String message) {
    StringBuilder buf = new StringBuilder();
    String port = null;
    boolean detail = false;
    if (message.length() > 0) {
        String[] parts = message.split("\\s+");
        for (String part : parts) {
            if ("-l".equals(part)) {
                detail = true;
            } else {
                if (!StringUtils.isInteger(part)) {
                    return "Illegal port " + part + ", must be integer.";
                }
                port = part;
            }
        }
    }
    if (port == null || port.length() == 0) {
        for (ExchangeServer server : DubboProtocol.getDubboProtocol().getServers()) {
            if (buf.length() > 0) {
                buf.append("\r\n");
            }
            if (detail) {
                buf.append(server.getUrl().getProtocol() + "://" + server.getUrl().getAddress());
            } else {
                buf.append(server.getUrl().getPort());
            }
        }
    } else {
        int p = Integer.parseInt(port);
        ExchangeServer server = null;
        for (ExchangeServer s : DubboProtocol.getDubboProtocol().getServers()) {
            if (p == s.getUrl().getPort()) {
                server = s;
                break;
            }
        }
        if (server != null) {
            Collection<ExchangeChannel> channels = server.getExchangeChannels();
            for (ExchangeChannel c : channels) {
                if (buf.length() > 0) {
                    buf.append("\r\n");
                }
                if (detail) {
                    buf.append(c.getRemoteAddress() + " -> " + c.getLocalAddress());
                } else {
                    buf.append(c.getRemoteAddress());
                }
            }
        } else {
            buf.append("No such port " + port);
        }
    }
    return buf.toString();
}
Also used : ExchangeServer(com.alibaba.dubbo.remoting.exchange.ExchangeServer) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel)

Example 13 with ExchangeServer

use of com.alibaba.dubbo.remoting.exchange.ExchangeServer in project dubbo by alibaba.

the class ProtocolUtils method closeAll.

public static void closeAll() {
    DubboProtocol.getDubboProtocol().destroy();
    Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers();
    for (ExchangeServer server : servers) {
        server.close();
    }
}
Also used : ExchangeServer(com.alibaba.dubbo.remoting.exchange.ExchangeServer)

Example 14 with ExchangeServer

use of com.alibaba.dubbo.remoting.exchange.ExchangeServer in project dubbo by alibaba.

the class AbstractExchangeGroup method join.

public ExchangePeer join(URL url, ExchangeHandler handler) throws RemotingException {
    ExchangeServer server = servers.get(url);
    if (server == null) {
        // TODO exist concurrent gap
        server = Exchangers.bind(url, handler);
        servers.put(url, server);
        dispatcher.addChannelHandler(handler);
    }
    return new ExchangeServerPeer(server, clients, this);
}
Also used : ExchangeServer(com.alibaba.dubbo.remoting.exchange.ExchangeServer)

Aggregations

ExchangeServer (com.alibaba.dubbo.remoting.exchange.ExchangeServer)14 ArrayList (java.util.ArrayList)6 ExchangeChannel (com.alibaba.dubbo.remoting.exchange.ExchangeChannel)5 List (java.util.List)5 Page (com.alibaba.dubbo.container.page.Page)2 Page (com.alibaba.dubbo.monitor.simple.common.Page)2 RemotingException (com.alibaba.dubbo.remoting.RemotingException)2 Transporter (com.alibaba.dubbo.remoting.Transporter)2 ExchangeHandlerAdapter (com.alibaba.dubbo.remoting.exchange.support.ExchangeHandlerAdapter)2 RpcException (com.alibaba.dubbo.rpc.RpcException)2 Status (com.alibaba.dubbo.common.status.Status)1 ExchangeClient (com.alibaba.dubbo.remoting.exchange.ExchangeClient)1