下面列出了io.netty.channel.Channel#id ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void startSubscription(SubscriptionItem item, Channel connection) {
checkNotNull(connection, "connection is null");
if (item.isSubscribed) {
logger.debug("StartSubscription REMOVING due to already subscribed {}.", item);
removeSubscription(item);
return;
}
item.correlationId = UUID.randomUUID();
item.connectionId = connection.id();
item.lastUpdated.update();
activeSubscriptions.put(item.correlationId, item);
if (!item.operation.subscribe(item.correlationId, connection)) {
logger.debug("StartSubscription REMOVING AS COULD NOT SUBSCRIBE {}.", item);
removeSubscription(item);
} else {
logger.debug("StartSubscription SUBSCRIBING {}.", item);
}
}
public static String channelInfoForLogging(Channel ch)
{
if (ch == null) {
return "null";
}
String channelInfo = ch.toString()
+ ", active=" + ch.isActive()
+ ", open=" + ch.isOpen()
+ ", registered=" + ch.isRegistered()
+ ", writable=" + ch.isWritable()
+ ", id=" + ch.id();
CurrentPassport passport = CurrentPassport.fromChannel(ch);
return "Channel: " + channelInfo + ", Passport: " + String.valueOf(passport);
}
@Override
public void channelInactive(Channel channel) {
ChannelId channelId = channel.id();
channelManager.removeChannel(channelId);
sessionManager.removeSession(channelId);
SessionHelper.markOffline(channel);
log.info("Remove an inactive Channel={}", channel);
}
private void send(OperationItem item, Channel connection) {
item.connectionId = connection.id();
item.lastUpdated.update();
activeOperations.put(item.correlationId, item);
TcpPackage tcpPackage = item.operation.create(item.correlationId);
logger.debug("send package {}, {}, {}.", tcpPackage.command, tcpPackage.correlationId, item);
connection.writeAndFlush(tcpPackage);
}
public void onExceptionCaught(Channel channel, Throwable cause) {
String message = "Exception caught in netty's pipeline in channel " + channel.id();
changeStatus(ServiceStatus.ERROR, message, cause);
stop(message, cause);
}
protected static Object channelId(Channel channel) {
return channel.id();
}
/**
* 접속 사용자 정보 제거
*
* @param channel Netty 채널
*/
public void removeUser(Channel channel) {
ChannelId channelId = channel.id();
Map<ChannelId, String> channelIdUserIdMap = channelIdUserIdRepository.getChannelIdUserIdMap();
String userId = channelIdUserIdMap.get(channelId);
// 사용자 정보 제거
if (!StringUtils.isEmpty(userId)) {
userIdChannelRepository.getUserIdChannelMap().remove(userId);
String roomId = userIdRoomIdRepository.getUserIdRoomIdMap().get(userId);
// 룸 정보 제거
if (!StringUtils.isEmpty(roomId)) {
roomIdUserIdRepository.getRoomIdUserIdMap().remove(roomId, userId);
userIdRoomIdRepository.getUserIdRoomIdMap().remove(userId);
}
channelIdUserIdMap.remove(channelId);
}
}