Search in sources :

Example 1 with MantaroEventManager

use of net.kodehawa.mantarobot.core.MantaroEventManager in project MantaroBot by Mantaro.

the class ShardedMantaro method shard.

/**
 * Starts building all the necessary Shards to start this bot instance.
 * After finishing loading all the necessary shards, this will call {@link ShardedMantaro#startPostLoadProcedure(long)} and set everything so the bot
 * will be functioning completely (sends {@link PostLoadEvent}, marks the core as ready, starts posting stats to most popular discord bot lists,
 * starts the birthday checker and starts the ShardWatcherThread both on all the started shards.
 */
public void shard() {
    try {
        MantaroCore.setLoadState(LoadState.LOADING_SHARDS);
        log.info("Spawning shards...");
        long start = System.currentTimeMillis();
        for (int i = 0; i < totalShards; i++) {
            if (MantaroData.config().get().upToShard != 0 && i > MantaroData.config().get().upToShard)
                continue;
            log.info("Starting shard #" + i + " of " + totalShards);
            // The custom event manager instance is important so we can track when we received the last event, or if we're receiving events at all.
            MantaroEventManager manager = new MantaroEventManager();
            managers.add(manager);
            // Builds the new MantaroShard instance, which will start the shard.
            shards[i] = new MantaroShard(i, totalShards, manager, processor);
            log.debug("Finished loading shard #" + i + ".");
        }
        // Beep-boop, we finished loading!
        this.startPostLoadProcedure(start);
    } catch (Exception e) {
        e.printStackTrace();
        SentryHelper.captureExceptionContext("Shards failed to initialize!", e, this.getClass(), "Shard Loader");
    }
}
Also used : MantaroEventManager(net.kodehawa.mantarobot.core.MantaroEventManager) PostingException(com.github.natanbc.discordbotsapi.PostingException)

Aggregations

PostingException (com.github.natanbc.discordbotsapi.PostingException)1 MantaroEventManager (net.kodehawa.mantarobot.core.MantaroEventManager)1