public RemotingException(Channel channel, String message, Throwable cause) { this(channel == null ? null : channel.getLocalAddress(), channel == null ? null : channel.getRemoteAddress(), message, cause); }
@Override public String telnet(Channel channel, String message) { channel.close(); return null; }
static HeaderExchangeChannel getOrAddChannel(Channel ch) { if (ch == null) { return null; } HeaderExchangeChannel ret = (HeaderExchangeChannel) ch.getAttribute(CHANNEL_KEY); if (ret == null) { ret = new HeaderExchangeChannel(ch); if (ch.isConnected()) { ch.setAttribute(CHANNEL_KEY, ret); } } return ret; }
private boolean isInvokedSelectCommand(Channel channel) { if (channel.hasAttribute(SelectTelnetHandler.SELECT_KEY)) { channel.removeAttribute(SelectTelnetHandler.SELECT_KEY); return true; } return false; } }
static void removeChannelIfDisconnected(Channel ch) { if (ch != null && !ch.isConnected()) { ch.removeAttribute(CHANNEL_KEY); } }
private boolean isClientSide(Channel channel) { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); return url.getPort() == address.getPort() && NetUtils.filterLocalHost(channel.getUrl().getIp()) .equals(NetUtils.filterLocalHost(address.getAddress().getHostAddress())); }
URL exportUrl = new URL(DubboProtocol.NAME, channel.getLocalAddress().getAddress().getHostAddress(), channel.getLocalAddress().getPort(), clazz.getName() + "." + instid, tmpMap); if (export) { if (!channel.hasAttribute(cacheKey)) { if (!isInstancesOverLimit(channel, url, clazz.getName(), instid, false)) { Invoker<?> invoker = proxyFactory.getInvoker(inst, clazz, exportUrl); channel.setAttribute(cacheKey, exporter); logger.info("Export a callback service :" + exportUrl + ", on " + channel + ", url is: " + url); increaseInstanceCount(channel, countKey); if (channel.hasAttribute(cacheKey)) { Exporter<?> exporter = (Exporter<?>) channel.getAttribute(cacheKey); exporter.unexport(); channel.removeAttribute(cacheKey); decreaseInstanceCount(channel, countKey);
@Override public Collection<Channel> getChannels() { Collection<Channel> chs = new HashSet<Channel>(); for (Channel channel : this.channels.values()) { if (channel.isConnected()) { chs.add(channel); } else { channels.remove(NetUtils.toAddressString(channel.getRemoteAddress())); } } return chs; }
@Override public void send(Object message, boolean sent) throws RemotingException { Collection<Channel> channels = getChannels(); for (Channel channel : channels) { if (channel.isConnected()) { channel.send(message, sent); } } }
@Override public void connected(Channel ch) throws RemotingException { channels.put(NetUtils.toAddressString(ch.getRemoteAddress()), ch); super.connected(ch); }
@Override public void connected(Channel ch) throws RemotingException { // If the server has entered the shutdown process, reject any new connection if (this.isClosing() || this.isClosed()) { logger.warn("Close new channel " + ch + ", cause: server is closing or has been closed. For example, receive a new connect request while in shutdown process."); ch.close(); return; } Collection<Channel> channels = getChannels(); if (accepts > 0 && channels.size() > accepts) { logger.error("Close channel " + ch + ", cause: The server " + ch.getLocalAddress() + " connections greater than max config " + accepts); ch.close(); return; } super.connected(ch); }
private static void decreaseInstanceCount(Channel channel, String countkey) { try { Integer count = (Integer) channel.getAttribute(countkey); if (count == null || count <= 0) { return; } else { count--; } channel.setAttribute(countkey, count); } catch (Exception e) { logger.error(e.getMessage(), e); } }
@Override public boolean isClosed() { return channel.isClosed(); }
@Override public ExchangeHandler getExchangeHandler() { return (ExchangeHandler) channel.getChannelHandler(); }
private DefaultFuture(Channel channel, Request request, int timeout) { this.channel = channel; this.request = request; this.id = request.getId(); this.timeout = timeout > 0 ? timeout : channel.getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); // put into waiting map. FUTURES.put(id, this); CHANNELS.put(id, channel); }
@Override public InetSocketAddress getLocalAddress() { return channel.getLocalAddress(); }
@Override public boolean hasAttribute(String key) { return channel.hasAttribute(key); }
@Override public void removeAttribute(String key) { channel.removeAttribute(key); }
@Override public Object getAttribute(String key) { return channel.getAttribute(key); }
@Override public boolean isConnected() { Channel channel = getChannel(); if (channel == null) { return false; } return channel.isConnected(); }