Class AnjayAttrStorage


  • public final class AnjayAttrStorage
    extends java.lang.Object
    Attribute 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 AnjayAttrStorage install​(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.
      boolean isModified()
      Checks whether the Attribute Storage has been modified since last successful call to persist() or restore().
      void persist​(java.io.OutputStream outputStream)
      Dumps all set attributes to the output stream.
      void purge()
      Removes all attributes from all entities, leaving the Attribute Storage in an empty state.
      void restore​(java.io.InputStream inputStream)
      Attempts to restore attribute storage from specified input stream.
      void setInstanceAttrs​(int ssid, int oid, int iid, AnjayAttributes.ObjectInstanceAttrs attrs)
      Sets Instance level attributes for the specified SSID.
      void setObjectAttrs​(int ssid, int oid, AnjayAttributes.ObjectInstanceAttrs attrs)
      Sets Object level attributes for the specified SSID.
      void setResourceAttrs​(int ssid, int oid, int iid, int rid, AnjayAttributes.ResourceAttrs attrs)
      Sets Resource level attributes for the specified SSID.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 AnjayObjectAttrHandlers interface.

        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.Exception
        Sets 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 be null).
        Throws:
        java.lang.Exception - If setting the attributes failed or the object implements AnjayObjectAttrHandlers interface.
      • setInstanceAttrs

        public void setInstanceAttrs​(int ssid,
                                     int oid,
                                     int iid,
                                     AnjayAttributes.ObjectInstanceAttrs attrs)
                              throws java.lang.Exception
        Sets 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 be null).
        Throws:
        java.lang.Exception - If setting the attributes failed or the object implements AnjayObjectAttrHandlers interface.
      • setResourceAttrs

        public void setResourceAttrs​(int ssid,
                                     int oid,
                                     int iid,
                                     int rid,
                                     AnjayAttributes.ResourceAttrs attrs)
                              throws java.lang.Exception
        Sets 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 be null).
        Throws:
        java.lang.Exception - If setting the attributes failed or the object implements AnjayObjectAttrHandlers interface.
      • persist

        public void persist​(java.io.OutputStream outputStream)
                     throws java.lang.Exception
        Dumps 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.Exception
        Attempts 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 return true.

        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.
      • isModified

        public boolean isModified()
        Checks whether the Attribute Storage has been modified since last successful call to persist() or restore().
        Returns:
        true if Attribute Storage has been modified, false otherwise.