io.keen.client.java
Class FileEventStore

java.lang.Object
  extended by io.keen.client.java.FileEventStore
All Implemented Interfaces:
KeenEventStore

public class FileEventStore
extends java.lang.Object
implements KeenEventStore

Implementation of the KeenEventStore interface using the file system to cache events in between queueing and batch posting.

Since:
2.0.0

Constructor Summary
FileEventStore(java.io.File root)
          Constructs a new File-based event store.
 
Method Summary
 java.lang.String get(java.lang.Object handle)
          Gets the event corresponding to the given handle.
 java.util.Map<java.lang.String,java.util.List<java.lang.Object>> getHandles(java.lang.String projectId)
          Retrieves a map from collection names to lists of handles currently stored under each collection.
 void remove(java.lang.Object handle)
          Removes the specified event from the store.
 java.lang.Object store(java.lang.String projectId, java.lang.String eventCollection, java.lang.String event)
          Stores the given event.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileEventStore

public FileEventStore(java.io.File root)
               throws java.io.IOException
Constructs a new File-based event store.

Parameters:
root - The root directory in which to store queued event files.
Throws:
java.io.IOException - If the provided root isn't an existing directory.
Method Detail

store

public java.lang.Object store(java.lang.String projectId,
                              java.lang.String eventCollection,
                              java.lang.String event)
                       throws java.io.IOException
Stores the given event.

Specified by:
store in interface KeenEventStore
Parameters:
projectId - The ID of the project in which the event should be stored.
eventCollection - The name of the collection in which the event should be stored.
event - The serialized JSON for the event to store.
Returns:
A handle which can be used to retrieve or remove the event.
Throws:
java.io.IOException - If there is an error storing the event.

get

public java.lang.String get(java.lang.Object handle)
                     throws java.io.IOException
Gets the event corresponding to the given handle.

Specified by:
get in interface KeenEventStore
Parameters:
handle - A handle returned from a previous call to KeenEventStore.store(String, String, String) or KeenEventStore.getHandles(String).
Returns:
The serialized JSON for the event, or null if the handle is no longer present in the store.
Throws:
java.io.IOException - If there is an error retrieving the event.

remove

public void remove(java.lang.Object handle)
            throws java.io.IOException
Removes the specified event from the store.

Specified by:
remove in interface KeenEventStore
Parameters:
handle - A handle returned from a previous call to KeenEventStore.store(String, String, String) or KeenEventStore.getHandles(String).
Throws:
java.io.IOException - If there is an error removing the event.

getHandles

public java.util.Map<java.lang.String,java.util.List<java.lang.Object>> getHandles(java.lang.String projectId)
                                                                            throws java.io.IOException
Retrieves a map from collection names to lists of handles currently stored under each collection. This will be used by the KeenClient to retrieve the events to send in a batch to the Keen server, as well as to remove all successfully posted events after processing the response.

Specified by:
getHandles in interface KeenEventStore
Parameters:
projectId - The ID of the project for which to retrieve event handles.
Returns:
A map from collection names to lists of handles currently stored under each collection. If there are no events, an empty map will be returned.
Throws:
java.io.IOException - If there is an error retrieving the handles.