Java Code Examples for com.alibaba.dubbo.remoting.Channel#getAttribute()
The following examples show how to use
com.alibaba.dubbo.remoting.Channel#getAttribute() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeprecatedTelnetCodec.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
protected boolean isClientSide(Channel channel) { String side = (String) channel.getAttribute(Constants.SIDE_KEY); if ("client".equals(side)) { return true; } else if ("server".equals(side)) { return false; } else { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); boolean client = url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()).equals( NetUtils.filterLocalHost(address.getAddress() .getHostAddress())); channel.setAttribute(Constants.SIDE_KEY, client ? "client" : "server"); return client; } }
Example 2
Source File: DeprecatedTelnetCodec.java From dubbox with Apache License 2.0 | 6 votes |
protected boolean isClientSide(Channel channel) { String side = (String) channel.getAttribute(Constants.SIDE_KEY); if ("client".equals(side)) { return true; } else if ("server".equals(side)) { return false; } else { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); boolean client = url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()).equals( NetUtils.filterLocalHost(address.getAddress() .getHostAddress())); channel.setAttribute(Constants.SIDE_KEY, client ? "client" : "server"); return client; } }
Example 3
Source File: DeprecatedTelnetCodec.java From dubbo3 with Apache License 2.0 | 6 votes |
protected boolean isClientSide(Channel channel) { String side = (String) channel.getAttribute(Constants.SIDE_KEY); if ("client".equals(side)) { return true; } else if ("server".equals(side)) { return false; } else { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); boolean client = url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()).equals( NetUtils.filterLocalHost(address.getAddress() .getHostAddress())); channel.setAttribute(Constants.SIDE_KEY, client ? "client" : "server"); return client; } }
Example 4
Source File: AbstractCodec.java From dubbox-hystrix with Apache License 2.0 | 6 votes |
protected boolean isClientSide(Channel channel) { String side = (String) channel.getAttribute(Constants.SIDE_KEY); if ("client".equals(side)) { return true; } else if ("server".equals(side)) { return false; } else { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); boolean client = url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()).equals( NetUtils.filterLocalHost(address.getAddress() .getHostAddress())); channel.setAttribute(Constants.SIDE_KEY, client ? "client" : "server"); return client; } }
Example 5
Source File: AbstractCodec.java From dubbox with Apache License 2.0 | 6 votes |
protected boolean isClientSide(Channel channel) { String side = (String) channel.getAttribute(Constants.SIDE_KEY); if ("client".equals(side)) { return true; } else if ("server".equals(side)) { return false; } else { InetSocketAddress address = channel.getRemoteAddress(); URL url = channel.getUrl(); boolean client = url.getPort() == address.getPort() && NetUtils.filterLocalHost(url.getIp()).equals( NetUtils.filterLocalHost(address.getAddress() .getHostAddress())); channel.setAttribute(Constants.SIDE_KEY, client ? "client" : "server"); return client; } }
Example 6
Source File: AbstractClient.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Override public Object getAttribute(String key) { Channel channel = getChannel(); if (channel == null) return null; return channel.getAttribute(key); }
Example 7
Source File: CurrentTelnetHandler.java From dubbox with Apache License 2.0 | 5 votes |
public String telnet(Channel channel, String message) { if (message.length() > 0) { return "Unsupported parameter " + message + " for pwd."; } String service = (String) channel.getAttribute(ChangeTelnetHandler.SERVICE_KEY); StringBuilder buf = new StringBuilder(); if (service == null || service.length() == 0) { buf.append("/"); } else { buf.append(service); } return buf.toString(); }
Example 8
Source File: CallbackServiceCodec.java From dubbox with Apache License 2.0 | 5 votes |
private static boolean isInstancesOverLimit(Channel channel, URL url ,String interfaceClass, int instid, boolean isServer){ Integer count = (Integer)channel.getAttribute(isServer ? getServerSideCountKey(channel,interfaceClass) : getClientSideCountKey(interfaceClass)); int limit = url.getParameter(Constants.CALLBACK_INSTANCES_LIMIT_KEY, Constants.DEFAULT_CALLBACK_INSTANCES); if (count != null && count >= limit){ //client side error throw new IllegalStateException("interface " + interfaceClass +" `s callback instances num exceed providers limit :"+ limit +" ,current num: "+(count+1)+". The new callback service will not work !!! you can cancle the callback service which exported before. channel :"+ channel); }else { return false; } }
Example 9
Source File: CurrentTelnetHandler.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public String telnet(Channel channel, String message) { if (message.length() > 0) { return "Unsupported parameter " + message + " for pwd."; } String service = (String) channel.getAttribute(ChangeTelnetHandler.SERVICE_KEY); StringBuilder buf = new StringBuilder(); if (service == null || service.length() == 0) { buf.append("/"); } else { buf.append(service); } return buf.toString(); }
Example 10
Source File: CurrentTelnetHandler.java From dubbox with Apache License 2.0 | 5 votes |
public String telnet(Channel channel, String message) { if (message.length() > 0) { return "Unsupported parameter " + message + " for pwd."; } String service = (String) channel.getAttribute(ChangeTelnetHandler.SERVICE_KEY); StringBuilder buf = new StringBuilder(); if (service == null || service.length() == 0) { buf.append("/"); } else { buf.append(service); } return buf.toString(); }
Example 11
Source File: HeaderExchangeChannel.java From dubbo3 with Apache License 2.0 | 5 votes |
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; }
Example 12
Source File: CallbackServiceCodec.java From dubbox with Apache License 2.0 | 5 votes |
private static void increaseInstanceCount(Channel channel, String countkey){ try{ //ignore cuncurrent problem? Integer count = (Integer)channel.getAttribute(countkey); if (count == null ){ count = 1; }else { count ++ ; } channel.setAttribute(countkey, count); }catch (Exception e) { logger.error(e.getMessage(), e); } }
Example 13
Source File: CallbackServiceCodec.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
private static boolean isInstancesOverLimit(Channel channel, URL url, String interfaceClass, int instid, boolean isServer) { Integer count = (Integer) channel.getAttribute(isServer ? getServerSideCountKey(channel, interfaceClass) : getClientSideCountKey(interfaceClass)); int limit = url.getParameter(Constants.CALLBACK_INSTANCES_LIMIT_KEY, Constants.DEFAULT_CALLBACK_INSTANCES); if (count != null && count >= limit) { //client side error throw new IllegalStateException("interface " + interfaceClass + " `s callback instances num exceed providers limit :" + limit + " ,current num: " + (count + 1) + ". The new callback service will not work !!! you can cancle the callback service which exported before. channel :" + channel); } else { return false; } }
Example 14
Source File: HeaderExchangeChannel.java From dubbox with Apache License 2.0 | 5 votes |
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; }
Example 15
Source File: ChangeTelnetHandler.java From dubbox with Apache License 2.0 | 5 votes |
public String telnet(Channel channel, String message) { if (message == null || message.length() == 0) { return "Please input service name, eg: \r\ncd XxxService\r\ncd com.xxx.XxxService"; } StringBuilder buf = new StringBuilder(); if (message.equals("/") || message.equals("..")) { String service = (String) channel.getAttribute(SERVICE_KEY); channel.removeAttribute(SERVICE_KEY); buf.append("Cancelled default service " + service + "."); } else { boolean found = false; for (Exporter<?> exporter : DubboProtocol.getDubboProtocol().getExporters()) { if (message.equals(exporter.getInvoker().getInterface().getSimpleName()) || message.equals(exporter.getInvoker().getInterface().getName()) || message.equals(exporter.getInvoker().getUrl().getPath())) { found = true; break; } } if (found) { channel.setAttribute(SERVICE_KEY, message); buf.append("Used the " + message + " as default.\r\nYou can cancel default service by command: cd /"); } else { buf.append("No such service " + message); } } return buf.toString(); }
Example 16
Source File: AbstractClient.java From dubbox with Apache License 2.0 | 4 votes |
public Object getAttribute(String key) { Channel channel = getChannel(); if (channel == null) return null; return channel.getAttribute(key); }
Example 17
Source File: TraceTelnetHandler.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
public String telnet(Channel channel, String message) { String service = (String) channel.getAttribute(ChangeTelnetHandler.SERVICE_KEY); if ((service == null || service.length() == 0) && (message == null || message.length() == 0)) { return "Please input service name, eg: \r\ntrace XxxService\r\ntrace XxxService xxxMethod\r\ntrace XxxService xxxMethod 10\r\nor \"cd XxxService\" firstly."; } String[] parts = message.split("\\s+"); String method; String times; if (service == null || service.length() == 0) { service = parts.length > 0 ? parts[0] : null; method = parts.length > 1 ? parts[1] : null; } else { method = parts.length > 0 ? parts[0] : null; } if (StringUtils.isInteger(method)) { times = method; method = null; } else { times = parts.length > 2 ? parts[2] : "1"; } if (! StringUtils.isInteger(times)) { return "Illegal times " + times + ", must be integer."; } Invoker<?> invoker = null; for (Exporter<?> exporter : DubboProtocol.getDubboProtocol().getExporters()) { if (service.equals(exporter.getInvoker().getInterface().getSimpleName()) || service.equals(exporter.getInvoker().getInterface().getName()) || service.equals(exporter.getInvoker().getUrl().getPath())) { invoker = exporter.getInvoker(); break; } } if (invoker != null) { if (method != null && method.length() > 0) { boolean found = false; for (Method m : invoker.getInterface().getMethods()) { if (m.getName().equals(method)) { found = true; break; } } if (! found) { return "No such method " + method + " in class " + invoker.getInterface().getName(); } } TraceFilter.addTracer(invoker.getInterface(), method, channel, Integer.parseInt(times)); } else { return "No such service " + service; } return null; }
Example 18
Source File: AbstractClient.java From dubbox with Apache License 2.0 | 4 votes |
public Object getAttribute(String key) { Channel channel = getChannel(); if (channel == null) return null; return channel.getAttribute(key); }
Example 19
Source File: TraceTelnetHandler.java From dubbox with Apache License 2.0 | 4 votes |
public String telnet(Channel channel, String message) { String service = (String) channel.getAttribute(ChangeTelnetHandler.SERVICE_KEY); if ((service == null || service.length() == 0) && (message == null || message.length() == 0)) { return "Please input service name, eg: \r\ntrace XxxService\r\ntrace XxxService xxxMethod\r\ntrace XxxService xxxMethod 10\r\nor \"cd XxxService\" firstly."; } String[] parts = message.split("\\s+"); String method; String times; if (service == null || service.length() == 0) { service = parts.length > 0 ? parts[0] : null; method = parts.length > 1 ? parts[1] : null; } else { method = parts.length > 0 ? parts[0] : null; } if (StringUtils.isInteger(method)) { times = method; method = null; } else { times = parts.length > 2 ? parts[2] : "1"; } if (! StringUtils.isInteger(times)) { return "Illegal times " + times + ", must be integer."; } Invoker<?> invoker = null; for (Exporter<?> exporter : DubboProtocol.getDubboProtocol().getExporters()) { if (service.equals(exporter.getInvoker().getInterface().getSimpleName()) || service.equals(exporter.getInvoker().getInterface().getName()) || service.equals(exporter.getInvoker().getUrl().getPath())) { invoker = exporter.getInvoker(); break; } } if (invoker != null) { if (method != null && method.length() > 0) { boolean found = false; for (Method m : invoker.getInterface().getMethods()) { if (m.getName().equals(method)) { found = true; break; } } if (! found) { return "No such method " + method + " in class " + invoker.getInterface().getName(); } } TraceFilter.addTracer(invoker.getInterface(), method, channel, Integer.parseInt(times)); } else { return "No such service " + service; } return null; }
Example 20
Source File: TraceTelnetHandler.java From dubbox with Apache License 2.0 | 4 votes |
public String telnet(Channel channel, String message) { String service = (String) channel.getAttribute(ChangeTelnetHandler.SERVICE_KEY); if ((service == null || service.length() == 0) && (message == null || message.length() == 0)) { return "Please input service name, eg: \r\ntrace XxxService\r\ntrace XxxService xxxMethod\r\ntrace XxxService xxxMethod 10\r\nor \"cd XxxService\" firstly."; } String[] parts = message.split("\\s+"); String method; String times; if (service == null || service.length() == 0) { service = parts.length > 0 ? parts[0] : null; method = parts.length > 1 ? parts[1] : null; } else { method = parts.length > 0 ? parts[0] : null; } if (StringUtils.isInteger(method)) { times = method; method = null; } else { times = parts.length > 2 ? parts[2] : "1"; } if (! StringUtils.isInteger(times)) { return "Illegal times " + times + ", must be integer."; } Invoker<?> invoker = null; for (Exporter<?> exporter : DubboProtocol.getDubboProtocol().getExporters()) { if (service.equals(exporter.getInvoker().getInterface().getSimpleName()) || service.equals(exporter.getInvoker().getInterface().getName()) || service.equals(exporter.getInvoker().getUrl().getPath())) { invoker = exporter.getInvoker(); break; } } if (invoker != null) { if (method != null && method.length() > 0) { boolean found = false; for (Method m : invoker.getInterface().getMethods()) { if (m.getName().equals(method)) { found = true; break; } } if (! found) { return "No such method " + method + " in class " + invoker.getInterface().getName(); } } TraceFilter.addTracer(invoker.getInterface(), method, channel, Integer.parseInt(times)); } else { return "No such service " + service; } return null; }