Interface AnjayObject
-
public interface AnjayObjectInterface specifying handlers for operations on Object's Instances and Resources.LwM2M Object may also implement
AnjayObjectAttrHandlersinterface.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classAnjayObject.ResourceDefObject's Resource definition.static classAnjayObject.ResourceKindKind of a Resource - indicates allowed operations.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidinstanceCreate(int iid)A handler that creates an Object Instance.default voidinstanceRemove(int iid)A handler that removes an Object Instance with given Instance ID.default voidinstanceReset(int iid)A handler that shall reset Object Instance to its default (after creational) state.java.util.SortedSet<java.lang.Integer>instances()A handler that returns all Object Instances for the Object.intoid()A handler that returns Object ID.default voidresourceExecute(int iid, int rid, java.util.Map<java.lang.Integer,java.util.Optional<java.lang.String>> args)A handler that performs the Execute action on given Resource, called only if the Resource is PRESENT and of theAnjayObject.ResourceKind.Ekind (as returned byresources(int)).default java.util.SortedSet<java.lang.Integer>resourceInstances(int iid, int rid)A handler that returns all Resource Instances of a Multiple Resource, called only if the Resource is PRESENT and is of eitherAnjayObject.ResourceKind.RM,AnjayObject.ResourceKind.WMorAnjayObject.ResourceKind.RWMkind (as returned byresources(int)).default voidresourceRead(int iid, int rid, int riid, AnjayOutputContext context)A handler that reads the Resource Instance value, called only if the Resource is PRESENT and is one of theAnjayObject.ResourceKind.RMorAnjayObject.ResourceKind.RWMkinds (as returned byresources(int)) andriidwas returned byresourceInstances(int,int).default voidresourceRead(int iid, int rid, AnjayOutputContext context)A handler that reads the Resource value, called only if the Resource is PRESENT and is one of theAnjayObject.ResourceKind.RorAnjayObject.ResourceKind.RWkinds (as returned byresources(int)).default voidresourceReset(int iid, int rid)A handler that shall reset a Resource to its default (after creational) state.default java.util.SortedSet<AnjayObject.ResourceDef>resources(int iid)A handler that returns SUPPORTED Resources for an Object Instance, called only if the Object Instance is PRESENT (has recently been returned viainstances()).default voidresourceWrite(int iid, int rid, int riid, AnjayInputContext context)A handler that writes the Resource Instance value, called only if the Resource is SUPPORTED and is one of theAnjayObject.ResourceKind.RMorAnjayObject.ResourceKind.RWMkind (as returned byresources(int)) andriidwas returned byresourceInstances(int,int).default voidresourceWrite(int iid, int rid, AnjayInputContext context)A handler that writes the Resource value, called only if the Resource is SUPPORTED and not of theAnjayObject.ResourceKind.Ekind (as returned byresources(int)).default voidtransactionBegin()A handler that is called when there is a request that might modify an Object and fail.default voidtransactionCommit()A handler that is called after transaction is finished.default voidtransactionRollback()A handler that is called whenever there is a need to restore previous Object state during a transaction or during committing a transaction.default voidtransactionValidate()A handler that is called after transaction is finished, but beforetransactionCommit()is called.default java.lang.Stringversion()A handler that returns version of the object.
-
-
-
Method Detail
-
oid
int oid()
A handler that returns Object ID.- Returns:
- Object ID.
-
version
default java.lang.String version()
A handler that returns version of the object.- Returns:
- Version of the object as string. If not implemented,
"1.0"is returned by default.
-
instances
java.util.SortedSet<java.lang.Integer> instances()
A handler that returns all Object Instances for the Object.- Returns:
SortedSetwith Instance IDs.
-
instanceReset
default void instanceReset(int iid) throws java.lang.ExceptionA handler that shall reset Object Instance to its default (after creational) state.Note: if this handler is not implemented, then non-partial write on the Object Instance will not succeed.
- Parameters:
iid- Instance ID to reset.- Throws:
java.lang.Exception- In case of error. IfAnjayExceptionis thrown with one of defined error codes, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.
-
instanceCreate
default void instanceCreate(int iid) throws java.lang.ExceptionA handler that creates an Object Instance.Note: if this handler is not implemented, LwM2M Server won't be able to create a new object instance.
- Parameters:
iid- Instance ID to create, chosen either by the server or the library. An ID that has been previously checked to not be PRESENT is guaranteed to be passed.- Throws:
java.lang.Exception- In case of error. IfAnjayExceptionis thrown with one of defined error codes, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.
-
instanceRemove
default void instanceRemove(int iid) throws java.lang.ExceptionA handler that removes an Object Instance with given Instance ID.Note: if this handler is not implemented, LwM2M Server won't be able to remove an object instance.
- Parameters:
iid- Checked Object Instance ID.- Throws:
java.lang.Exception- In case of error. IfAnjayExceptionis thrown with one of defined error codes, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.
-
resources
default java.util.SortedSet<AnjayObject.ResourceDef> resources(int iid)
A handler that returns SUPPORTED Resources for an Object Instance, called only if the Object Instance is PRESENT (has recently been returned viainstances()).- Parameters:
iid- Object Instance ID.- Returns:
SortedSetwith Resource definitions.
-
resourceRead
default void resourceRead(int iid, int rid, AnjayOutputContext context) throws java.lang.ExceptionA handler that reads the Resource value, called only if the Resource is PRESENT and is one of theAnjayObject.ResourceKind.RorAnjayObject.ResourceKind.RWkinds (as returned byresources(int)).If not implemented, Method Not Allowed CoAP code is sent in response.
- Parameters:
iid- Object Instance ID.rid- Resource ID.context- Output context to write the resource value to. One of theret*methods MUST be called in this handler before returning successfully. Failure to do so will result in 5.00 Internal Server Error being sent to the server.- Throws:
java.lang.Exception- In case of error. IfAnjayExceptionis thrown with one of defined error codes, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.
-
resourceRead
default void resourceRead(int iid, int rid, int riid, AnjayOutputContext context) throws java.lang.ExceptionA handler that reads the Resource Instance value, called only if the Resource is PRESENT and is one of theAnjayObject.ResourceKind.RMorAnjayObject.ResourceKind.RWMkinds (as returned byresources(int)) andriidwas returned byresourceInstances(int,int).If not implemented, Method Not Allowed CoAP code is sent in response.
- Parameters:
iid- Object Instance ID.rid- Resource ID.riid- Resource Instance ID.context- Output context to write the resource value to. One of theret*methods MUST be called in this handler before returning successfully. Failure to do so will result in 5.00 Internal Server Error being sent to the server.- Throws:
java.lang.Exception- In case of error. IfAnjayExceptionis thrown with one of defined error codes, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.
-
resourceWrite
default void resourceWrite(int iid, int rid, AnjayInputContext context) throws java.lang.ExceptionA handler that writes the Resource value, called only if the Resource is SUPPORTED and not of theAnjayObject.ResourceKind.Ekind (as returned byresources(int)). Note that it may be called on nominally read-only Resources if the write is performed by the Bootstrap Server.If not implemented, Method Not Allowed CoAP code is sent in response.
- Parameters:
iid- Object Instance ID.rid- Resource ID.context- Input context to read the resource value from using theget*methods.- Throws:
java.lang.Exception- In case of error. IfAnjayExceptionis thrown with one of defined error codes, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.
-
resourceWrite
default void resourceWrite(int iid, int rid, int riid, AnjayInputContext context) throws java.lang.ExceptionA handler that writes the Resource Instance value, called only if the Resource is SUPPORTED and is one of theAnjayObject.ResourceKind.RMorAnjayObject.ResourceKind.RWMkind (as returned byresources(int)) andriidwas returned byresourceInstances(int,int). Note that it may be called on nominally read-only Resources if the write is performed by the Bootstrap Server.If not implemented, Method Not Allowed CoAP code is sent in response.
- Parameters:
iid- Object Instance ID.rid- Resource ID.riid- Resource Instance ID.context- Input context to read the resource value from using theget*methods.- Throws:
java.lang.Exception- In case of error. IfAnjayExceptionis thrown with one of defined error codes, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.
-
resourceExecute
default void resourceExecute(int iid, int rid, java.util.Map<java.lang.Integer,java.util.Optional<java.lang.String>> args) throws java.lang.ExceptionA handler that performs the Execute action on given Resource, called only if the Resource is PRESENT and of theAnjayObject.ResourceKind.Ekind (as returned byresources(int)).If not implemented, Method Not Allowed CoAP code is sent in response.
- Parameters:
iid- Object Instance ID.rid- Resource ID.args- Arguments for the execute command.- Throws:
java.lang.Exception- In case of error. IfAnjayExceptionis thrown with one of defined error codes, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.
-
resourceReset
default void resourceReset(int iid, int rid) throws java.lang.ExceptionA handler that shall reset a Resource to its default (after creational) state. In particular, for any writeable optional resource, it shall remove it; for any writeable mandatory Multiple Resource, it shall remove all its instances.NOTE: If this handler is not implemented for a Multiple Resource, then non-partial write on it will not succeed.
NOTE: In the current version of Anjay, this handler is only ever called on Multiple Resources. It is REQUIRED so that after calling this handler, any Multiple Resource is either not PRESENT, or PRESENT, but contain zero Resource Instances.
- Parameters:
iid- Object Instance ID.rid- ID of the Resource to reset.- Throws:
java.lang.Exception- In case of error. IfAnjayExceptionis thrown with one of defined error codes, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.
-
resourceInstances
default java.util.SortedSet<java.lang.Integer> resourceInstances(int iid, int rid) throws java.lang.ExceptionA handler that returns all Resource Instances of a Multiple Resource, called only if the Resource is PRESENT and is of eitherAnjayObject.ResourceKind.RM,AnjayObject.ResourceKind.WMorAnjayObject.ResourceKind.RWMkind (as returned byresources(int)).- Parameters:
iid- Object Instance ID.rid- Resource ID.- Returns:
SortedSetwith Resource Instance IDs.- Throws:
java.lang.Exception- In case of error. IfAnjayExceptionis thrown with one of defined error codes, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.
-
transactionBegin
default void transactionBegin() throws java.lang.ExceptionA handler that is called when there is a request that might modify an Object and fail. Such situation often requires to rollback changes, and this handler shall implement logic that prepares for possible failure in the future.Handlers listed below are NOT called without beginning transaction in the first place (note that if an Object does not implement transaction handlers, then it will not be possible to perform operations listed below):
instanceCreate(int),instanceRemove(int),instanceReset(int),resourceWrite(int,int,com.avsystem.anjay.AnjayInputContext),resourceWrite(int,int,int,com.avsystem.anjay.AnjayInputContext),resourceReset(int,int),transactionCommit(),transactionRollback().
Note: if an error occurs during a transaction (i.e. after successful call of this function) then the rollback handler
transactionRollback()will be executed by the library.- Throws:
java.lang.Exception- In case of error. IfAnjayExceptionis thrown with one of defined error codes, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.
-
transactionValidate
default void transactionValidate() throws java.lang.ExceptionA handler that is called after transaction is finished, but beforetransactionCommit()is called. It is used to check whether the commit operation may be successfully performed.Any validation of the object's state shall be performed in this function, rather than in the commit handler. If there is a need to commit changes to multiple objects at once, this handler is called on all modified objects first, to avoid potential inconsistencies that may arise from a failing commit operation.
Successfully returning from this handler means that the corresponding commit function shall subsequently execute successfully. The commit handler may nevertheless fail, but if and only if a fatal, unpredictable and irrecoverable error (e.g. physical write error) occurs.
- Throws:
java.lang.Exception- In case of error. IfAnjayExceptionis thrown with one of defined error codes, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.
-
transactionCommit
default void transactionCommit() throws java.lang.ExceptionA handler that is called after transaction is finished. If it fails thentransactionRollback()handler must be called by the user code if it is necessary.NOTE: If this function fails, the data model will be left in an inconsistent state. For this reason, it may return an error value if and only if a fatal, unpredictable and irrecoverable error (e.g. physical write error) occurs. All other errors (such as invalid object state) shall be reported via
transactionValidate().- Throws:
java.lang.Exception- In case of error. IfAnjayExceptionis thrown with one of defined error codes, the response message will have an appropriate CoAP response code. Otherwise, the device will respond with an unspecified (but valid) error code.
-
transactionRollback
default void transactionRollback() throws java.lang.ExceptionA handler that is called whenever there is a need to restore previous Object state during a transaction or during committing a transaction.- Throws:
java.lang.Exception- In case of error.
-
-