use of net.robinfriedli.aiode.exceptions.handler.handlers.LoggingUncaughtExceptionHandler in project aiode by robinfriedli.
the class HttpServerManager method start.
public void start() throws IOException {
httpServer = HttpServer.create(new InetSocketAddress(port), 0);
ExecutorService executorService = new ThreadPoolExecutor(5, 50, 30, TimeUnit.SECONDS, new SynchronousQueue<>(), new ThreadFactory() {
final AtomicLong threadId = new AtomicLong(1);
@Override
public Thread newThread(@NotNull Runnable r) {
Thread thread = new Thread(r);
thread.setName("http-server-thread-" + threadId.getAndIncrement());
thread.setUncaughtExceptionHandler(new LoggingUncaughtExceptionHandler());
return thread;
}
});
httpServer.setExecutor(executorService);
for (HttpHandlerContribution contribution : httpHandlersContext.getInstancesOf(HttpHandlerContribution.class)) {
httpServer.createContext(contribution.getAttribute("path").getValue(), contribution.instantiate());
}
httpServer.start();
}
use of net.robinfriedli.aiode.exceptions.handler.handlers.LoggingUncaughtExceptionHandler in project aiode by robinfriedli.
the class AudioTrafficSimulationCommand method runAdmin.
@Override
public void runAdmin() throws Exception {
Aiode aiode = Aiode.get();
AudioManager audioManager = aiode.getAudioManager();
AudioPlayerManager playerManager = audioManager.getPlayerManager();
PlayableFactory playableFactory = audioManager.createPlayableFactory(getSpotifyService(), new BlockingTrackLoadingExecutor());
CommandContext context = getContext();
Guild guild = context.getGuild();
ThreadExecutionQueue threadExecutionQueue = aiode.getExecutionQueueManager().getForGuild(guild);
SpotifyApi spotifyApi = context.getSpotifyApi();
AudioTrackLoader audioTrackLoader = new AudioTrackLoader(playerManager);
int streams = getArgumentValueOrElse("streams", DEFAULT_STREAM_COUNT);
int durationSecs = getArgumentValueOrElse("duration", DEFAULT_DURATION);
String playbackUrl = getArgumentValueOrElse("url", DEFAULT_PLAYBACK_URL);
Integer nativeBuffer = getArgumentValueWithTypeOrElse("nativeBuffer", Integer.class, null);
List<Playable> playables = playableFactory.createPlayables(playbackUrl, spotifyApi, true);
if (playables.isEmpty()) {
throw new InvalidCommandException("No playables found for url " + playbackUrl);
}
Playable playable = playables.get(0);
AudioItem audioItem = audioTrackLoader.loadByIdentifier(playable.getPlaybackUrl());
AudioTrack track;
if (audioItem instanceof AudioTrack) {
track = (AudioTrack) audioItem;
} else {
throw new IllegalStateException("Could not get AudioTrack for Playable " + playable);
}
LoopTrackListener loopTrackListener = new LoopTrackListener(track);
List<Thread> playbackThreads = nativeBuffer != null ? null : Lists.newArrayListWithCapacity(streams);
List<Tuple2<IAudioSendSystem, AudioPlayer>> audioSendSystems = nativeBuffer != null ? Lists.newArrayListWithCapacity(streams) : null;
NativeAudioSendFactory nativeAudioSendFactory = nativeBuffer != null ? new NativeAudioSendFactory(nativeBuffer) : null;
LoggingUncaughtExceptionHandler eh = new LoggingUncaughtExceptionHandler();
for (int i = 0; i < streams; i++) {
AudioPlayer player = playerManager.createPlayer();
player.addListener(loopTrackListener);
player.playTrack(track.makeClone());
if (nativeAudioSendFactory != null) {
IAudioSendSystem sendSystem = nativeAudioSendFactory.createSendSystem(new FakePacketProvider(player));
audioSendSystems.add(new Tuple2<>(sendSystem, player));
} else {
Thread playbackThread = new Thread(new PlayerPollingRunnable(player));
playbackThread.setDaemon(true);
playbackThread.setUncaughtExceptionHandler(eh);
playbackThread.setName("simulated-playback-thread-" + i);
playbackThreads.add(playbackThread);
}
}
QueuedTask playbackThreadsManagementTask = new QueuedTask(threadExecutionQueue, new FakePlayerManagementTask(playbackThreads, audioSendSystems, durationSecs)) {
@Override
protected boolean isPrivileged() {
return true;
}
};
playbackThreadsManagementTask.setName("simulated-playback-management-task");
threadExecutionQueue.add(playbackThreadsManagementTask, false);
}
use of net.robinfriedli.aiode.exceptions.handler.handlers.LoggingUncaughtExceptionHandler in project aiode by robinfriedli.
the class AbortCommand method doRun.
@Override
public void doRun() {
CommandExecutionTask commandExecutionTask = getTask();
Thread abortThread = new Thread(() -> {
if (commandExecutionTask != null) {
try {
commandExecutionTask.await();
} catch (InterruptedException ignored) {
}
}
CommandExecutionQueueManager executionQueueManager = Aiode.get().getExecutionQueueManager();
GuildContext guildContext = getContext().getGuildContext();
ThreadExecutionQueue executionQueue = executionQueueManager.getForGuild(getContext().getGuild());
PooledTrackLoadingExecutor pooledTrackLoadingExecutor = guildContext.getPooledTrackLoadingExecutor();
ReplaceableTrackLoadingExecutor replaceableTrackLoadingExecutor = guildContext.getReplaceableTrackLoadingExecutor();
if (executionQueue.isIdle() && pooledTrackLoadingExecutor.isIdle() && replaceableTrackLoadingExecutor.isIdle()) {
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setDescription("No commands are currently running");
getMessageService().sendTemporary(embedBuilder, getContext().getChannel());
setFailed(true);
} else {
executionQueue.abortAll();
pooledTrackLoadingExecutor.abortAll();
replaceableTrackLoadingExecutor.abort();
sendSuccess("Sent all currently running commands an interrupt signal and cancelled queued commands.");
}
});
abortThread.setName("aiode abort thread");
abortThread.setUncaughtExceptionHandler(new LoggingUncaughtExceptionHandler());
abortThread.start();
}
use of net.robinfriedli.aiode.exceptions.handler.handlers.LoggingUncaughtExceptionHandler in project aiode by robinfriedli.
the class LoggingThreadFactory method newThread.
@Override
public Thread newThread(@NotNull Runnable r) {
Thread thread = new Thread(r);
thread.setName(poolName + "-thread-" + threadNumber.getAndIncrement());
thread.setUncaughtExceptionHandler(new LoggingUncaughtExceptionHandler());
return thread;
}
Aggregations