@Override public void shutdown(final int shardId) { final JDA jda = this.shards.getMap().remove(shardId); if (jda != null) { if (this.useShutdownNow) jda.shutdownNow(); else jda.shutdown(); } }
private void stop() { if (EXITING.get()) return; LOGGER.info("Saving data."); EXITING.set(true); Constants.getImportantLogChannel().sendMessage("Average load time of this session: " + manager.getGuildWrapperLoader().getLoadTimes() .stream().mapToLong(v -> v).average().orElse(0) + "\nTotal loads: " + manager.getGuildWrapperLoader().getLoadTimes().size()) .complete(); for (ScheduledFuture<?> scheduledFuture : Scheduler.getTasks().values()) scheduledFuture.cancel(false); // No tasks in theory should block this or cause issues. We'll see for (JDA client : shardManager.getShards()) client.removeEventListener(events); //todo: Make a replacement for the array sendData(); manager.getGuilds().invalidateAll(); shardManager.shutdown(); LOGGER.info("Finished saving!"); for (JDA client : shardManager.getShards()) client.shutdown(); }
@Override public void shutdown() { if (this.shutdown.getAndSet(true)) return; // shutdown has already been requested if (this.worker != null && !this.worker.isDone()) this.worker.cancel(true); if (this.shutdownHook != null) { try { Runtime.getRuntime().removeShutdownHook(this.shutdownHook); } catch (final Exception ignored) {} } this.executor.shutdown(); if (this.shards != null) { for (final JDA jda : this.shards) { if (this.useShutdownNow) jda.shutdownNow(); else jda.shutdown(); } } }
public void shutdown() { if(shuttingDown) return; shuttingDown = true; threadpool.shutdownNow(); if(jda.getStatus()!=JDA.Status.SHUTTING_DOWN) { jda.getGuilds().stream().forEach(g -> { g.getAudioManager().closeAudioConnection(); AudioHandler ah = (AudioHandler)g.getAudioManager().getSendingHandler(); if(ah!=null) { ah.stopAndClear(); ah.getPlayer().destroy(); nowplaying.updateTopic(g.getIdLong(), ah, true); } }); jda.shutdown(); } if(gui!=null) gui.dispose(); System.exit(0); }
@Override public void restart(final int shardId) { Checks.notNegative(shardId, "shardId"); Checks.check(shardId < this.shardsTotal, "shardId must be lower than shardsTotal"); final JDA jda = this.shards.getMap().remove(shardId); if (jda != null) { if (this.useShutdownNow) jda.shutdownNow(); else jda.shutdown(); } enqueueShard(shardId); }
shard.shutdown();
public void stopStuff(Boolean fake) { if (!fake) { if (jda != null) { DiscordHandler.sendMessageToChannel(Config.CHANNELS.MAIN_CHANNEL, Config.MESSAGES.SERVER_STOPPING); DiscordHandler.close(); if (updater != null) updater.interrupt(); jda.getTextChannelById(Config.CHANNELS.MAIN_CHANNEL).getManager().setTopic(FormatType.OFFLINE_TOPIC_FORMAT.get()).queue(); jda.shutdown(); long time = System.currentTimeMillis(); while ((System.currentTimeMillis() - time < 10000) && (jda != null && jda.getStatus() != JDA.Status.SHUTDOWN)) { try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } return; } } logger.info("Disconnecting from Discord..."); if (jda != null && jda.getStatus() != JDA.Status.SHUTDOWN && jda.getStatus() != JDA.Status.SHUTTING_DOWN) { jda.shutdownNow(); } // Unregistering listeners Sponge.getEventManager().unregisterPluginListeners(this); Sponge.getEventManager().registerListeners(this, this); Config = null; }
/** * shutdown hook, closing connections * */ private static void shutdownHook() { if (botContainer != null) { for (DiscordBot discordBot : botContainer.getShards()) { for (Guild guild : discordBot.getJda().getGuilds()) { AudioManager audio = guild.getAudioManager(); if (audio.isConnected()) { CBotPlayingOn.insert(guild.getId(), audio.getConnectedChannel().getId()); } } discordBot.getJda().shutdown(); } } }