Java Code Examples for com.alibaba.dubbo.remoting.exchange.Response#setEvent()

The following examples show how to use com.alibaba.dubbo.remoting.exchange.Response#setEvent() . 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: HeartbeatHandler.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
    public void received(Channel channel, Object message) throws RemotingException {
        setReadTimestamp(channel);
//        是否是心跳检测时间
        if (isHeartbeatRequest(message)) {
            Request req = (Request) message;
            if (req.isTwoWay()) {
                Response res = new Response(req.getId(), req.getVersion());
                res.setEvent(Response.HEARTBEAT_EVENT);
//                发送心跳检测请求
                channel.send(res);
                if (logger.isInfoEnabled()) {
//                    获取心跳检测时间 heartbeat属性值
                    int heartbeat = channel.getUrl().getParameter(Constants.HEARTBEAT_KEY, 0);
                    if (logger.isDebugEnabled()) {
                        logger.debug("Received heartbeat from remote channel " + channel.getRemoteAddress()
                                + ", cause: The channel has no data-transmission exceeds a heartbeat period"
                                + (heartbeat > 0 ? ": " + heartbeat + "ms" : ""));
                    }
                }
            }
            return;
        }
//        是否是心跳检测的响应信息
        if (isHeartbeatResponse(message)) {
            if (logger.isDebugEnabled()) {
                logger.debug("Receive heartbeat response in thread " + Thread.currentThread().getName());
            }
            return;
        }
//        =》com.alibaba.dubbo.remoting.transport.dispatcher.all.AllChannelHandler.received()
        handler.received(channel, message);
    }
 
Example 2
Source File: HeartBeatExchangeHandler.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@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 3
Source File: HeartbeatHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void received(Channel channel, Object message) throws RemotingException {
    setReadTimestamp(channel);
    if (isHeartbeatRequest(message)) {
        Request req = (Request) message;
        if (req.isTwoWay()) {
            Response res = new Response(req.getId(), req.getVersion());
            res.setEvent(Response.HEARTBEAT_EVENT);
            channel.send(res);
            if (logger.isInfoEnabled()) {
                int heartbeat = channel.getUrl().getParameter(Constants.HEARTBEAT_KEY, 0);
                if(logger.isDebugEnabled()) {
                    logger.debug("Received heartbeat from remote channel " + channel.getRemoteAddress()
                                    + ", cause: The channel has no data-transmission exceeds a heartbeat period"
                                    + (heartbeat > 0 ? ": " + heartbeat + "ms" : ""));
                }
         }
        }
        return;
    }
    if (isHeartbeatResponse(message)) {
        if (logger.isDebugEnabled()) {
        	logger.debug(
                new StringBuilder(32)
                    .append("Receive heartbeat response in thread ")
                    .append(Thread.currentThread().getName())
                    .toString());
        }
        return;
    }
    handler.received(channel, message);
}
 
Example 4
Source File: HeartBeatExchangeHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: HeartbeatHandler.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public void received(Channel channel, Object message) throws RemotingException {
    setReadTimestamp(channel);
    if (isHeartbeatRequest(message)) {
        Request req = (Request) message;
        if (req.isTwoWay()) {
            Response res = new Response(req.getId(), req.getVersion());
            res.setEvent(Response.HEARTBEAT_EVENT);
            channel.send(res);
            if (logger.isInfoEnabled()) {
                int heartbeat = channel.getUrl().getParameter(Constants.HEARTBEAT_KEY, 0);
                if(logger.isDebugEnabled()) {
                    logger.debug("Received heartbeat from remote channel " + channel.getRemoteAddress()
                                    + ", cause: The channel has no data-transmission exceeds a heartbeat period"
                                    + (heartbeat > 0 ? ": " + heartbeat + "ms" : ""));
                }
         }
        }
        return;
    }
    if (isHeartbeatResponse(message)) {
        if (logger.isDebugEnabled()) {
        	logger.debug(
                new StringBuilder(32)
                    .append("Receive heartbeat response in thread ")
                    .append(Thread.currentThread().getName())
                    .toString());
        }
        return;
    }
    handler.received(channel, message);
}
 
Example 6
Source File: HeartBeatExchangeHandler.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@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 7
Source File: HeartbeatHandler.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public void received(Channel channel, Object message) throws RemotingException {
    setReadTimestamp(channel);
    if (isHeartbeatRequest(message)) {
        Request req = (Request) message;
        if (req.isTwoWay()) {
            Response res = new Response(req.getId(), req.getVersion());
            res.setEvent(Response.HEARTBEAT_EVENT);
            channel.send(res);
            if (logger.isInfoEnabled()) {
                int heartbeat = channel.getUrl().getParameter(Constants.HEARTBEAT_KEY, 0);
                if(logger.isDebugEnabled()) {
                    logger.debug("Received heartbeat from remote channel " + channel.getRemoteAddress()
                                    + ", cause: The channel has no data-transmission exceeds a heartbeat period"
                                    + (heartbeat > 0 ? ": " + heartbeat + "ms" : ""));
                }
         }
        }
        return;
    }
    if (isHeartbeatResponse(message)) {
        if (logger.isDebugEnabled()) {
        	logger.debug(
                new StringBuilder(32)
                    .append("Receive heartbeat response in thread ")
                    .append(Thread.currentThread().getName())
                    .toString());
        }
        return;
    }
    handler.received(channel, message);
}
 
Example 8
Source File: HeartbeatHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void received(Channel channel, Object message) throws RemotingException {
    setReadTimestamp(channel);
    if (isHeartbeatRequest(message)) {
        Request req = (Request) message;
        if (req.isTwoWay()) {
            Response res = new Response(req.getId(), req.getVersion());
            res.setEvent(Response.HEARTBEAT_EVENT);
            channel.send(res);
            if (logger.isInfoEnabled()) {
                int heartbeat = channel.getUrl().getParameter(Constants.HEARTBEAT_KEY, 0);
                if(logger.isDebugEnabled()) {
                    logger.debug("Received heartbeat from remote channel " + channel.getRemoteAddress()
                                    + ", cause: The channel has no data-transmission exceeds a heartbeat period"
                                    + (heartbeat > 0 ? ": " + heartbeat + "ms" : ""));
                }
         }
        }
        return;
    }
    if (isHeartbeatResponse(message)) {
        if (logger.isDebugEnabled()) {
        	logger.debug(
                new StringBuilder(32)
                    .append("Receive heartbeat response in thread ")
                    .append(Thread.currentThread().getName())
                    .toString());
        }
        return;
    }
    handler.received(channel, message);
}
 
Example 9
Source File: HeartBeatExchangeHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: HeartbeatHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void received(Channel channel, Object message) throws RemotingException {
    setReadTimestamp(channel);
    if (isHeartbeatRequest(message)) {
        Request req = (Request) message;
        if (req.isTwoWay()) {
            Response res = new Response(req.getId(), req.getVersion());
            res.setEvent(Response.HEARTBEAT_EVENT);
            channel.send(res);
            if (logger.isInfoEnabled()) {
                int heartbeat = channel.getUrl().getParameter(Constants.HEARTBEAT_KEY, 0);
                if(logger.isDebugEnabled()) {
                    logger.debug("Received heartbeat from remote channel " + channel.getRemoteAddress()
                                    + ", cause: The channel has no data-transmission exceeds a heartbeat period"
                                    + (heartbeat > 0 ? ": " + heartbeat + "ms" : ""));
                }
         }
        }
        return;
    }
    if (isHeartbeatResponse(message)) {
        if (logger.isDebugEnabled()) {
        	logger.debug(
                new StringBuilder(32)
                    .append("Receive heartbeat response in thread ")
                    .append(Thread.currentThread().getName())
                    .toString());
        }
        return;
    }
    handler.received(channel, message);
}
 
Example 11
Source File: HeartBeatExchangeHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@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 );
    }
}