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 void
clearChatMap()
Clears the chat map, used to persist Chat objects in the Platform.protected void
clearUserMap()
Clears the user map, used to persist PlatformUser objects in the Platform.void
disconnect()
Calls to disconnect from the platform.protected Chat
getCachedChatById(java.lang.String id)
protected Chat
getCachedChatById(java.lang.String id, java.util.function.Function<java.lang.String,Chat> function)
protected PlatformUser
getCachedUserById(java.lang.String id)
protected PlatformUser
getCachedUserById(java.lang.String id, java.util.function.Function<java.lang.String,PlatformUser> function)
Chat
getChat(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.PlatformUser
getPlatformUser(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 Chat
loadChatById(java.lang.String id)
Loads a chat by its ID.protected abstract PlatformUser
loadUserById(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:PlatformConnection
Calls to disconnect from the platform.- Specified by:
disconnect
in 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:PlatformConnection
Gets a chat by its user-specific ID.- Specified by:
getChat
in 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:PlatformConnection
Gets a user on this platform by their platform-specific ID.- Specified by:
getPlatformUser
in interfacePlatformConnection
- Parameters:
id
- platform-specific Id.- Returns:
- PlatformUser instance if found, null otherwise.
-
getChats
public java.util.Collection<Chat> getChats()
Description copied from interface:PlatformConnection
Gets a list of chats associated with this platform.- Specified by:
getChats
in interfacePlatformConnection
- Returns:
- immutable collection of Chat instances associated with this platform.
-
getPlatformUsers
public java.util.Collection<PlatformUser> getPlatformUsers()
Description copied from interface:PlatformConnection
Gets a collection of known platform users to this platform.- Specified by:
getPlatformUsers
in interfacePlatformConnection
- Returns:
- immutable list of platform users.
-
-