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);
}
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(" > " + NetUtils.getHostName(address) + "/" + address);
} else {
select.append(" > <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() + " > Clients", "Clients (" + rows.size() + ")", new String[] { "Client Address:" }, rows);
}
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();
}
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);
}
}
}
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());
}
Aggregations