Java Code Examples for com.alibaba.rocketmq.remoting.common.RemotingUtil#closeChannel()

The following examples show how to use com.alibaba.rocketmq.remoting.common.RemotingUtil#closeChannel() . 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: NettyEncoder.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void encode(ChannelHandlerContext ctx, RemotingCommand remotingCommand, ByteBuf out)
        throws Exception {
    try {
        ByteBuffer header = remotingCommand.encodeHeader();
        out.writeBytes(header);
        byte[] body = remotingCommand.getBody();
        if (body != null) {
            out.writeBytes(body);
        }
    } catch (Exception e) {
        log.error("encode exception, " + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), e);
        if (remotingCommand != null) {
            log.error(remotingCommand.toString());
        }
        RemotingUtil.closeChannel(ctx.channel());
    }
}
 
Example 2
Source File: NettyRemotingServer.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent evnet = (IdleStateEvent) evt;
        if (evnet.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress);
            RemotingUtil.closeChannel(ctx.channel());
            if (NettyRemotingServer.this.channelEventListener != null) {
                NettyRemotingServer.this
                    .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress.toString(), ctx.channel()));
            }
        }
    }

    ctx.fireUserEventTriggered(evt);
}
 
Example 3
Source File: NettyRemotingServer.java    From RocketMQ-Master-analyze with Apache License 2.0 6 votes vote down vote up
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent evnet = (IdleStateEvent) evt;
        if (evnet.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress);
            RemotingUtil.closeChannel(ctx.channel());
            if (NettyRemotingServer.this.channelEventListener != null) {
                NettyRemotingServer.this.putNettyEvent(
                    new NettyEvent(NettyEventType.IDLE, remoteAddress.toString(), ctx.channel()));
            }
        }
    }

    ctx.fireUserEventTriggered(evt);
}
 
Example 4
Source File: NettyEncoder.java    From RocketMQ-Master-analyze with Apache License 2.0 6 votes vote down vote up
@Override
public void encode(ChannelHandlerContext ctx, RemotingCommand remotingCommand, ByteBuf out)
        throws Exception {
    try {
        ByteBuffer header = remotingCommand.encodeHeader();
        out.writeBytes(header);
        byte[] body = remotingCommand.getBody();
        if (body != null) {
            out.writeBytes(body);
        }
    }
    catch (Exception e) {
        log.error("encode exception, " + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), e);
        if (remotingCommand != null) {
            log.error(remotingCommand.toString());
        }
        RemotingUtil.closeChannel(ctx.channel());
    }
}
 
Example 5
Source File: NettyEncoder.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Override
public void encode(ChannelHandlerContext ctx, RemotingCommand remotingCommand, ByteBuf out)
        throws Exception {
    try {
        ByteBuffer header = remotingCommand.encodeHeader();
        out.writeBytes(header);
        byte[] body = remotingCommand.getBody();
        if (body != null) {
            out.writeBytes(body);
        }
    } catch (Exception e) {
        log.error("encode exception, " + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), e);
        if (remotingCommand != null) {
            log.error(remotingCommand.toString());
        }
        RemotingUtil.closeChannel(ctx.channel());
    }
}
 
Example 6
Source File: NettyRemotingServer.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent evnet = (IdleStateEvent) evt;
        if (evnet.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress);
            RemotingUtil.closeChannel(ctx.channel());
            if (NettyRemotingServer.this.channelEventListener != null) {
                NettyRemotingServer.this
                        .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress.toString(), ctx.channel()));
            }
        }
    }

    ctx.fireUserEventTriggered(evt);
}
 
Example 7
Source File: ProducerManager.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
/**
 * 扫描出空闲的连接并关闭移除
 */
public void scanNotActiveChannel() {
    try {
        if (this.groupChannelLock.tryLock(LockTimeoutMillis, TimeUnit.MILLISECONDS)) {
            try {
                for (final Map.Entry<String, HashMap<Channel, ClientChannelInfo>> entry : this.groupChannelTable
                    .entrySet()) {
                    final String group = entry.getKey();
                    final HashMap<Channel, ClientChannelInfo> chlMap = entry.getValue();

                    Iterator<Entry<Channel, ClientChannelInfo>> it = chlMap.entrySet().iterator();
                    while (it.hasNext()) {
                        Entry<Channel, ClientChannelInfo> item = it.next();
                        // final Integer id = item.getKey();
                        final ClientChannelInfo info = item.getValue();

                        long diff = System.currentTimeMillis() - info.getLastUpdateTimestamp();
                        if (diff > ChannelExpiredTimeout) {
                            it.remove();
                            log.warn(
                                "SCAN: remove expired channel[{}] from ProducerManager groupChannelTable, "
                                        + "producer group name: {}",
                                RemotingHelper.parseChannelRemoteAddr(info.getChannel()), group);
                            RemotingUtil.closeChannel(info.getChannel());
                        }
                    }
                }
            }
            finally {
                this.groupChannelLock.unlock();
            }
        }
        else {
            log.warn("ProducerManager scanNotActiveChannel lock timeout");
        }
    }
    catch (InterruptedException e) {
        log.error("", e);
    }
}
 
Example 8
Source File: RouteInfoManager.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public void scanNotActiveBroker() {
    Iterator<Entry<String, BrokerLiveInfo>> it = this.brokerLiveTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, BrokerLiveInfo> next = it.next();
        long last = next.getValue().getLastUpdateTimestamp();
        //本地 brokerLiveTable 默认2分钟过期
        if ((last + BrokerChannelExpiredTime) < System.currentTimeMillis()) {
            RemotingUtil.closeChannel(next.getValue().getChannel());
            it.remove();
            log.warn("The broker channel expired, {} {}ms", next.getKey(), BrokerChannelExpiredTime);
            this.onChannelDestroy(next.getKey(), next.getValue().getChannel());
        }
    }
}
 
Example 9
Source File: FilterServerManager.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
/**
 * Filter Server 10s向Broker注册一次,Broker如果发现30s没有注册,则删除它
 */
public void scanNotActiveChannel() {
    // 单位毫秒
    Iterator<Entry<Channel, FilterServerInfo>> it = this.filterServerTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<Channel, FilterServerInfo> next = it.next();
        long timestamp = next.getValue().getLastUpdateTimestamp();
        Channel channel = next.getKey();
        if ((System.currentTimeMillis() - timestamp) > FilterServerMaxIdleTimeMills) {
            log.info("The Filter Server<{}> expired, remove it", next.getKey());
            it.remove();
            RemotingUtil.closeChannel(channel);
        }
    }
}
 
Example 10
Source File: NettyRemotingServer.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
    log.warn("NETTY SERVER PIPELINE: exceptionCaught {}", remoteAddress);
    log.warn("NETTY SERVER PIPELINE: exceptionCaught exception.", cause);

    if (NettyRemotingServer.this.channelEventListener != null) {
        NettyRemotingServer.this.putNettyEvent(
            new NettyEvent(NettyEventType.EXCEPTION, remoteAddress.toString(), ctx.channel()));
    }

    RemotingUtil.closeChannel(ctx.channel());
}
 
Example 11
Source File: RouteInfoManager.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
public void scanNotActiveBroker() {
    Iterator<Entry<String, BrokerLiveInfo>> it = this.brokerLiveTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, BrokerLiveInfo> next = it.next();
        long last = next.getValue().getLastUpdateTimestamp();
        if ((last + BrokerChannelExpiredTime) < System.currentTimeMillis()) {
            RemotingUtil.closeChannel(next.getValue().getChannel());
            it.remove();
            log.warn("The broker channel expired, {} {}ms", next.getKey(), BrokerChannelExpiredTime);
            this.onChannelDestroy(next.getKey(), next.getValue().getChannel());
        }
    }
}
 
Example 12
Source File: ConsumerManager.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void scanNotActiveChannel() {
    Iterator<Entry<String, ConsumerGroupInfo>> it = this.consumerTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, ConsumerGroupInfo> next = it.next();
        String group = next.getKey();
        ConsumerGroupInfo consumerGroupInfo = next.getValue();
        ConcurrentHashMap<Channel, ClientChannelInfo> channelInfoTable =
                consumerGroupInfo.getChannelInfoTable();

        Iterator<Entry<Channel, ClientChannelInfo>> itChannel = channelInfoTable.entrySet().iterator();
        while (itChannel.hasNext()) {
            Entry<Channel, ClientChannelInfo> nextChannel = itChannel.next();
            ClientChannelInfo clientChannelInfo = nextChannel.getValue();
            long diff = System.currentTimeMillis() - clientChannelInfo.getLastUpdateTimestamp();
            if (diff > ChannelExpiredTimeout) {
                log.warn(
                        "SCAN: remove expired channel from ConsumerManager consumerTable. channel={}, consumerGroup={}",
                        RemotingHelper.parseChannelRemoteAddr(clientChannelInfo.getChannel()), group);
                RemotingUtil.closeChannel(clientChannelInfo.getChannel());
                itChannel.remove();
            }
        }

        if (channelInfoTable.isEmpty()) {
            log.warn(
                    "SCAN: remove expired channel from ConsumerManager consumerTable, all clear, consumerGroup={}",
                    group);
            it.remove();
        }
    }
}
 
Example 13
Source File: ProducerManager.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void scanNotActiveChannel() {
    try {
        if (this.groupChannelLock.tryLock(LockTimeoutMillis, TimeUnit.MILLISECONDS)) {
            try {
                for (final Map.Entry<String, HashMap<Channel, ClientChannelInfo>> entry : this.groupChannelTable
                    .entrySet()) {
                    final String group = entry.getKey();
                    final HashMap<Channel, ClientChannelInfo> chlMap = entry.getValue();

                    Iterator<Entry<Channel, ClientChannelInfo>> it = chlMap.entrySet().iterator();
                    while (it.hasNext()) {
                        Entry<Channel, ClientChannelInfo> item = it.next();
                        // final Integer id = item.getKey();
                        final ClientChannelInfo info = item.getValue();

                        long diff = System.currentTimeMillis() - info.getLastUpdateTimestamp();
                        if (diff > ChannelExpiredTimeout) {
                            it.remove();
                            log.warn(
                                "SCAN: remove expired channel[{}] from ProducerManager groupChannelTable, producer group name: {}",
                                RemotingHelper.parseChannelRemoteAddr(info.getChannel()), group);
                            RemotingUtil.closeChannel(info.getChannel());
                        }
                    }
                }
            }
            finally {
                this.groupChannelLock.unlock();
            }
        }
        else {
            log.warn("ProducerManager scanNotActiveChannel lock timeout");
        }
    }
    catch (InterruptedException e) {
        log.error("", e);
    }
}
 
Example 14
Source File: ConsumerManager.java    From RocketMQ-Master-analyze with Apache License 2.0 5 votes vote down vote up
/**
 * 扫描出空闲的连接并关闭移除
 */
public void scanNotActiveChannel() {
    Iterator<Entry<String, ConsumerGroupInfo>> it = this.consumerTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, ConsumerGroupInfo> next = it.next();
        String group = next.getKey();
        ConsumerGroupInfo consumerGroupInfo = next.getValue();
        ConcurrentHashMap<Channel, ClientChannelInfo> channelInfoTable =
                consumerGroupInfo.getChannelInfoTable();

        Iterator<Entry<Channel, ClientChannelInfo>> itChannel = channelInfoTable.entrySet().iterator();
        while (itChannel.hasNext()) {
            Entry<Channel, ClientChannelInfo> nextChannel = itChannel.next();
            ClientChannelInfo clientChannelInfo = nextChannel.getValue();
            long diff = System.currentTimeMillis() - clientChannelInfo.getLastUpdateTimestamp();
            if (diff > ChannelExpiredTimeout) {
                log.warn(
                    "SCAN: remove expired channel from ConsumerManager consumerTable. channel={}, consumerGroup={}",
                    RemotingHelper.parseChannelRemoteAddr(clientChannelInfo.getChannel()), group);
                RemotingUtil.closeChannel(clientChannelInfo.getChannel());
                itChannel.remove();
            }
        }

        if (channelInfoTable.isEmpty()) {
            log.warn(
                "SCAN: remove expired channel from ConsumerManager consumerTable, all clear, consumerGroup={}",
                group);
            it.remove();
        }
    }
}
 
Example 15
Source File: NettyRemotingServer.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
    log.warn("NETTY SERVER PIPELINE: exceptionCaught {}", remoteAddress);
    log.warn("NETTY SERVER PIPELINE: exceptionCaught exception.", cause);

    if (NettyRemotingServer.this.channelEventListener != null) {
        NettyRemotingServer.this.putNettyEvent(new NettyEvent(NettyEventType.EXCEPTION, remoteAddress.toString(), ctx.channel()));
    }

    RemotingUtil.closeChannel(ctx.channel());
}
 
Example 16
Source File: RouteInfoManager.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public void scanNotActiveBroker() {
    Iterator<Entry<String, BrokerLiveInfo>> it = this.brokerLiveTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, BrokerLiveInfo> next = it.next();
        long last = next.getValue().getLastUpdateTimestamp();
        if ((last + BrokerChannelExpiredTime) < System.currentTimeMillis()) {
            RemotingUtil.closeChannel(next.getValue().getChannel());
            it.remove();
            log.warn("The broker channel expired, {} {}ms", next.getKey(), BrokerChannelExpiredTime);
            this.onChannelDestroy(next.getKey(), next.getValue().getChannel());
        }
    }
}
 
Example 17
Source File: ConsumerManager.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public void scanNotActiveChannel() {
    Iterator<Entry<String, ConsumerGroupInfo>> it = this.consumerTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<String, ConsumerGroupInfo> next = it.next();
        String group = next.getKey();
        ConsumerGroupInfo consumerGroupInfo = next.getValue();
        ConcurrentHashMap<Channel, ClientChannelInfo> channelInfoTable =
                consumerGroupInfo.getChannelInfoTable();

        Iterator<Entry<Channel, ClientChannelInfo>> itChannel = channelInfoTable.entrySet().iterator();
        while (itChannel.hasNext()) {
            Entry<Channel, ClientChannelInfo> nextChannel = itChannel.next();
            ClientChannelInfo clientChannelInfo = nextChannel.getValue();
            long diff = System.currentTimeMillis() - clientChannelInfo.getLastUpdateTimestamp();
            if (diff > ChannelExpiredTimeout) {
                log.warn(
                    "SCAN: remove expired channel from ConsumerManager consumerTable. channel={}, consumerGroup={}",
                    RemotingHelper.parseChannelRemoteAddr(clientChannelInfo.getChannel()), group);
                RemotingUtil.closeChannel(clientChannelInfo.getChannel());
                itChannel.remove();
            }
        }

        if (channelInfoTable.isEmpty()) {
            log.warn(
                "SCAN: remove expired channel from ConsumerManager consumerTable, all clear, consumerGroup={}",
                group);
            it.remove();
        }
    }
}
 
Example 18
Source File: ProducerManager.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
public void scanNotActiveChannel() {
    try {
        if (this.groupChannelLock.tryLock(LockTimeoutMillis, TimeUnit.MILLISECONDS)) {
            try {
                for (final Map.Entry<String, HashMap<Channel, ClientChannelInfo>> entry : this.groupChannelTable
                    .entrySet()) {
                    final String group = entry.getKey();
                    final HashMap<Channel, ClientChannelInfo> chlMap = entry.getValue();

                    Iterator<Entry<Channel, ClientChannelInfo>> it = chlMap.entrySet().iterator();
                    while (it.hasNext()) {
                        Entry<Channel, ClientChannelInfo> item = it.next();
                        // final Integer id = item.getKey();
                        final ClientChannelInfo info = item.getValue();

                        long diff = System.currentTimeMillis() - info.getLastUpdateTimestamp();
                        if (diff > ChannelExpiredTimeout) {
                            it.remove();
                            log.warn(
                                "SCAN: remove expired channel[{}] from ProducerManager groupChannelTable, producer group name: {}",
                                RemotingHelper.parseChannelRemoteAddr(info.getChannel()), group);
                            RemotingUtil.closeChannel(info.getChannel());
                        }
                    }
                }
            }
            finally {
                this.groupChannelLock.unlock();
            }
        }
        else {
            log.warn("ProducerManager scanNotActiveChannel lock timeout");
        }
    }
    catch (InterruptedException e) {
        log.error("", e);
    }
}
 
Example 19
Source File: FilterServerManager.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Filter Server register to broker every 10s ,if over 30s,no registration info.,remove it
 */
public void scanNotActiveChannel() {
    Iterator<Entry<Channel, FilterServerInfo>> it = this.filterServerTable.entrySet().iterator();
    while (it.hasNext()) {
        Entry<Channel, FilterServerInfo> next = it.next();
        long timestamp = next.getValue().getLastUpdateTimestamp();
        Channel channel = next.getKey();
        if ((System.currentTimeMillis() - timestamp) > FilterServerMaxIdleTimeMills) {
            log.info("The Filter Server<{}> expired, remove it", next.getKey());
            it.remove();
            RemotingUtil.closeChannel(channel);
        }
    }
}
 
Example 20
Source File: NettyRemotingServer.java    From reading-and-annotate-rocketmq-3.4.6 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
    log.warn("NETTY SERVER PIPELINE: exceptionCaught {}", remoteAddress);
    log.warn("NETTY SERVER PIPELINE: exceptionCaught exception.", cause);

    if (NettyRemotingServer.this.channelEventListener != null) {
        NettyRemotingServer.this.putNettyEvent(new NettyEvent(NettyEventType.EXCEPTION, remoteAddress.toString(), ctx.channel()));
    }

    RemotingUtil.closeChannel(ctx.channel());
}