当前位置: 首页>>代码示例>>Java>>正文


Java Channel.isActive方法代码示例

本文整理汇总了Java中io.netty.channel.Channel.isActive方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.isActive方法的具体用法?Java Channel.isActive怎么用?Java Channel.isActive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.channel.Channel的用法示例。


在下文中一共展示了Channel.isActive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: closeChannelGracefully

import io.netty.channel.Channel; //导入方法依赖的package包/类
static void closeChannelGracefully(InetSocketAddress udpSource) {
    Channel socksChannel = removeSocksMapping(udpSource);
    Channel udpChannel = removeUdpMapping(udpSource);
    Channel tcpChannel = removeTcpMapping(udpSource);
    if (tcpChannel.isActive()) {
        tcpChannel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
        log.info("\t          Proxy << Target \tDisconnect");
    }
    if (socksChannel.isActive()) {
        socksChannel.close();
        log.info("\tClient << Proxy           \tDisconnect");
    }
    if (udpChannel.isActive()) {
        udpChannel.close();
    }
}
 
开发者ID:ZhangJiupeng,项目名称:AgentX,代码行数:17,代码来源:XChannelMapper.java

示例2: invokeSync

import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
 * 发起同步调用
 * 其实后面也是异步的
 * 这个同步是指:可以携带结果返回
 * 
 * @param address
 * @param message
 * @param timeout
 * @return 
 * @throws Exception
 */
@SuppressWarnings("rawtypes")
public RemotingProtocol invokeSync(String address, final RemotingProtocol message, int timeout) throws Exception, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException {
    final Channel channel = this.createChannel(address);
    if (channel != null && channel.isActive()) {
        try {
            RemotingProtocol proto = invokeSyncImpl(channel, message, timeout);
            //                logger.info(String.format("%s", Thread.currentThread().getName()));
            //                logger.info(String.format("invokesync use:%s", watch.toString()));
            return proto;
        } catch (Exception e) {
            logger.error("", e);
            throw e;
        }
    } else {
        closeChannel(channel, address);
        throw new RemotingConnectException(address);
    }
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:30,代码来源:RemotingNettyClient.java

示例3: invokeAsync

import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void invokeAsync(String addr, RemotingCommand request, long timeoutMillis,
        InvokeCallback invokeCallback) throws InterruptedException, RemotingConnectException,
        RemotingTooMuchRequestException, RemotingTimeoutException, RemotingSendRequestException {
    final Channel channel = this.getAndCreateChannel(addr);
    if (channel != null && channel.isActive()) {
        if (this.rpcHook != null) {
            this.rpcHook.doBeforeRequest(addr, request);
        }
        this.invokeAsyncImpl(channel, request, timeoutMillis, invokeCallback);
    }
    else {
        this.closeChannel(addr, channel);
        throw new RemotingConnectException(addr);
    }
}
 
开发者ID:jiumao-org,项目名称:wechat-mall,代码行数:17,代码来源:NettyRemotingClient.java

示例4: invokeOneway

import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void invokeOneway(String addr, RemotingCommand request, long timeoutMillis)
        throws InterruptedException, RemotingConnectException, RemotingTooMuchRequestException,
        RemotingTimeoutException, RemotingSendRequestException {
    final Channel channel = this.getAndCreateChannel(addr);
    if (channel != null && channel.isActive()) {
        try {
            if (this.rpcHook != null) {
                this.rpcHook.doBeforeRequest(addr, request);
            }
            this.invokeOnewayImpl(channel, request, timeoutMillis);
        }
        catch (RemotingSendRequestException e) {
            log.warn("invokeOneway: send request exception, so close the channel[{}]", addr);
            this.closeChannel(addr, channel);
            throw e;
        }
    }
    else {
        this.closeChannel(addr, channel);
        throw new RemotingConnectException(addr);
    }
}
 
开发者ID:jiumao-org,项目名称:wechat-mall,代码行数:24,代码来源:NettyRemotingClient.java

示例5: closeOnFlush

import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
 * Closes the specified channel after all queued write requests are flushed.
 */
public static void closeOnFlush(Channel ch) {
    if (ch.isActive()) {
        ch.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(
                ChannelFutureListener.CLOSE);
    }
}
 
开发者ID:zhoulifu,项目名称:ss-java,代码行数:10,代码来源:ChannelUtils.java

示例6: addChannel

import io.netty.channel.Channel; //导入方法依赖的package包/类
public static void addChannel(Channel channel) {
    String remoteAddr = NettyUtil.parseChannelRemoteAddr(channel);
    if (!channel.isActive()) {
        logger.error("channel is not active, address: {}", remoteAddr);
    }
    UserInfo userInfo = new UserInfo();
    userInfo.setAddr(remoteAddr);
    userInfo.setChannel(channel);
    userInfo.setTime(System.currentTimeMillis());
    userInfos.put(channel, userInfo);
}
 
开发者ID:beyondfengyu,项目名称:HappyChat,代码行数:12,代码来源:UserInfoManager.java

示例7: channelRead

import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    DatagramPacket datagram = (DatagramPacket) msg;
    InetSocketAddress sender = datagram.sender();
    Channel tcpChannel = XChannelMapper.getTcpChannel(sender);
    if (tcpChannel == null) {
        // udpSource not registered, actively discard this packet
        // without register, an udp channel cannot relate to any tcp channel, so remove the map
        XChannelMapper.removeUdpMapping(sender);
        log.warn("Bad Connection! (unexpected udp datagram from {})", sender);
    } else if (tcpChannel.isActive()) {
        ByteBuf byteBuf = datagram.content();
        try {
            if (!byteBuf.hasArray()) {
                byte[] bytes = new byte[byteBuf.readableBytes()];
                byteBuf.getBytes(0, bytes);
                log.info("\t          Proxy << Target \tFrom   {}:{}", sender.getHostString(), sender.getPort());

                // write udp payload via tcp channel
                tcpChannel.writeAndFlush(Unpooled.wrappedBuffer(wrapper.wrap(requestResolver.wrap(XRequest.Channel.UDP, bytes))));
                log.info("\tClient << Proxy           \tGet [{} bytes]", bytes.length);
            }
        } finally {
            ReferenceCountUtil.release(msg);
        }
    }
}
 
开发者ID:ZhangJiupeng,项目名称:AgentX,代码行数:28,代码来源:Udp2TcpHandler.java

示例8: closeChannelGracefully

import io.netty.channel.Channel; //导入方法依赖的package包/类
static void closeChannelGracefully(InetSocketAddress udpSource) {
    Channel udpChannel = removeUdpMapping(udpSource);
    Channel tcpChannel = removeTcpMapping(udpSource);
    if (udpChannel.isActive()) {
        log.info("\t          Proxy << Target \tDisconnect");
        udpChannel.close();
    }
    if (tcpChannel.isActive()) {
        tcpChannel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
        log.info("\tClient << Proxy           \tDisconnect");
    }
}
 
开发者ID:ZhangJiupeng,项目名称:AgentX,代码行数:13,代码来源:XChannelMapper.java

示例9: invokeASync

import io.netty.channel.Channel; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public void invokeASync(String address, final RemotingProtocol message, int timeout, InvokeCallback callback) throws Exception, RemotingConnectException, RemotingSendRequestException, RemotingTimeoutException {
    final Channel channel = this.createChannel(address);
    if (channel != null && channel.isActive()) {
        try {
            invokeAsyncImpl(channel, message, timeout, callback);
        } catch (Exception e) {
            logger.error("", e);
            throw e;
        }
    } else {
        closeChannel(channel, address);
        throw new RemotingConnectException(address);
    }
}
 
开发者ID:lemonJun,项目名称:TakinRPC,代码行数:16,代码来源:RemotingNettyClient.java

示例10: addChannel

import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
 * 添加Channel
 * @param channel
 */
public void addChannel(Channel channel){
    String remoteAddr = NettyUtil.parseChannelRemoteAddr(channel);
    if (!channel.isActive())  logger.error("channel is not active, address: {}", remoteAddr);
    ChatUser chatUser = new ChatUser();
    chatUser.setAddr(remoteAddr);
    chatUser.setChannel(channel);
    chatUserMap.put(channel,chatUser);
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:13,代码来源:ChannelManager.java

示例11: scanNotActiveChannel

import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
 * 扫描并关闭失效的Channel
 */
public void scanNotActiveChannel(){
    Set<Channel> keySet = chatUserMap.keySet();
    for (Channel ch : keySet) {
        ChatUser cUser = chatUserMap.get(ch);
        if (cUser==null) continue;
        if (!ch.isOpen() || !ch.isActive() || (!cUser.isAuth() &&
                (System.currentTimeMillis() - cUser.getTime()) > 10000))
            removeChannel(ch);
    }
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:14,代码来源:ChannelManager.java

示例12: release

import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public final void release(final List<Channel> conns) {
	String nodeAddr;
	Queue<Channel> connQueue;
	for(final Channel conn : conns) {
		nodeAddr = conn.attr(ATTR_KEY_NODE).get();
		if(conn.isActive()) {
			connQueue = availableConns.get(nodeAddr);
			connQueue.add(conn);
			concurrencyThrottle.release();
		} else {
			conn.close();
		}
	}
}
 
开发者ID:akurilov,项目名称:netty-connection-pool,代码行数:16,代码来源:BasicMultiNodeConnPool.java

示例13: fireExceptionAndClose

import io.netty.channel.Channel; //导入方法依赖的package包/类
static void fireExceptionAndClose(Channel channel, Throwable t, boolean close) {
    channel.pipeline().fireExceptionCaught(t);
    if (channel.isActive()) {
        Channel.Unsafe unsafe = channel.unsafe();
        unsafe.close(unsafe.voidPromise());
    }
}
 
开发者ID:szhnet,项目名称:kcp-netty,代码行数:8,代码来源:Utils.java

示例14: sentToClient

import io.netty.channel.Channel; //导入方法依赖的package包/类
private void sentToClient(RemotingCommand request){
	Map<String,Set<Channel>> groupChannelTable = this.producerManager.getGroupChannelTable();
	if(groupChannelTable.get(request.getGroup()) == null || 
			CollectionUtils.isEmpty(groupChannelTable.get(request.getGroup()))){
		return;
	}
	List<Channel> channels = Lists.newArrayList(groupChannelTable.get(request.getGroup()));
	Channel c = channels.get(new Random().nextInt(channels.size()));
	if(c.isActive()){
		c.writeAndFlush(request);
	}
}
 
开发者ID:yanghuijava,项目名称:elephant,代码行数:13,代码来源:TransactionCheckJob.java

示例15: manualRemoveChannel

import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
 * 手动移除相应的 Channel
 *
 * @param channel 欲被手动移除的 Channel
 */
private void manualRemoveChannel(Channel channel) {
    if (channel.isActive()) {
        channel.disconnect();
    } else {
        removeChannelCompleted(channel);
    }
}
 
开发者ID:bitkylin,项目名称:ClusterDeviceControlPlatform,代码行数:13,代码来源:TcpRepository.java


注:本文中的io.netty.channel.Channel.isActive方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。