public class EventStream extends Object
EventListeners
.
This class handles long polling the Box events endpoint in order to receive real-time user or enterprise events.
When an EventStream is started, it begins long polling on a separate thread until the stop()
method is called.
Since the API may return duplicate events, EventStream also maintains a small cache of the most recently received
event IDs in order to automatically deduplicate events.
Constructor and Description |
---|
EventStream(BoxAPIConnection api)
Constructs an EventStream using an API connection.
|
EventStream(BoxAPIConnection api,
long startingPosition)
Constructs an EventStream using an API connection and a starting initial position.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(EventListener listener)
Adds a listener that will be notified when an event is received.
|
protected boolean |
isDuplicate(String eventID)
Indicates whether or not an event ID is a duplicate.
|
boolean |
isStarted()
Indicates whether or not this EventStream has been started.
|
void |
start()
Starts this EventStream and begins long polling the API.
|
void |
stop()
Stops this EventStream and disconnects from the API.
|
public EventStream(BoxAPIConnection api)
api
- the API connection to use.public EventStream(BoxAPIConnection api, long startingPosition)
api
- the API connection to use.startingPosition
- the starting position of the event stream.public void addListener(EventListener listener)
listener
- the listener to add.public boolean isStarted()
public void stop()
IllegalStateException
- if the EventStream is already stopped.public void start()
IllegalStateException
- if the EventStream is already started.protected boolean isDuplicate(String eventID)
This method can be overridden by a subclass in order to provide custom de-duping logic.
eventID
- the event ID.