public class AWSS3StateHandler extends AlexaSessionStateHandler
Constructor and Description |
---|
AWSS3StateHandler(com.amazon.speech.speechlet.Session session,
com.amazonaws.services.s3.AmazonS3 awsClient,
String bucketName)
Takes the Alexa session and an AWS client set up for the AWS region the given bucket is in.
|
AWSS3StateHandler(com.amazon.speech.speechlet.Session session,
String bucketName)
Takes the Alexa session.
|
Modifier and Type | Method and Description |
---|---|
boolean |
exists(String id,
AlexaScope scope)
Looks for a state object with the given id in the given scope.
|
com.amazonaws.services.s3.AmazonS3 |
getAwsClient()
Returns the AWS connection client used to write to and read from files in S3 bucket.
|
String |
getBucketName()
Returns the name of the S3 bucket which is used by this handler to store JSON files with
model states.
|
<TModel extends AlexaStateModel> |
readModels(Class<TModel> modelClass,
Collection<String> ids)
Reads out models from the persistence store of this handler.
|
Map<String,AlexaStateObject> |
readValues(Map<String,AlexaScope> idsInScope)
Reads multiple single object values from the persistence store in scopes.
|
void |
removeValues(Collection<String> ids)
Removes multiple value states from the persistence store with given keys used
when those values were written in store.
|
AWSS3StateHandler |
withUserId(String userId)
sets the userId used as a key when storing user-scoped model-state
If no userId is provided the handler will use userId coming in with the session
Note, the userId from Alexa will change when a user re-enables your skill
|
void |
writeModels(Collection<? extends AlexaStateModel> models)
The given models will be saved in the persistence store according to their
AlexaStateSave -annotations. |
void |
writeValues(Collection<? extends AlexaStateObject> stateObjects)
Values of given state objects will be saved with their ids in the persistence store.
|
createModel, createModel, exists, exists, exists, exists, exists, getSession, getUserId, readModel, readModel, readValue, readValue, readValues, readValues, removeModel, removeModels, removeValue, setUserId, writeModel, writeValue, writeValue, writeValue
public AWSS3StateHandler(com.amazon.speech.speechlet.Session session, String bucketName)
session
- The Alexa session of your current skill invocation.bucketName
- The bucket where all saved states will go into.public AWSS3StateHandler(com.amazon.speech.speechlet.Session session, com.amazonaws.services.s3.AmazonS3 awsClient, String bucketName)
session
- The Alexa session of your current skill invocation.awsClient
- An AWS client capable of getting and putting objects to the given bucket.bucketName
- The bucket where all saved states will go into.public com.amazonaws.services.s3.AmazonS3 getAwsClient()
public String getBucketName()
public AWSS3StateHandler withUserId(String userId)
withUserId
in class AlexaSessionStateHandler
userId
- userId used as a key when storing user-scoped model-statepublic void writeModels(Collection<? extends AlexaStateModel> models) throws AlexaStateException
AlexaStateSave
-annotations.
If you set up an Id for the model it will be accessible with it on later reads to the handler.
If you have multiple models to save always prefer this method as it tries to batch process
the models so it reduces the number of write-transactions to one.writeModels
in interface AlexaStateHandler
writeModels
in class AlexaSessionStateHandler
models
- list of models to save stateAlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelpublic void writeValues(Collection<? extends AlexaStateObject> stateObjects) throws AlexaStateException
writeValues
in interface AlexaStateHandler
writeValues
in class AlexaSessionStateHandler
stateObjects
- the state objects to write to the persistence storeAlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelpublic void removeValues(Collection<String> ids) throws AlexaStateException
removeValues
in interface AlexaStateHandler
removeValues
in class AlexaSessionStateHandler
ids
- the keys of single value objects whose state you want to remove from the store.AlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelpublic boolean exists(String id, AlexaScope scope) throws AlexaStateException
exists
in interface AlexaStateHandler
exists
in class AlexaSessionStateHandler
id
- id of a state-object whose existence you want to be checked in the store.scope
- look for state-object in that scope.AlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelpublic <TModel extends AlexaStateModel> Map<String,TModel> readModels(Class<TModel> modelClass, Collection<String> ids) throws AlexaStateException
AlexaScope
s configured in
the AlexaStateSave
annotations it will possibly collect data from more than one persistence store. (most
likely from the Alexa session and maybe from the permanent persistence store associated with this handler.)
You are providing ids with this call. If you never saved any model with one of the ids in the store you won't get them.readModels
in interface AlexaStateHandler
readModels
in class AlexaSessionStateHandler
TModel
- Type derived from AlexaStateModel
modelClass
- Type of the model you would like to read out. It needs to be of type AlexaStateModel
.ids
- Collection of ids of existing instances of your model in the persistence store. If you provide ids of non-existing items they just won't show up in the returned map.AlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelpublic Map<String,AlexaStateObject> readValues(Map<String,AlexaScope> idsInScope) throws AlexaStateException
readValues
in interface AlexaStateHandler
readValues
in class AlexaSessionStateHandler
idsInScope
- ids with scope of state-objects whose state you want to read from the store.AlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelCopyright © 2017. All rights reserved.