public void listenBucketNotification ( String bucketName , String prefix , String suffix , String [ ] events , BucketEventListener eventCallback ) throws InvalidBucketNameException , NoSuchAlgorithmException , InsufficientDataException , IOException , InvalidKeyException , NoResponseException , XmlPullParserException , ErrorResponseException , InternalException { Multimap < String , String > queryParamMap = HashMultimap . create ( ) ; queryParamMap . put ( "prefix" , prefix ) ; queryParamMap . put ( "suffix" , suffix ) ; for ( String event : events ) { queryParamMap . put ( "events" , event ) ; } String bodyContent = "" ; Scanner scanner = null ; HttpResponse response = null ; ObjectMapper mapper = new ObjectMapper ( ) ; try { response = executeReq ( Method . GET , getRegion ( bucketName ) , bucketName , "" , null , queryParamMap , null , 0 ) ; scanner = new Scanner ( response . body ( ) . charStream ( ) ) ; scanner . useDelimiter ( "\n" ) ; while ( scanner . hasNext ( ) ) { bodyContent = scanner . next ( ) . trim ( ) ; if ( bodyContent . equals ( "" ) ) { continue ; } NotificationInfo ni = mapper . readValue ( bodyContent , NotificationInfo . class ) ; eventCallback . updateEvent ( ni ) ; } } catch ( RuntimeException e ) { throw e ; } catch ( Exception e ) { throw e ; } finally { if ( response != null ) { response . body ( ) . close ( ) ; } if ( scanner != null ) { scanner . close ( ) ; } } }
Listen to bucket notifications .