public class AWSIotStateHandler extends AlexaSessionStateHandler
Constructor and Description |
---|
AWSIotStateHandler(com.amazon.speech.speechlet.Session session) |
AWSIotStateHandler(com.amazon.speech.speechlet.Session session,
com.amazonaws.services.iot.AWSIot awsClient,
com.amazonaws.services.iotdata.AWSIotData awsDataClient) |
Modifier and Type | Method and Description |
---|---|
void |
createThingIfNotExisting(AlexaScope scope)
The thing will be created in AWS IoT if not existing for this application (when scope
APPLICATION is given) or for this user in this application (when scope USER is given)
|
boolean |
doesThingExist(AlexaScope scope)
Returns if the thing dedicated to the scope given is existing in AWS IoT.
|
com.amazonaws.services.iot.AWSIot |
getAwsClient()
Returns the AWS connection client used by this handler to manage resources
in AWS IoT.
|
String |
getThingName(AlexaScope scope)
Returns name of the thing whose shadow is updated by this handler.
|
<TModel extends AlexaStateModel> |
readModel(Class<TModel> modelClass)
Reads out the model from the persistence store of this handler.
|
<TModel extends AlexaStateModel> |
readModels(Class<TModel> modelClass,
Collection<String> ids)
Reads out models from the persistence store of this handler.
|
Optional<AlexaStateObject> |
readValue(String id,
AlexaScope scope)
Reads a single object value from the persistence store.
|
void |
removeModels(Collection<? extends AlexaStateModel> models)
The given models will be removed from the persistence store.
|
void |
removeValues(Collection<String> ids)
Removes multiple value states from the persistence store with given keys used
when those values were written in store.
|
AWSIotStateHandler |
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, exists, getSession, getUserId, readModel, readValue, readValues, readValues, readValues, removeModel, removeValue, setUserId, writeModel, writeValue, writeValue, writeValue
public AWSIotStateHandler(com.amazon.speech.speechlet.Session session)
public AWSIotStateHandler(com.amazon.speech.speechlet.Session session, com.amazonaws.services.iot.AWSIot awsClient, com.amazonaws.services.iotdata.AWSIotData awsDataClient)
public com.amazonaws.services.iot.AWSIot getAwsClient()
public AWSIotStateHandler 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 <TModel extends AlexaStateModel> Optional<TModel> readModel(Class<TModel> modelClass) 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 not providing an id with this call. Thus it will look for the single representative without an id.readModel
in interface AlexaStateHandler
readModel
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
.AlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelpublic void removeModels(Collection<? extends AlexaStateModel> models) throws AlexaStateException
removeModels
in interface AlexaStateHandler
removeModels
in class AlexaSessionStateHandler
models
- Your models which need to be a type of AlexaStateModel
AlexaStateException
- 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 <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 Optional<AlexaStateObject> readValue(String id, AlexaScope scope) throws AlexaStateException
readValue
in interface AlexaStateHandler
readValue
in class AlexaSessionStateHandler
id
- id of a state-object whose state you want to read from the store.scope
- read state-object in that scope.AlexaStateException
- Wraps all inner exceptions and gives you context related to handler and modelpublic String getThingName(AlexaScope scope) throws AlexaStateException
scope
- The scope this thing is dedicated toAlexaStateException
- Any error regarding thing name generationpublic void createThingIfNotExisting(AlexaScope scope) throws AlexaStateException
scope
- The scope this thing is dedicated toAlexaStateException
- Any error regarding thing creation or existence checkpublic boolean doesThingExist(AlexaScope scope) throws AlexaStateException
scope
- The scope this thing is dedicated toAlexaStateException
- Any error regarding thing creation or existence checkCopyright © 2017. All rights reserved.