use of com.alibaba.dubbo.remoting.exchange.ExchangeServer in project dubbo by alibaba.
the class ThriftProtocol method getServer.
private ExchangeServer getServer(URL url) {
// enable sending readonly event when server closes by default
url = url.addParameterIfAbsent(Constants.CHANNEL_READONLYEVENT_SENT_KEY, Boolean.TRUE.toString());
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);
ExchangeServer server;
try {
server = Exchangers.bind(url, handler);
} 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;
}
use of com.alibaba.dubbo.remoting.exchange.ExchangeServer in project dubbo by alibaba.
the class PerformanceServerTest method statServer.
private static ExchangeServer statServer() throws Exception {
final int port = PerformanceUtils.getIntProperty("port", 9911);
final String transporter = PerformanceUtils.getProperty(Constants.TRANSPORTER_KEY, Constants.DEFAULT_TRANSPORTER);
final String serialization = PerformanceUtils.getProperty(Constants.SERIALIZATION_KEY, Constants.DEFAULT_REMOTING_SERIALIZATION);
final String threadpool = PerformanceUtils.getProperty(Constants.THREADPOOL_KEY, Constants.DEFAULT_THREADPOOL);
final int threads = PerformanceUtils.getIntProperty(Constants.THREADS_KEY, Constants.DEFAULT_THREADS);
final int iothreads = PerformanceUtils.getIntProperty(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS);
final int buffer = PerformanceUtils.getIntProperty(Constants.BUFFER_KEY, Constants.DEFAULT_BUFFER_SIZE);
final String channelHandler = PerformanceUtils.getProperty(Constants.DISPATCHER_KEY, ExecutionDispatcher.NAME);
// Start server
ExchangeServer server = Exchangers.bind("exchange://0.0.0.0:" + port + "?transporter=" + transporter + "&serialization=" + serialization + "&threadpool=" + threadpool + "&threads=" + threads + "&iothreads=" + iothreads + "&buffer=" + buffer + "&channel.handler=" + channelHandler, new ExchangeHandlerAdapter() {
public String telnet(Channel channel, String message) throws RemotingException {
return "echo: " + message + "\r\ntelnet> ";
}
public Object reply(ExchangeChannel channel, Object request) throws RemotingException {
if ("environment".equals(request)) {
return PerformanceUtils.getEnvironment();
}
if ("scene".equals(request)) {
List<String> scene = new ArrayList<String>();
scene.add("Transporter: " + transporter);
scene.add("Service Threads: " + threads);
return scene;
}
return request;
}
});
return server;
}
use of com.alibaba.dubbo.remoting.exchange.ExchangeServer in project dubbo by alibaba.
the class PerformanceServerTest method statTelnetServer.
private static ExchangeServer statTelnetServer(int port) throws Exception {
// Start server
ExchangeServer telnetserver = Exchangers.bind("exchange://0.0.0.0:" + port, new ExchangeHandlerAdapter() {
public String telnet(Channel channel, String message) throws RemotingException {
if (message.equals("help")) {
return "support cmd: \r\n\tstart \r\n\tstop \r\n\tshutdown \r\n\trestart times [alive] [sleep] \r\ntelnet>";
} else if (message.equals("stop")) {
logger.info("server closed:" + server);
server.close();
return "stop server\r\ntelnet>";
} else if (message.startsWith("start")) {
try {
restartServer(0, 0, 0);
} catch (Exception e) {
e.printStackTrace();
}
return "start server\r\ntelnet>";
} else if (message.startsWith("shutdown")) {
System.exit(0);
return "start server\r\ntelnet>";
} else if (message.startsWith("channels")) {
return "server.getExchangeChannels():" + server.getExchangeChannels().size() + "\r\ntelnet>";
} else if (message.startsWith("restart ")) {
// r times [sleep] r 10 or r 10 100
String[] args = message.split(" ");
int times = Integer.parseInt(args[1]);
int alive = args.length > 2 ? Integer.parseInt(args[2]) : 0;
int sleep = args.length > 3 ? Integer.parseInt(args[3]) : 100;
try {
restartServer(times, alive, sleep);
} catch (Exception e) {
e.printStackTrace();
}
return "restart server,times:" + times + " stop alive time: " + alive + ",sleep time: " + sleep + " usage:r times [alive] [sleep] \r\ntelnet>";
} else {
return "echo: " + message + "\r\ntelnet> ";
}
}
});
return telnetserver;
}
use of com.alibaba.dubbo.remoting.exchange.ExchangeServer in project dubbo by alibaba.
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 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);
}
Aggregations