public class EventStream extends Object
EventListeners
.
This class handles long polling the Box events endpoint in order to receive real-time user 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.
Note: Enterprise Events can be accessed by admin users with the EventLog.getEnterpriseEvents method
Modifier and Type | Field and Description |
---|---|
static URLTemplate |
EVENT_URL
Events URL.
|
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.
|
EventStream(BoxAPIConnection api,
long startingPosition,
int pollingDelay)
Constructs an EventStream using an API connection and a starting initial position with custom polling delay.
|
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 static final URLTemplate EVENT_URL
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 EventStream(BoxAPIConnection api, long startingPosition, int pollingDelay)
api
- the API connection to use.startingPosition
- the starting position of the event stream.pollingDelay
- the delay in milliseconds between successive calls to get more events.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.