EventSource eventSource = EventSource.target(target).build(); eventSource.register(new EventHandler(RestconfDiscoveryNode.this)); eventSource.open();
@Override public Optional<AutoCloseable> subscribe(@NonNull String rel, @NonNull SSEObserver<S> observer, @NonNull String mainEventName, long reconnectionTime) { checkArgument(reconnectionTime > 0); CallContext pair = resolve(rel); if (pair == null) { return Optional.empty(); } // this hack is needed because of // https://github.com/jersey/jersey/pull/3600 // setting a global last event id header via LastEventIdHeaderFilter and // synchronizing all sse // sources :-( synchronized (lock) { // this hack is needed because of // https://github.com/jersey/jersey/pull/3600 if (observer.lastKnownEventId().isPresent()) { pair.target.property(SseFeature.LAST_EVENT_ID_HEADER, observer.lastKnownEventId().get()); } EventSource eventSource = EventSource.target(pair.target).named("SSE" + UUID.randomUUID()) .usePersistentConnections().reconnectingEvery(reconnectionTime, TimeUnit.MILLISECONDS).build(); SSEListener<S> sseListener = new SSEListener<>(responseClass, responseBuilder, observer, mainEventName, uri); eventSource.register(sseListener); EventSourceWithCloseGuard ev = new EventSourceWithCloseGuard(eventSource, reconnectionTime, sseListener); ev.open(); return Optional.of(ev); } }
/** * Create a new {@link EventSource.Builder event source builder} that provides convenient way how to * configure and fine-tune various aspects of a newly prepared event source instance. * * @param endpoint SSE streaming endpoint. Must not be {@code null}. * @return a builder of a new event source instance pointing at the specified SSE streaming endpoint. * @throws NullPointerException in case the supplied web target is {@code null}. * @since 2.3 */ public static Builder target(WebTarget endpoint) { return new Builder(endpoint); }
/** * Create a new {@link EventSource.Builder event source builder} that provides convenient way how to * configure and fine-tune various aspects of a newly prepared event source instance. * * @param endpoint SSE streaming endpoint. Must not be {@code null}. * @return a builder of a new event source instance pointing at the specified SSE streaming endpoint. * @throws NullPointerException in case the supplied web target is {@code null}. * @since 2.3 */ public static Builder target(WebTarget endpoint) { return new Builder(endpoint); }
/** * Create a new {@link EventSource.Builder event source builder} that provides convenient way how to * configure and fine-tune various aspects of a newly prepared event source instance. * * @param endpoint SSE streaming endpoint. Must not be {@code null}. * @return a builder of a new event source instance pointing at the specified SSE streaming endpoint. * @throws NullPointerException in case the supplied web target is {@code null}. * @since 2.3 */ public static Builder target(WebTarget endpoint) { return new Builder(endpoint); }
/** * Create a new {@link EventSource.Builder event source builder} that provides convenient way how to * configure and fine-tune various aspects of a newly prepared event source instance. * * @param endpoint SSE streaming endpoint. Must not be {@code null}. * @return a builder of a new event source instance pointing at the specified SSE streaming endpoint. * @throws NullPointerException in case the supplied web target is {@code null}. * @since 2.3 */ public static Builder target(WebTarget endpoint) { return new Builder(endpoint); }