package pro.gravit.launcher.request; import java.io.IOException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; public interface RequestService { CompletableFuture request(Request request) throws IOException; void registerEventHandler(EventHandler handler); void unregisterEventHandler(EventHandler handler); default T requestSync(Request request) throws IOException { try { return request(request).get(); } catch (InterruptedException e) { throw new RequestException("Request interrupted"); } catch (ExecutionException e) { Throwable cause = e.getCause(); if (cause instanceof IOException) throw (IOException) e.getCause(); else { throw new RequestException(cause); } } } boolean isClosed(); @FunctionalInterface public interface EventHandler { /** * @param event processing event * @param event type * @return false - continue, true - stop */ boolean eventHandle(T event); } }