本文整理汇总了Java中com.alibaba.dubbo.remoting.Channel.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.setAttribute方法的具体用法?Java Channel.setAttribute怎么用?Java Channel.setAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.dubbo.remoting.Channel
的用法示例。
在下文中一共展示了Channel.setAttribute方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: received
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
@Override
public void received( Channel channel, Object message ) throws RemotingException {
if ( message instanceof Request ) {
Request req = ( Request ) message;
if ( req.isHeartbeat() ) {
heartBeatCounter.incrementAndGet();
channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
Response res = new Response( req.getId(), req.getVersion() );
res.setEvent( req.getData() == null ? null : req.getData().toString() );
channel.send( res );
}
} else {
super.received( channel, message );
}
}
示例4: disconnected
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
public void disconnected(Channel channel) throws RemotingException {
channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
try {
handler.disconnected(exchangeChannel);
} finally {
HeaderExchangeChannel.removeChannelIfDisconnected(channel);
}
}
示例5: sent
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
public void sent(Channel channel, Object message) throws RemotingException {
Throwable exception = null;
try {
channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
try {
handler.sent(exchangeChannel, message);
} finally {
HeaderExchangeChannel.removeChannelIfDisconnected(channel);
}
} catch (Throwable t) {
exception = t;
}
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);
}
}
}
示例6: received
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
public void received(Channel channel, Object message) throws RemotingException {
channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis());
ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
try {
if (message instanceof Request) {
// handle request.
Request request = (Request) message;
if (request.isEvent()) {
handlerEvent(channel, request);
} else {
if (request.isTwoWay()) {
Response response = handleRequest(exchangeChannel, request);
channel.send(response);
} else {
handler.received(exchangeChannel, request.getData());
}
}
} else if (message instanceof Response) {
handleResponse(channel, (Response) message);
} else if (message instanceof String) {
if (isClientSide(channel)) {
Exception e = new Exception("Dubbo client can not supported string message: " + message + " in channel: " + channel + ", url: " + channel.getUrl());
logger.error(e.getMessage(), e);
} else {
String echo = handler.telnet(channel, (String) message);
if (echo != null && echo.length() > 0) {
channel.send(echo);
}
}
} else {
handler.received(exchangeChannel, message);
}
} finally {
HeaderExchangeChannel.removeChannelIfDisconnected(channel);
}
}
示例7: 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);
}
}
示例8: 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();
}
示例9: 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);
}
}
示例10: 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;
}
示例11: addTracer
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
public static void addTracer(Class<?> type, String method, Channel channel, int max) {
channel.setAttribute(TRACE_MAX, max);
channel.setAttribute(TRACE_COUNT, new AtomicInteger());
String key = method != null && method.length() > 0 ? type.getName() + "." + method : type.getName();
Set<Channel> channels = tracers.get(key);
if (channels == null) {
tracers.putIfAbsent(key, new ConcurrentHashSet<Channel>());
channels = tracers.get(key);
}
channels.add(channel);
}
示例12: setWriteTimestamp
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
private void setWriteTimestamp(Channel channel) {
channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
}
示例13: handlerEvent
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
void handlerEvent(Channel channel, Request req) throws RemotingException {
if (req.getData() != null && req.getData().equals(Request.READONLY_EVENT)) {
channel.setAttribute(Constants.CHANNEL_ATTRIBUTE_READONLY_KEY, Boolean.TRUE);
}
}
示例14: setAttribute
import com.alibaba.dubbo.remoting.Channel; //导入方法依赖的package包/类
public void setAttribute(String key, Object value) {
Channel channel = getChannel();
if (channel == null)
return;
channel.setAttribute(key, value);
}