|
|
|
@ -19,45 +19,23 @@ public class GatewayConnectionsManager
|
|
|
|
|
/**
|
|
|
|
|
* Main datastore
|
|
|
|
|
*/
|
|
|
|
|
private Set<IDiscordClient> connectionsDatastore;
|
|
|
|
|
private static Set<IDiscordClient> connectionsDatastore = new HashSet<>();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List of registered listeners for each connection, as we can't access registered listeners in IDC dispatcher.
|
|
|
|
|
*/
|
|
|
|
|
private Map<IDiscordClient, Set<Object>> registeredListeners;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Singleton unique instance
|
|
|
|
|
*/
|
|
|
|
|
private static final GatewayConnectionsManager INSTANCE = new GatewayConnectionsManager();
|
|
|
|
|
private static Map<IDiscordClient, Set<Object>> registeredListeners = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Logger
|
|
|
|
|
*/
|
|
|
|
|
private static final Logger LOGGER = LogManager.getLogger(GatewayConnectionsManager.class);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get singleton instance
|
|
|
|
|
*/
|
|
|
|
|
public static GatewayConnectionsManager getInstance()
|
|
|
|
|
{
|
|
|
|
|
return INSTANCE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Private constructor, to enforce singleton
|
|
|
|
|
*/
|
|
|
|
|
private GatewayConnectionsManager()
|
|
|
|
|
{
|
|
|
|
|
connectionsDatastore = new HashSet<>();
|
|
|
|
|
registeredListeners = new HashMap<>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Registers a connection and login automatically
|
|
|
|
|
* @param builder Filled and builder ready for log in
|
|
|
|
|
*/
|
|
|
|
|
public void registerConnection(ClientBuilder builder)
|
|
|
|
|
public static void registerConnection(ClientBuilder builder)
|
|
|
|
|
{
|
|
|
|
|
LOGGER.info("Registering new connection");
|
|
|
|
|
builder.withReconnects(); // Makes the connections auto-reconnects on dropped connection.
|
|
|
|
@ -77,7 +55,7 @@ public class GatewayConnectionsManager
|
|
|
|
|
* Logout and unregister specified connection
|
|
|
|
|
* @param client Target connection
|
|
|
|
|
*/
|
|
|
|
|
public void unregisterConnection(IDiscordClient client)
|
|
|
|
|
public static void unregisterConnection(IDiscordClient client)
|
|
|
|
|
{
|
|
|
|
|
LOGGER.info("Unregistering connection with user #" + client.getOurUser().getID());
|
|
|
|
|
|
|
|
|
@ -91,7 +69,7 @@ public class GatewayConnectionsManager
|
|
|
|
|
* @param target Target conection, must be registered
|
|
|
|
|
* @param refListeners Reference listeners list
|
|
|
|
|
*/
|
|
|
|
|
public void updateListeners(IDiscordClient target, Set<Class<?>> refListeners)
|
|
|
|
|
public static void updateListeners(IDiscordClient target, Set<Class<?>> refListeners)
|
|
|
|
|
{
|
|
|
|
|
LOGGER.debug("Updating listeners for target " + target.getOurUser().getID());
|
|
|
|
|
|
|
|
|
@ -123,7 +101,7 @@ public class GatewayConnectionsManager
|
|
|
|
|
* Update all connections listeners
|
|
|
|
|
* @param refListeners Reference listeners list
|
|
|
|
|
*/
|
|
|
|
|
public void updateAllListeners(Set<Class<?>> refListeners)
|
|
|
|
|
public static void updateAllListeners(Set<Class<?>> refListeners)
|
|
|
|
|
{
|
|
|
|
|
for(IDiscordClient i : connectionsDatastore) updateListeners(i, refListeners);
|
|
|
|
|
}
|
|
|
|
@ -132,7 +110,7 @@ public class GatewayConnectionsManager
|
|
|
|
|
* Reconnect a disconnected gateway connection
|
|
|
|
|
* @param target Disconnected connection
|
|
|
|
|
*/
|
|
|
|
|
public void reconnect(IDiscordClient target)
|
|
|
|
|
public static void reconnect(IDiscordClient target)
|
|
|
|
|
{
|
|
|
|
|
if(!connectionsDatastore.contains(target)) return;
|
|
|
|
|
|
|
|
|
|