本文整理汇总了Java中com.alibaba.dubbo.remoting.Channel.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.getAttribute方法的具体用法?Java Channel.getAttribute怎么用?Java Channel.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.remoting.Channel
的用法示例。
在下文中一共展示了Channel.getAttribute方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isClientSide
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
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;
}
}
示例2: isClientSide
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
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;
}
}
示例3: getOrAddChannel
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
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;
}
示例4: telnet
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
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();
}
示例5: increaseInstanceCount
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
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);
}
}
示例6: telnet
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
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();
}
示例7: isInstancesOverLimit
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
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;
}
}
示例8: decreaseInstanceCount
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
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);
}
}
示例9: telnet
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
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;
}
示例10: getAttribute
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
public Object getAttribute(String key) {
Channel channel = getChannel();
if (channel == null)
return null;
return channel.getAttribute(key);
}