@Override public void open() { if (!state.compareAndSet(EventProcessor.State.READY, EventProcessor.State.OPEN)) { switch (state.get()) { case CLOSED: throw new IllegalStateException(LocalizationMessages.EVENT_SOURCE_ALREADY_CLOSED()); case OPEN: throw new IllegalStateException(LocalizationMessages.EVENT_SOURCE_ALREADY_CONNECTED()); } } EventProcessor processor = EventProcessor .builder(endpoint, state, clientExecutor, this::onEvent, this::close) .reconnectDelay(reconnectDelay, reconnectTimeUnit) .build(); clientExecutor.submit(processor); // return only after the first request to the SSE endpoint has been made processor.awaitFirstContact(); }
/** * Open the connection to the supplied SSE underlying {@link WebTarget web target} and start processing incoming * {@link InboundEvent events}. * * @throws IllegalStateException in case the event source has already been opened earlier. */ public void open() { if (!state.compareAndSet(EventProcessor.State.READY, EventProcessor.State.OPEN)) { switch (state.get()) { case OPEN: throw new IllegalStateException(LocalizationMessages.EVENT_SOURCE_ALREADY_CONNECTED()); case CLOSED: throw new IllegalStateException(LocalizationMessages.EVENT_SOURCE_ALREADY_CLOSED()); } } EventProcessor.Builder builder = EventProcessor.builder(target, state, executor, this, shutdownHandler) .boundListeners(boundListeners) .unboundListeners(unboundListeners) .reconnectDelay(reconnectDelay, TimeUnit.MILLISECONDS); if (disableKeepAlive) { builder.disableKeepAlive(); } EventProcessor processor = builder.build(); executor.submit(processor); // return only after the first request to the SSE endpoint has been made processor.awaitFirstContact(); }