Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare 1.9.0 release #31

Merged
merged 11 commits into from
Dec 13, 2018
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Change log

All notable changes to the LaunchDarkly EventSource implementation for Java will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).

## [1.8.0] - 2018-04-04
### Added:
- Added `maxReconnectTimeMs(long)` method to `EventSource.Builder` to override the default maximum reconnect time of 30 seconds

## [1.7.1] - 2018-01-30
### Changed:
- Fixed EventSource logger name to match convention
- Ensure background threads are daemon threads
- Don't log IOExceptions when the stream is already being shut down

## [1.7.0] - 2018-01-07
### Added:
- Added the ability to connect to an SSE resource using any HTTP method (defaults to GET), and specify a request body.

## [1.6.0] - 2017-12-20
### Added:
- Add new handler interface for stopping connection retries after an error

### Fixed:
- Ensure that connections are closed completely ([#24](https://github.com/launchdarkly/okhttp-eventsource/pull/24))
- Ensure that we reconnect with backoff in case of a read timeout
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Java EventSource implementation based on OkHttp
Project Information
-----------

This libary allows Java developers to consume Server Sent Events from a remote API. The server sent events spec is defined here: [https://html.spec.whatwg.org/multipage/server-sent-events.html](https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events)
This library allows Java developers to consume Server Sent Events from a remote API. The server sent events spec is defined here: [https://html.spec.whatwg.org/multipage/server-sent-events.html](https://html.spec.whatwg.org/multipage/server-sent-events.html#server-sent-events)
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
version=1.8.0
version=1.9.0-SNAPSHOT
ossrhUsername=
ossrhPassword=
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.launchdarkly.eventsource;

/**
* Interface for an object that will be notified when EventSource encounters a connection failure.
* This is different from {@link EventHandler#onError(Throwable)} in that it will not be called for
* other kinds of errors; also, it has the ability to tell EventSource to stop reconnecting.
*/
public interface ConnectionErrorHandler {
/**
* Return values of {@link ConnectionErrorHandler#onConnectionError(Throwable)} indicating what
Expand Down Expand Up @@ -28,6 +33,9 @@ public static enum Action {
*/
Action onConnectionError(Throwable t);

/**
* Default handler that does nothing.
*/
public static final ConnectionErrorHandler DEFAULT = new ConnectionErrorHandler() {
@Override
public Action onConnectionError(Throwable t) {
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/launchdarkly/eventsource/EventHandler.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,36 @@
package com.launchdarkly.eventsource;

/**
* Interface for an object that will receive SSE events.
*/
public interface EventHandler {
/**
* EventSource calls this method when the stream connection has been opened.
* @throws Exception throwing an exception here will cause it to be logged and also sent to {@link #onError(Throwable)}
*/
void onOpen() throws Exception;

/**
* EventSource calls this method when the stream connection has been closed.
* @throws Exception throwing an exception here will cause it to be logged and also sent to {@link #onError(Throwable)}
*/
void onClosed() throws Exception;

/**
* EventSource calls this method when it has received a new event from the stream.
* @param event the event name, from the {@code event:} line in the stream
* @param messageEvent a {@link MessageEvent} object containing all the other event properties
* @throws Exception throwing an exception here will cause it to be logged and also sent to {@link #onError(Throwable)}
*/
void onMessage(String event, MessageEvent messageEvent) throws Exception;

/**
* EventSource calls this method when it has received a comment line from the stream (any line starting with a colon).
* @param comment the comment line
* @throws Exception throwing an exception here will cause it to be logged and also sent to {@link #onError(Throwable)}
*/
void onComment(String comment) throws Exception;

/**
* This method will be called for all exceptions that occur on the socket connection (including
* an {@link UnsuccessfulResponseException} if the server returns an unexpected HTTP status),
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/launchdarkly/eventsource/EventParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public class EventParser {
this.connectionHandler = connectionHandler;
}

/**
* Accepts a single line of input and updates the parser state. If this completes a valid event,
* the event is sent to the {@link EventHandler}.
* @param line an input line
*/
public void line(String line) {
logger.debug("Parsing line: " + line);
int colonIndex;
Expand Down
Loading