public synchronized void sendQueuedEvents ( KeenProject project , KeenCallback callback ) { if ( ! isActive ) { handleLibraryInactive ( callback ) ; return ; } if ( project == null && defaultProject == null ) { handleFailure ( null , new IllegalStateException ( "No project specified, but no default project found" ) ) ; return ; } if ( ! isNetworkConnected ( ) ) { KeenLogging . log ( "Not sending events because there is no network connection. " + "Events will be retried next time `sendQueuedEvents` is called." ) ; handleFailure ( callback , new Exception ( "Network not connected." ) ) ; return ; } KeenProject useProject = ( project == null ? defaultProject : project ) ; try { String projectId = useProject . getProjectId ( ) ; Map < String , List < Object > > eventHandles = eventStore . getHandles ( projectId ) ; Map < String , List < Map < String , Object > > > events = buildEventMap ( projectId , eventHandles ) ; String response = publishAll ( useProject , events ) ; if ( response != null ) { try { handleAddEventsResponse ( eventHandles , response ) ; } catch ( Exception e ) { // Errors handling the response are non-fatal; just log them. KeenLogging . log ( "Error handling response to batch publish: " + e . getMessage ( ) ) ; } } handleSuccess ( callback ) ; } catch ( Exception e ) { handleFailure ( callback , e ) ; } }
Synchronously sends all queued events for the given project . This method will immediately publish the events to the Keen server in the current thread .