當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。