use of org.apache.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.
the class HeaderExchangeHandler method connected.
@Override
public void connected(Channel channel) throws RemotingException {
ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
handler.connected(exchangeChannel);
}
use of org.apache.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.
the class HeaderExchangeHandler method disconnected.
@Override
public void disconnected(Channel channel) throws RemotingException {
ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
try {
handler.disconnected(exchangeChannel);
} finally {
DefaultFuture.closeChannel(channel);
HeaderExchangeChannel.removeChannel(channel);
}
}
use of org.apache.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.
the class HeaderExchangeHandler method sent.
@Override
public void sent(Channel channel, Object message) throws RemotingException {
Throwable exception = null;
try {
ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
handler.sent(exchangeChannel, message);
} catch (Throwable t) {
exception = t;
HeaderExchangeChannel.removeChannelIfDisconnected(channel);
}
if (message instanceof Request) {
Request request = (Request) message;
DefaultFuture.sent(channel, request);
}
if (exception != null) {
if (exception instanceof RuntimeException) {
throw (RuntimeException) exception;
} else if (exception instanceof RemotingException) {
throw (RemotingException) exception;
} else {
throw new RemotingException(channel.getLocalAddress(), channel.getRemoteAddress(), exception.getMessage(), exception);
}
}
}
use of org.apache.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.
the class PortTelnetHandler method telnet.
@Override
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 (ProtocolServer server : DubboProtocol.getDubboProtocol().getServers()) {
if (buf.length() > 0) {
buf.append("\r\n");
}
if (detail) {
buf.append(server.getUrl().getProtocol()).append("://").append(server.getUrl().getAddress());
} else {
buf.append(server.getUrl().getPort());
}
}
} else {
int p = Integer.parseInt(port);
ProtocolServer protocolServer = null;
for (ProtocolServer s : DubboProtocol.getDubboProtocol().getServers()) {
if (p == s.getUrl().getPort()) {
protocolServer = s;
break;
}
}
if (protocolServer != null) {
ExchangeServer server = (ExchangeServer) protocolServer.getRemotingServer();
Collection<ExchangeChannel> channels = server.getExchangeChannels();
for (ExchangeChannel c : channels) {
if (buf.length() > 0) {
buf.append("\r\n");
}
if (detail) {
buf.append(c.getRemoteAddress()).append(" -> ").append(c.getLocalAddress());
} else {
buf.append(c.getRemoteAddress());
}
}
} else {
buf.append("No such port ").append(port);
}
}
return buf.toString();
}
use of org.apache.dubbo.remoting.exchange.ExchangeChannel in project dubbo by alibaba.
the class NettyClientTest method testClientClose.
@Test
public void testClientClose() throws Exception {
List<ExchangeChannel> clients = new ArrayList<ExchangeChannel>(100);
for (int i = 0; i < 100; i++) {
ExchangeChannel client = Exchangers.connect(URL.valueOf("exchange://localhost:" + port + "?client=netty3"));
Thread.sleep(5);
clients.add(client);
}
for (ExchangeChannel client : clients) {
client.close();
}
Thread.sleep(1000);
}
Aggregations