Package io.manebot.platform
Class AbstractPlatformConnection
- java.lang.Object
-
- io.manebot.platform.AbstractPlatformConnection
-
- All Implemented Interfaces:
PlatformConnection
public abstract class AbstractPlatformConnection extends java.lang.Object implements PlatformConnection
Describes an abstract platform connection, a helper class to cover holding instantiations for chats and users in the system in weak reference caches, a memory-tolerant behavior that ensures one-reference for a platform connection.
-
-
Constructor Summary
Constructors Constructor Description AbstractPlatformConnection()
-
Method Summary
Modifier and Type Method Description protected voidclearChatMap()Clears the chat map, used to persist Chat objects in the Platform.protected voidclearUserMap()Clears the user map, used to persist PlatformUser objects in the Platform.voiddisconnect()Calls to disconnect from the platform.protected ChatgetCachedChatById(java.lang.String id)protected ChatgetCachedChatById(java.lang.String id, java.util.function.Function<java.lang.String,Chat> function)protected PlatformUsergetCachedUserById(java.lang.String id)protected PlatformUsergetCachedUserById(java.lang.String id, java.util.function.Function<java.lang.String,PlatformUser> function)ChatgetChat(java.lang.String id)Gets a chat by its user-specific ID.java.util.Collection<Chat>getChats()Gets a list of chats associated with this platform.PlatformUsergetPlatformUser(java.lang.String id)Gets a user on this platform by their platform-specific ID.java.util.Collection<PlatformUser>getPlatformUsers()Gets a collection of known platform users to this platform.protected abstract ChatloadChatById(java.lang.String id)Loads a chat by its ID.protected abstract PlatformUserloadUserById(java.lang.String id)Loads a user by its ID.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.manebot.platform.PlatformConnection
connect, createChatFromIds, createChatFromUsers, getChatIds, getChatsByUser, getChatsByUser, getPlatformUserIds, getSelf, getStatus, getUserRegistration, isConnected, setStatus
-
-
-
-
Method Detail
-
clearChatMap
protected final void clearChatMap()
Clears the chat map, used to persist Chat objects in the Platform.
-
clearUserMap
protected final void clearUserMap()
Clears the user map, used to persist PlatformUser objects in the Platform.
-
disconnect
public void disconnect()
Description copied from interface:PlatformConnectionCalls to disconnect from the platform.- Specified by:
disconnectin interfacePlatformConnection
-
loadUserById
protected abstract PlatformUser loadUserById(java.lang.String id)
Loads a user by its ID.- Parameters:
id- PlatformUser ID to load.- Returns:
- PlatformUser instance loaded, null otherwise.
-
loadChatById
protected abstract Chat loadChatById(java.lang.String id)
Loads a chat by its ID.- Parameters:
id- Chat ID to load.- Returns:
- Chat instance loaded, null otherwise.
-
getCachedUserById
protected final PlatformUser getCachedUserById(java.lang.String id)
-
getCachedChatById
protected final Chat getCachedChatById(java.lang.String id)
-
getCachedUserById
protected final PlatformUser getCachedUserById(java.lang.String id, java.util.function.Function<java.lang.String,PlatformUser> function)
-
getCachedChatById
protected final Chat getCachedChatById(java.lang.String id, java.util.function.Function<java.lang.String,Chat> function)
-
getChat
public Chat getChat(java.lang.String id)
Description copied from interface:PlatformConnectionGets a chat by its user-specific ID.- Specified by:
getChatin interfacePlatformConnection- Parameters:
id- Chat ID to search for.- Returns:
- Chat instance if found, null otherwise.
-
getPlatformUser
public PlatformUser getPlatformUser(java.lang.String id)
Description copied from interface:PlatformConnectionGets a user on this platform by their platform-specific ID.- Specified by:
getPlatformUserin interfacePlatformConnection- Parameters:
id- platform-specific Id.- Returns:
- PlatformUser instance if found, null otherwise.
-
getChats
public java.util.Collection<Chat> getChats()
Description copied from interface:PlatformConnectionGets a list of chats associated with this platform.- Specified by:
getChatsin interfacePlatformConnection- Returns:
- immutable collection of Chat instances associated with this platform.
-
getPlatformUsers
public java.util.Collection<PlatformUser> getPlatformUsers()
Description copied from interface:PlatformConnectionGets a collection of known platform users to this platform.- Specified by:
getPlatformUsersin interfacePlatformConnection- Returns:
- immutable list of platform users.
-
-