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;
}
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();
}
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();
}
}
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);
}
Aggregations