Search in sources :

Example 1 with EventStream

use of com.box.sdk.EventStream in project camel by apache.

the class BoxEventsManager method listen.

/**
     * Create an event stream with optional starting initial position and add
     * listener that will be notified when an event is received.
     * 
     * @param startingPosition
     *            - the starting position of the event stream.
     * @param listener
     *            - the listener to add to event stream.
     * 
     * @return The event stream.
     */
public void listen(EventListener listener, Long startingPosition) {
    try {
        LOG.debug("Listening for events with listener=" + listener + " at startingPosition=" + startingPosition);
        if (listener == null) {
            LOG.debug("Parameter 'listener' is null: will not listen for events");
            return;
        }
        if (startingPosition != null) {
            eventStream = new EventStream(boxConnection, startingPosition);
        } else {
            eventStream = new EventStream(boxConnection);
        }
        eventStream.addListener(listener);
        eventStream.start();
    } catch (BoxAPIException e) {
        throw new RuntimeException(String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : EventStream(com.box.sdk.EventStream) BoxAPIException(com.box.sdk.BoxAPIException)

Aggregations

BoxAPIException (com.box.sdk.BoxAPIException)1 EventStream (com.box.sdk.EventStream)1