eclipse-ee4j / eclipse-ee4j/jersey

SseEventSource reconnect time unit isn't applied when set using the builder

Open
#3,663 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

When setting the reconnect time using the following code, the unit isn't applied, instead the value is applied always as milliseconds:

```
SseEventSource eventSource = SseEventSource.target(target)
.reconnectingEvery(1, TimeUnit.DAYS)
.build()
```

The cause is that the builder of [org.glassfish.jersey.media.sse.internal.EventProcessor](https://github.com/jersey/jersey/blob/12e5d8bdf22bcd2676a1032ed69473cf2bbc48c7/media/sse/src/main/java/org/glassfish/jersey/media/sse/internal/EventProcessor.java#L145) doesn't apply the time unit and just copies the value of `reconnectDelay` as is, ignoring the value of `reconnectUnit` in the builder.

### Proposed fix:

Simply multiply the value of `reconnectDelay` in the builder by `reconnectUnit` before setting the value of `reconnectDelay` in the `EventProcessor`:

```
private EventProcessor(Builder builder) {
...
this.reconnectDelay = TimeUnit.MILLISECONDS.convert(builder.reconnectDelay, builder.reconnectUnit != null ? builder.reconnectUnit : TimeUnit.MILLISECONDS);
...

Contributor guide

Open the contributing guide

Research direction

Start in media/sse/src/main/java/org/glassfish/jersey/media/sse/internal/EventProcessor.java at the Builder constructor around the referenced line. Trace how reconnectDelay and reconnectUnit are passed from SseEventSource.reconnectingEvery, then verify that the completed EventProcessor represents the requested delay in milliseconds for non-millisecond units.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.