Java Code Examples for com.alibaba.dubbo.remoting.Channel#setAttribute()
The following examples show how to use
com.alibaba.dubbo.remoting.Channel#setAttribute() .
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 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 2
Source File: DeprecatedTelnetCodec.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 3
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 4
Source File: CallbackServiceCodec.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
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); } }
Example 5
Source File: HeartBeatExchangeHandler.java From dubbox with Apache License 2.0 | 5 votes |
@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 ); } }
Example 6
Source File: CallbackServiceCodec.java From dubbox-hystrix 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 7
Source File: ChangeTelnetHandler.java From dubbo3 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 8
Source File: TraceFilter.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
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); }
Example 9
Source File: CallbackServiceCodec.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
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); } }
Example 10
Source File: CallbackServiceCodec.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
private static void increaseInstanceCount(Channel channel, String countkey) { try { //ignore concurrent 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 11
Source File: TraceFilter.java From dubbox with Apache License 2.0 | 5 votes |
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); }
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: HeaderExchangeHandler.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Override public void received(Channel channel, Object message) throws RemotingException { channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis()); // 查询channel 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); // 消息发送com.alibaba.dubbo.remoting.transport.AbstractPeer.send() 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); } }
Example 14
Source File: HeaderExchangeHandler.java From dubbox-hystrix with Apache License 2.0 | 5 votes |
public void connected(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.connected(exchangeChannel); } finally { HeaderExchangeChannel.removeChannelIfDisconnected(channel); } }
Example 15
Source File: HeaderExchangeHandler.java From dubbox with Apache License 2.0 | 5 votes |
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); } }
Example 16
Source File: HeaderExchangeHandler.java From dubbo3 with Apache License 2.0 | 4 votes |
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); } }
Example 17
Source File: HeartbeatHandler.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
private void setReadTimestamp(Channel channel) { channel.setAttribute(KEY_READ_TIMESTAMP, System.currentTimeMillis()); }
Example 18
Source File: HeartbeatHandler.java From dubbox with Apache License 2.0 | 4 votes |
private void setWriteTimestamp(Channel channel) { channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis()); }
Example 19
Source File: HeartbeatHandler.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
private void setWriteTimestamp(Channel channel) { channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis()); }
Example 20
Source File: HeartbeatHandler.java From dubbo3 with Apache License 2.0 | 4 votes |
private void setWriteTimestamp(Channel channel) { channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis()); }