Class AnjayAttrStorage
- java.lang.Object
-
- com.avsystem.anjay.AnjayAttrStorage
-
public final class AnjayAttrStorage extends java.lang.ObjectAttribute Storage module. Manages attributes for LwM2M Objects, their instances and resources.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static AnjayAttrStorageinstall(Anjay anjay)Installs the Attribute Storage handlers in an Anjay object, making it possible to automatically manage attributes for LwM2M Objects, their instances and resources.booleanisModified()voidpersist(java.io.OutputStream outputStream)Dumps all set attributes to the output stream.voidpurge()Removes all attributes from all entities, leaving the Attribute Storage in an empty state.voidrestore(java.io.InputStream inputStream)Attempts to restore attribute storage from specified input stream.voidsetInstanceAttrs(int ssid, int oid, int iid, AnjayAttributes.ObjectInstanceAttrs attrs)Sets Instance level attributes for the specified SSID.voidsetObjectAttrs(int ssid, int oid, AnjayAttributes.ObjectInstanceAttrs attrs)Sets Object level attributes for the specified SSID.voidsetResourceAttrs(int ssid, int oid, int iid, int rid, AnjayAttributes.ResourceAttrs attrs)Sets Resource level attributes for the specified SSID.
-
-
-
Method Detail
-
install
public static AnjayAttrStorage install(Anjay anjay) throws java.lang.Exception
Installs the Attribute Storage handlers in an Anjay object, making it possible to automatically manage attributes for LwM2M Objects, their instances and resources.In accordance to the LwM2M specification, there are three levels on which attributes may be stored:
- Resource level
- Instance level
- Object level
Attribute Storage is used for the object only if it doesn't implement
AnjayObjectAttrHandlersinterface.- Parameters:
anjay- Anjay instance to install the Attribute Storage for.- Returns:
- Attribute Storage object.
- Throws:
java.lang.Exception- In case of failure.
-
purge
public void purge()
Removes all attributes from all entities, leaving the Attribute Storage in an empty state.
-
setObjectAttrs
public void setObjectAttrs(int ssid, int oid, AnjayAttributes.ObjectInstanceAttrs attrs) throws java.lang.ExceptionSets Object level attributes for the specified SSID.- Parameters:
ssid- SSID for which given Attributes shall be set (must be a valid SSID corresponding to one of the non-Bootstrap LwM2M Servers).oid- Object ID for which given Attributes shall be set.attrs- Attributes to be set (MUST NOT benull).- Throws:
java.lang.Exception- If setting the attributes failed or the object implementsAnjayObjectAttrHandlersinterface.
-
setInstanceAttrs
public void setInstanceAttrs(int ssid, int oid, int iid, AnjayAttributes.ObjectInstanceAttrs attrs) throws java.lang.ExceptionSets Instance level attributes for the specified SSID.- Parameters:
ssid- SSID for which given Attributes shall be set (must be a valid SSID corresponding to one of the non-Bootstrap LwM2M Servers).oid- Object ID for which given Attributes shall be set.iid- Instance ID for which given Attributes shall be set.attrs- Attributes to be set (MUST NOT benull).- Throws:
java.lang.Exception- If setting the attributes failed or the object implementsAnjayObjectAttrHandlersinterface.
-
setResourceAttrs
public void setResourceAttrs(int ssid, int oid, int iid, int rid, AnjayAttributes.ResourceAttrs attrs) throws java.lang.ExceptionSets Resource level attributes for the specified SSID.- Parameters:
ssid- SSID for which given Attributes shall be set (must be a valid SSID corresponding to one of the non-Bootstrap LwM2M Servers).oid- Object ID owning the specified Instance.iid- Instance ID owning the specified Resource.rid- Resource ID for which given Attributes shall be set.attrs- Attributes to be set (MUST NOT benull).- Throws:
java.lang.Exception- If setting the attributes failed or the object implementsAnjayObjectAttrHandlersinterface.
-
persist
public void persist(java.io.OutputStream outputStream) throws java.lang.ExceptionDumps all set attributes to the output stream.- Parameters:
outputStream- Stream to write to.- Throws:
java.lang.Exception- If the persist operation failed.
-
restore
public void restore(java.io.InputStream inputStream) throws java.lang.ExceptionAttempts to restore attribute storage from specified input stream.Note: before attempting restoration, the Attribute Storage is cleared, so no previously set attributes will be retained. In particular, if restore fails, then the Attribute Storage will be completely cleared and
isModified()will returntrue.NOTE: For historical reasons, this function behaves differently than all other restore methods.
- On failed restoration, the storage is cleared, rather than left untouched
- Zero-length stream is treated as valid, and causes the storage to be cleared without throwing an exception
Relying on these behaviours is DEPRECATED. Future versions of Anjay may change the semantics of this function so that it retains the contents of Attribute Storage on failure, and does not treat empty streams as valid. It is RECOMMENDED that any new code involving this function is written to work properly with both semantics.
- Parameters:
inputStream- Stream to read from.- Throws:
java.lang.Exception- If the restoration failed.
-
-