com.amazonaws.mobileconnectors.kinesis.kinesisrecorder
Class KinesisRecorder

java.lang.Object
  extended by com.amazonaws.mobileconnectors.kinesis.kinesisrecorder.KinesisRecorder

public class KinesisRecorder
extends java.lang.Object

The KinesisRecorder is a high level client meant for storing PutRecordRequests on the users Android device. This allows developers to retain requests when the device is offline. It can also increase performance and battery efficiency since the wi-fi or cell network does not need to be woken up as frequently. Note: KinesisRecorder uses all synchronous calls regardless of the AmazonKinesisClient passed in. Therefore you should not call KinesisRecorder methods on the main thread. To use KinesisRecorder create an AmazonKinesisClient and an directory that is private to your application. The directory passed should be empty the first time you instantiate KinesisRecorder, and should only be used for KinesisRecorder to prevent collision. Additionally you may pass an instance of KinesisRecorderConfig in order to set parameters on KinesisRecorder (Such as the maximum amount of storage KinesisRecorder may use). Warning: You should not create multiple KinesisRecorders given the same directory. Doing so is an error and behavior is undefined. Note: KinesisRecorder stores the requests in plain-text, and does not perform additional security measures outside of what the Android OS offers by default. Therefore it is recommended you pass a directory that is only visible to your application, and additionally do not store highly sensitive information using Kinesis Recorder.


Constructor Summary
KinesisRecorder(java.io.File directory, Regions region, AWSCredentialsProvider credentialsProvider)
          Constructs a new Kinesis Recorder specifying a directory that Kinesis Recorder has exclusive access to for storing requests.
KinesisRecorder(java.io.File directory, Regions region, AWSCredentialsProvider credentialsProvider, KinesisRecorderConfig config)
          Constructs a new Kinesis Recorder specifying a directory that Kinesis Recorder has exclusive access to for storing requests.
 
Method Summary
 void deleteAllRecords()
          Removes all requests saved to disk in the directory provided this KinesisRecorder
 long getDiskByteLimit()
          Returns the max number of bytes that this Kinesis Recorder will store on disk.
 long getDiskBytesUsed()
          Returns the number of bytes KinesisRecorder currently has stored in the directory passed in the constructor
 KinesisRecorderConfig getKinesisRecorderConfig()
          Returns the KinesisRecorderConfig this Kinesis Recorder is using.
 void saveRecord(byte[] data, java.lang.String streamName)
          Saves a record to local storage to be sent later.
 void submitAllRecords()
          Submits all requests saved to Amazon Kinesis.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KinesisRecorder

public KinesisRecorder(java.io.File directory,
                       Regions region,
                       AWSCredentialsProvider credentialsProvider)
Constructs a new Kinesis Recorder specifying a directory that Kinesis Recorder has exclusive access to for storing requests. Note: Kinesis Recorder is synchronous, and it's methods should not be called on the main thread. Note: Kinesis Recorder stores requests in plain-text, we recommend using a directory that is only readable by your application and not storing highly sensitive information in requests stored by Kinesis Recorder.

Parameters:
credentialsProvider - The credentials provider to use when making requests to AWS
region - The region of Amazon Kinesis this Recorder should save and send requests to.
directory - An empty directory KinesisRecorder can use for storing requests.

KinesisRecorder

public KinesisRecorder(java.io.File directory,
                       Regions region,
                       AWSCredentialsProvider credentialsProvider,
                       KinesisRecorderConfig config)
Constructs a new Kinesis Recorder specifying a directory that Kinesis Recorder has exclusive access to for storing requests. Allows specifying various aspects of Kinesis Recorder through the KinesisRecorderConfig parameter. Note: Kinesis Recorder is synchronous, and it's methods should not be called on the main thread. Note: Kinesis Recorder stores requests in plain-text, we recommend using a directory that is only readable by your application and not storing highly sensitive information in requests stored by Kinesis Recorder.

Parameters:
credentialsProvider - The credentials provider to use when making requests to AWS
region - The region of Amazon Kinesis this Recorder should save and send requests to.
directory - An empty directory KinesisRecorder can use for storing requests.
config - Allows configuring various parameters of the recorder
Method Detail

saveRecord

public void saveRecord(byte[] data,
                       java.lang.String streamName)
Saves a record to local storage to be sent later. The record will be submitted to the streamName provided with a randomly generated partition key to ensure equal distribution across shards. Note: Since operation involves file I/O it is recommended not to call this method on the main thread to ensure responsive applications.

Parameters:
data - The data to submit to the stream
streamName - The stream to submit the data to.

submitAllRecords

public void submitAllRecords()
Submits all requests saved to Amazon Kinesis. Requests that are successfully sent will be deleted from the device. Requests that fail due to the device being offline will stop the submission process and be kept. Requests that fail due to other reasons (such as the request being invalid) will be deleted. Note: Since KinesisRecorder uses synchronous methods to make calls to Amazon Kinesis, do not call submitAll() on the main thread of your application.

Throws:
AmazonClientException - Thrown if there was an unrecoverable error during submission. Note: If the request appears to be invalid, the record will be deleted. If the request appears to be valid, it will be kept.

deleteAllRecords

public void deleteAllRecords()
Removes all requests saved to disk in the directory provided this KinesisRecorder


getDiskBytesUsed

public long getDiskBytesUsed()
Returns the number of bytes KinesisRecorder currently has stored in the directory passed in the constructor

Returns:
long The number of bytes used

getDiskByteLimit

public long getDiskByteLimit()
Returns the max number of bytes that this Kinesis Recorder will store on disk. This is the same as specified in getMaxStorageSize() in the KinesisRecorderConfig, either the one passed into the constructor or the default one that was constructed.

Returns:
The number of bytes allowed

getKinesisRecorderConfig

public KinesisRecorderConfig getKinesisRecorderConfig()
Returns the KinesisRecorderConfig this Kinesis Recorder is using. This is either the config passed into the constructor or the default one if one was not specified

Returns:
The KinesisRecorderConfig


Copyright © 2010 Amazon Web Services, Inc. All Rights Reserved.