Class SocketUserSessions
java.lang.Object
com.iohao.net.external.core.netty.session.SocketUserSessions
- All Implemented Interfaces:
AttrOptionDynamic, UserSessions<io.netty.channel.ChannelHandlerContext, SocketUserSession>
Netty session manager for TCP and WebSocket external transports.
- Author:
- 渔民小镇
- date:
- 2023-02-18
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected ExternalJoinEnumprotected final AttrOptionsprotected final com.iohao.net.external.core.netty.session.Long2ObjectConcurrentHashMap<SocketUserSession> key : userChannelIdprotected UserHookprotected final com.iohao.net.external.core.netty.session.Long2ObjectConcurrentHashMap<SocketUserSession> key : userId -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadd(io.netty.channel.ChannelHandlerContext channelHandlerContext) Add a newly connected channel as a user session and assign a generated channel-scoped id.voidBroadcasts a message to all users.intCurrent number of online usersbooleanexistUserSession(long userId) true if user existsGets the dynamic member attributes (options)getUserSession(long userId) Gets UserSession.getUserSession(io.netty.channel.ChannelHandlerContext channelHandlerContext) Gets UserSession.getUserSessionByUserChannelId(long userChannelId) getUserSessionvoidremoveUserSession(long userId, Object msg) Removes UserSession by userId, and sends a message before removal.voidremoveUserSession(SocketUserSession userSession) Removes UserSession.static voidsetIdGenerator(org.agrona.concurrent.SnowflakeIdGenerator idGenerator) voidsetJoinEnum(ExternalJoinEnum joinEnum) Connection methodbooleansettingUserId(long userChannelId, long userId) Sets the userId for the channel, indicating that the identity has been authenticated (i.e., logged in).voidsetUserHook(UserHook userHook) userHookMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface AttrOptionDynamic
ifNull, ifPresent, option, option, optionValueMethods inherited from interface UserSessions
forEach, ifPresent, ifPresent, ifPresent
-
Field Details
-
options
-
userIdMap
protected final com.iohao.net.external.core.netty.session.Long2ObjectConcurrentHashMap<SocketUserSession> userIdMapkey : userId -
userChannelIdMap
protected final com.iohao.net.external.core.netty.session.Long2ObjectConcurrentHashMap<SocketUserSession> userChannelIdMapkey : userChannelId -
joinEnum
-
userHook
-
-
Constructor Details
-
SocketUserSessions
public SocketUserSessions()
-
-
Method Details
-
add
Add a newly connected channel as a user session and assign a generated channel-scoped id.- Parameters:
channelHandlerContext- netty channel context- Returns:
- created user session
-
getUserSession
public SocketUserSession getUserSession(io.netty.channel.ChannelHandlerContext channelHandlerContext) Description copied from interface:UserSessionsGets UserSession.- Parameters:
channelHandlerContext- sessionContext- Returns:
- SessionContext
-
settingUserId
public boolean settingUserId(long userChannelId, long userId) Description copied from interface:UserSessionsSets the userId for the channel, indicating that the identity has been authenticated (i.e., logged in).- Parameters:
userChannelId- userChannelIduserId- userId- Returns:
- true if set successfully
-
removeUserSession
Description copied from interface:UserSessionsRemoves UserSession.- Parameters:
userSession- userSession
-
countOnline
public int countOnline()Description copied from interface:UserSessionsCurrent number of online users- Returns:
- Current number of online users
-
broadcast
Description copied from interface:UserSessionsBroadcasts a message to all users.- Parameters:
msg- message
-
setIdGenerator
public static void setIdGenerator(org.agrona.concurrent.SnowflakeIdGenerator idGenerator) -
setJoinEnum
Description copied from interface:UserSessionsConnection method- Specified by:
setJoinEnumin interfaceUserSessions<ChannelHandlerContext, Session extends UserSession>- Parameters:
joinEnum- joinEnum
-
setUserHook
Description copied from interface:UserSessionsuserHook- Specified by:
setUserHookin interfaceUserSessions<ChannelHandlerContext, Session extends UserSession>- Parameters:
userHook- userHook
-
getUserHook
- Specified by:
getUserHookin interfaceUserSessions<ChannelHandlerContext, Session extends UserSession>
-
existUserSession
public boolean existUserSession(long userId) Description copied from interface:UserSessionstrue if user exists- Specified by:
existUserSessionin interfaceUserSessions<ChannelHandlerContext, Session extends UserSession>- Parameters:
userId- user id- Returns:
- true if user exists
-
getUserSession
Description copied from interface:UserSessionsGets UserSession.- Specified by:
getUserSessionin interfaceUserSessions<ChannelHandlerContext, Session extends UserSession>- Parameters:
userId- userId- Returns:
- UserSession
-
getUserSessionByUserChannelId
Description copied from interface:UserSessionsgetUserSession- Specified by:
getUserSessionByUserChannelIdin interfaceUserSessions<ChannelHandlerContext, Session extends UserSession>- Parameters:
userChannelId- userChannelId- Returns:
- userSession
-
removeUserSession
Description copied from interface:UserSessionsRemoves UserSession by userId, and sends a message before removal.- Specified by:
removeUserSessionin interfaceUserSessions<ChannelHandlerContext, Session extends UserSession>- Parameters:
userId- userIdmsg- msg
-
listUserSession
- Specified by:
listUserSessionin interfaceUserSessions<ChannelHandlerContext, Session extends UserSession>
-
getOptions
Description copied from interface:AttrOptionDynamicGets the dynamic member attributes (options)- Specified by:
getOptionsin interfaceAttrOptionDynamic- Returns:
- The dynamic member attributes
-