Class AnjayServerObject


  • public final class AnjayServerObject
    extends java.lang.Object
    Default implementation of LwM2M Server Object (/1).
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  AnjayServerObject.Instance
      Instance of LwM2M Server Object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int addInstance​(AnjayServerObject.Instance instance)
      Adds new Instance of Server Object and returns newly created Instance ID.
      int addInstance​(AnjayServerObject.Instance instance, int preferredIid)
      Overload of addInstance(Instance), but allows to specify preferred Instance ID.
      static AnjayServerObject install​(Anjay anjay)
      Installs the Server Object in an Anjay instance.
      boolean isModified()
      Checks whether the Server Object from Anjay instance has been modified since last successful call to persist() or restore.
      void persist​(java.io.OutputStream outputStream)
      Dumps Server Object Instances into the outputStream.
      void purge()
      Removes all instances of Server Object leaving it in an empty state.
      void restore​(java.io.InputStream inputStream)
      Attempts to restore Server Object Instances from specified inputStream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • install

        public static AnjayServerObject install​(Anjay anjay)
                                         throws java.lang.Exception
        Installs the Server Object in an Anjay instance.
        Parameters:
        anjay - Anjay instance for which the Server Object is installed.
        Returns:
        Server object which may be used to manage its instances.
        Throws:
        java.lang.Exception - In case of error.
      • addInstance

        public int addInstance​(AnjayServerObject.Instance instance)
                        throws java.lang.Exception
        Adds new Instance of Server Object and returns newly created Instance ID.
        Parameters:
        instance - Server Instance to insert.
        Returns:
        ID of the added instance.
        Throws:
        java.lang.Exception - If instance can't be added.
      • addInstance

        public int addInstance​(AnjayServerObject.Instance instance,
                               int preferredIid)
                        throws java.lang.Exception
        Overload of addInstance(Instance), but allows to specify preferred Instance ID.

        Note: if preferredIid is set to Anjay.ID_INVALID then the Instance ID is generated automatically.

        Parameters:
        instance - Server Instance to insert.
        preferredIid - Preferred Instance ID to be set.
        Returns:
        ID of the added instance.
        Throws:
        java.lang.Exception - If instance can't be added.
      • purge

        public void purge()
        Removes all instances of Server Object leaving it in an empty state.
      • persist

        public void persist​(java.io.OutputStream outputStream)
                     throws java.lang.Exception
        Dumps Server Object Instances into the outputStream.
        Parameters:
        outputStream - Stream to write to.
        Throws:
        java.lang.Exception - If instances can't be persisted.
      • restore

        public void restore​(java.io.InputStream inputStream)
                     throws java.lang.Exception
        Attempts to restore Server Object Instances from specified inputStream.

        Note: if restore fails, then Server Object will be left untouched, on success though all Instances stored within the Object will be purged.

        Parameters:
        inputStream - Stream to read from.
        Throws:
        java.lang.Exception - If instances can't be restored.
      • isModified

        public boolean isModified()
        Checks whether the Server Object from Anjay instance has been modified since last successful call to persist() or restore.
        Returns:
        true if Server Object has beed modified, false otherwise.