private File prepareCollectionDir ( String projectId , String eventCollection ) throws IOException { File collectionDir = getCollectionDir ( projectId , eventCollection ) ; // Make sure the max number of events has not been exceeded in this collection. If it has, // delete events to make room. File [ ] eventFiles = getFilesInDir ( collectionDir ) ; if ( eventFiles . length >= getMaxEventsPerCollection ( ) ) { // need to age out old data so the cache doesn't grow too large KeenLogging . log ( String . format ( Locale . US , "Too many events in cache for %s, " + "aging out old data" , eventCollection ) ) ; KeenLogging . log ( String . format ( Locale . US , "Count: %d and Max: %d" , eventFiles . length , getMaxEventsPerCollection ( ) ) ) ; // delete the eldest (i.e. first we have to sort the list by name) List < File > fileList = Arrays . asList ( eventFiles ) ; Collections . sort ( fileList , new Comparator < File > ( ) { @ Override public int compare ( File file , File file1 ) { return file . getAbsolutePath ( ) . compareToIgnoreCase ( file1 . getAbsolutePath ( ) ) ; } } ) ; for ( int i = 0 ; i < getNumberEventsToForget ( ) ; i ++ ) { File f = fileList . get ( i ) ; if ( ! f . delete ( ) ) { KeenLogging . log ( String . format ( Locale . US , "CRITICAL: can't delete file %s, cache is going to be too big" , f . getAbsolutePath ( ) ) ) ; } } } return collectionDir ; }
Prepares the file cache for the given event collection for another event to be added . This method checks to make sure that the maximum number of events per collection hasn t been exceeded and if it has this method discards events to make room .