Search in sources :

Example 1 with ExchangeServer

use of com.alibaba.dubbo.remoting.exchange.ExchangeServer in project incubator-dubbo-ops by apache.

the class ServersPageHandler method handle.

public Page handle(URL url) {
    List<List<String>> rows = new ArrayList<List<String>>();
    Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers();
    int clientCount = 0;
    if (servers != null && servers.size() > 0) {
        for (ExchangeServer s : servers) {
            List<String> row = new ArrayList<String>();
            String address = s.getUrl().getAddress();
            row.add(NetUtils.getHostName(address) + "/" + address);
            int clientSize = s.getExchangeChannels().size();
            clientCount += clientSize;
            row.add("<a href=\"clients.html?port=" + s.getUrl().getPort() + "\">Clients(" + clientSize + ")</a>");
            rows.add(row);
        }
    }
    return new Page("Servers", "Servers (" + rows.size() + ")", new String[] { "Server Address:", "Clients(" + clientCount + ")" }, rows);
}
Also used : ArrayList(java.util.ArrayList) ExchangeServer(com.alibaba.dubbo.remoting.exchange.ExchangeServer) List(java.util.List) ArrayList(java.util.ArrayList) Page(com.alibaba.dubbo.monitor.simple.common.Page)

Example 2 with ExchangeServer

use of com.alibaba.dubbo.remoting.exchange.ExchangeServer in project incubator-dubbo-ops by apache.

the class ClientsPageHandler method handle.

public Page handle(URL url) {
    String port = url.getParameter("port");
    int p = port == null || port.length() == 0 ? 0 : Integer.parseInt(port);
    Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers();
    ExchangeServer server = null;
    StringBuilder select = new StringBuilder();
    if (servers != null && servers.size() > 0) {
        if (servers.size() == 1) {
            server = servers.iterator().next();
            String address = server.getUrl().getAddress();
            select.append(" &gt; " + NetUtils.getHostName(address) + "/" + address);
        } else {
            select.append(" &gt; <select onchange=\"window.location.href='clients.html?port=' + this.value;\">");
            for (ExchangeServer s : servers) {
                int sp = s.getUrl().getPort();
                select.append("<option value=\">");
                select.append(sp);
                if (p == 0 && server == null || p == sp) {
                    server = s;
                    select.append("\" selected=\"selected");
                }
                select.append("\">");
                select.append(s.getUrl().getAddress());
                select.append("</option>");
            }
            select.append("</select>");
        }
    }
    List<List<String>> rows = new ArrayList<List<String>>();
    if (server != null) {
        Collection<ExchangeChannel> channels = server.getExchangeChannels();
        for (ExchangeChannel c : channels) {
            List<String> row = new ArrayList<String>();
            String address = NetUtils.toAddressString(c.getRemoteAddress());
            row.add(NetUtils.getHostName(address) + "/" + address);
            rows.add(row);
        }
    }
    return new Page("<a href=\"servers.html\">Servers</a>" + select.toString() + " &gt; Clients", "Clients (" + rows.size() + ")", new String[] { "Client Address:" }, rows);
}
Also used : ArrayList(java.util.ArrayList) ExchangeServer(com.alibaba.dubbo.remoting.exchange.ExchangeServer) List(java.util.List) ArrayList(java.util.ArrayList) ExchangeChannel(com.alibaba.dubbo.remoting.exchange.ExchangeChannel) Page(com.alibaba.dubbo.monitor.simple.common.Page)

Example 3 with ExchangeServer

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

the class DubboProtocol method destroy.

public void destroy() {
    for (String key : new ArrayList<String>(serverMap.keySet())) {
        ExchangeServer server = serverMap.remove(key);
        if (server != null) {
            try {
                if (logger.isInfoEnabled()) {
                    logger.info("Close dubbo server: " + server.getLocalAddress());
                }
                server.close(ConfigUtils.getServerShutdownTimeout());
            } catch (Throwable t) {
                logger.warn(t.getMessage(), t);
            }
        }
    }
    for (String key : new ArrayList<String>(referenceClientMap.keySet())) {
        ExchangeClient client = referenceClientMap.remove(key);
        if (client != null) {
            try {
                if (logger.isInfoEnabled()) {
                    logger.info("Close dubbo connect: " + client.getLocalAddress() + "-->" + client.getRemoteAddress());
                }
                client.close(ConfigUtils.getServerShutdownTimeout());
            } catch (Throwable t) {
                logger.warn(t.getMessage(), t);
            }
        }
    }
    for (String key : new ArrayList<String>(ghostClientMap.keySet())) {
        ExchangeClient client = ghostClientMap.remove(key);
        if (client != null) {
            try {
                if (logger.isInfoEnabled()) {
                    logger.info("Close dubbo connect: " + client.getLocalAddress() + "-->" + client.getRemoteAddress());
                }
                client.close(ConfigUtils.getServerShutdownTimeout());
            } catch (Throwable t) {
                logger.warn(t.getMessage(), t);
            }
        }
    }
    stubServiceMethodsMap.clear();
    super.destroy();
}
Also used : ExchangeClient(com.alibaba.dubbo.remoting.exchange.ExchangeClient) ArrayList(java.util.ArrayList) ExchangeServer(com.alibaba.dubbo.remoting.exchange.ExchangeServer)

Example 4 with ExchangeServer

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

the class DubboProtocol method openServer.

private void openServer(URL url) {
    // find server.
    String key = url.getAddress();
    // client can export a service which's only for server to invoke
    boolean isServer = url.getParameter(Constants.IS_SERVER_KEY, true);
    if (isServer) {
        ExchangeServer server = serverMap.get(key);
        if (server == null) {
            serverMap.put(key, createServer(url));
        } else {
            // server supports reset, use together with override
            server.reset(url);
        }
    }
}
Also used : ExchangeServer(com.alibaba.dubbo.remoting.exchange.ExchangeServer)

Example 5 with ExchangeServer

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

the class ServerStatusChecker method check.

public Status check() {
    Collection<ExchangeServer> servers = DubboProtocol.getDubboProtocol().getServers();
    if (servers == null || servers.isEmpty()) {
        return new Status(Status.Level.UNKNOWN);
    }
    Status.Level level = Status.Level.OK;
    StringBuilder buf = new StringBuilder();
    for (ExchangeServer server : servers) {
        if (!server.isBound()) {
            level = Status.Level.ERROR;
            buf.setLength(0);
            buf.append(server.getLocalAddress());
            break;
        }
        if (buf.length() > 0) {
            buf.append(",");
        }
        buf.append(server.getLocalAddress());
        buf.append("(clients:");
        buf.append(server.getChannels().size());
        buf.append(")");
    }
    return new Status(level, buf.toString());
}
Also used : Status(com.alibaba.dubbo.common.status.Status) 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