本文整理匯總了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);
}
}