public abstract class EventsFilesManager<T>
extends Object
| Modifier and Type | Field and Description |
|---|---|
protected Context |
context |
protected CurrentTimeProvider |
currentTimeProvider |
protected EventsStorage |
eventStorage |
protected long |
lastRollOverTime |
static int |
MAX_BYTE_SIZE_PER_FILE |
static int |
MAX_FILES_IN_BATCH |
static int |
MAX_FILES_TO_KEEP |
static String |
ROLL_OVER_FILE_NAME_SEPARATOR |
protected List<EventsStorageListener> |
rollOverListeners |
protected EventTransform<T> |
transform |
| Constructor and Description |
|---|
EventsFilesManager(Context context,
EventTransform<T> transform,
CurrentTimeProvider currentTimeProvider,
EventsStorage eventStorage,
int defaultMaxFilesToKeep) |
| Modifier and Type | Method and Description |
|---|---|
void |
deleteAllEventsFiles() |
void |
deleteOldestInRollOverIfOverMax() |
void |
deleteSentFiles(List<File> files) |
protected abstract String |
generateUniqueRollOverFileName() |
List<File> |
getBatchOfFilesToSend() |
long |
getLastRollOverTime() |
protected int |
getMaxByteSizePerFile() |
protected int |
getMaxFilesToKeep()
This method can be overridden by subclasses to vary the maximum file count value used
during file clean-up.
|
long |
parseCreationTimestampFromFileName(String fileName) |
void |
registerRollOverListener(EventsStorageListener listener)
Register a listener for session analytics file roll over events that may get triggered
due to the file reaching threshold size.
|
boolean |
rollFileOver()
Trigger a file roll over.
|
void |
writeEvent(T event) |
public static final String ROLL_OVER_FILE_NAME_SEPARATOR
public static final int MAX_BYTE_SIZE_PER_FILE
public static final int MAX_FILES_IN_BATCH
public static final int MAX_FILES_TO_KEEP
protected final Context context
protected final EventTransform<T> transform
protected final CurrentTimeProvider currentTimeProvider
protected final EventsStorage eventStorage
protected volatile long lastRollOverTime
protected final List<EventsStorageListener> rollOverListeners
public EventsFilesManager(Context context,
EventTransform<T> transform,
CurrentTimeProvider currentTimeProvider,
EventsStorage eventStorage,
int defaultMaxFilesToKeep)
throws IOException
context - Context to use for file accesstransform - EventTransform used to convert events to bytes for storagecurrentTimeProvider - CurrentTimeProvider that defines how we determine timeeventStorage - EventsStorage into which we will store eventsdefaultMaxFilesToKeep - int defining the maximum number of storage files we will buffer
on device. This is useful for providing a constant maximum, or
a default value that varies based on overriding
getMaxFilesToKeep()IOExceptionpublic void writeEvent(T event) throws IOException
IOExceptionpublic void registerRollOverListener(EventsStorageListener listener)
public boolean rollFileOver()
throws IOException
true if events existed and a roll-over file was created.
Returns false if no events existed and a roll-over file was not created.IOExceptionprotected abstract String generateUniqueRollOverFileName()
protected int getMaxFilesToKeep()
protected int getMaxByteSizePerFile()
public long getLastRollOverTime()
public List<File> getBatchOfFilesToSend()
public void deleteSentFiles(List<File> files)
public void deleteAllEventsFiles()
public void deleteOldestInRollOverIfOverMax()
public long parseCreationTimestampFromFileName(String fileName)