本文整理汇总了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();
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
}
示例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");
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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();
}
}
}
示例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());
}
}
示例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);
}
}
示例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);
}
}