public void start ( ) { if ( this . started ) { throw new IllegalStateException ( "Cannot start the EventStream because it isn't stopped." ) ; } final long initialPosition ; if ( this . startingPosition == STREAM_POSITION_NOW ) { BoxAPIRequest request = new BoxAPIRequest ( this . api , EVENT_URL . build ( this . api . getBaseURL ( ) , "now" ) , "GET" ) ; BoxJSONResponse response = ( BoxJSONResponse ) request . send ( ) ; JsonObject jsonObject = JsonObject . readFrom ( response . getJSON ( ) ) ; initialPosition = jsonObject . get ( "next_stream_position" ) . asLong ( ) ; } else { assert this . startingPosition >= 0 : "Starting position must be non-negative" ; initialPosition = this . startingPosition ; } this . poller = new Poller ( initialPosition ) ; this . pollerThread = new Thread ( this . poller ) ; this . pollerThread . setUncaughtExceptionHandler ( new Thread . UncaughtExceptionHandler ( ) { public void uncaughtException ( Thread t , Throwable e ) { EventStream . this . notifyException ( e ) ; } } ) ; this . pollerThread . start ( ) ; this . started = true ; }
Starts this EventStream and begins long polling the API .