Class LocalFileUserAccessor

  • All Implemented Interfaces:
    IUserAccessor, SnapshotProcessor

    public class LocalFileUserAccessor
    extends java.lang.Object
    implements IUserAccessor
    This class loads a user's information from the corresponding file.The user file is a sequential file. User file schema: Int32 username bytes size Utf-8 username bytes Int32 Password bytes size Utf-8 password bytes Int32 seriesPath privilege number n Int32 seriesPath[1] size Utf-8 seriesPath[1] bytes Int32 privilege num k1 Int32 privilege[1][1] Int32 privilege[1][2] ... Int32 privilege[1][k1] Int32 seriesPath[2] size Utf-8 seriesPath[2] bytes Int32 privilege num k2 Int32 privilege[2][1] Int32 privilege[2][2] ... Int32 privilege[2][k2] ... Int32 seriesPath[n] size Utf-8 seriesPath[n] bytes Int32 privilege num kn Int32 privilege[n][1] Int32 privilege[n][2] ... Int32 privilege[n][kn] Int32 user name number m Int32 user name[1] size Utf-8 user name[1] bytes Int32 user name[2] size Utf-8 user name[2] bytes ... Int32 user name[m] size Utf-8 user name[m] bytes
    • Constructor Summary

      Constructors 
      Constructor Description
      LocalFileUserAccessor​(java.lang.String userDirPath)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean deleteUser​(java.lang.String username)
      Delete a user's user file.
      java.lang.String getDirPath()
      get UserDirPath
      java.util.List<java.lang.String> listAllUsers()
      List all users existing in the database.
      User loadUser​(java.lang.String username)
      Deserialize a user from its user file.
      void processLoadSnapshot​(java.io.File snapshotDir)
      Load snapshot
      boolean processTakeSnapshot​(java.io.File snapshotDir)
      Take snapshot
      void reset()
      Re-initialize this object.
      void saveUser​(User user)
      Serialize the user object to a temp file, then replace the old user file with the new file.
      • Methods inherited from class java.lang.Object

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

      • LocalFileUserAccessor

        public LocalFileUserAccessor​(java.lang.String userDirPath)
    • Method Detail

      • loadUser

        public User loadUser​(java.lang.String username)
                      throws java.io.IOException
        Deserialize a user from its user file.
        Specified by:
        loadUser in interface IUserAccessor
        Parameters:
        username - The name of the user to be deserialized.
        Returns:
        The user object or null if no such user.
        Throws:
        java.io.IOException - if an exception is raised when interacting with the lower storage.
      • saveUser

        public void saveUser​(User user)
                      throws java.io.IOException
        Serialize the user object to a temp file, then replace the old user file with the new file.
        Specified by:
        saveUser in interface IUserAccessor
        Parameters:
        user - The user object that is to be saved.
        Throws:
        java.io.IOException - if an exception is raised when interacting with the lower storage.
      • deleteUser

        public boolean deleteUser​(java.lang.String username)
                           throws java.io.IOException
        Delete a user's user file.
        Specified by:
        deleteUser in interface IUserAccessor
        Parameters:
        username - The name of the user to be deleted.
        Returns:
        True if the file is successfully deleted, false if the file does not exists.
        Throws:
        java.io.IOException - when the file cannot be deleted.
      • listAllUsers

        public java.util.List<java.lang.String> listAllUsers()
        Description copied from interface: IUserAccessor
        List all users existing in the database.
        Specified by:
        listAllUsers in interface IUserAccessor
        Returns:
        A list that contains names of all users.
      • processTakeSnapshot

        public boolean processTakeSnapshot​(java.io.File snapshotDir)
                                    throws org.apache.thrift.TException,
                                           java.io.IOException
        Description copied from interface: SnapshotProcessor
        Take snapshot
        Specified by:
        processTakeSnapshot in interface SnapshotProcessor
        Parameters:
        snapshotDir - Where snapshot files are stored.
        Returns:
        Whether the snapshot is successfully executed
        Throws:
        org.apache.thrift.TException - Exception occurred during the thrift serialize struct
        java.io.IOException - Exception related to file read and write
      • processLoadSnapshot

        public void processLoadSnapshot​(java.io.File snapshotDir)
                                 throws org.apache.thrift.TException,
                                        java.io.IOException
        Description copied from interface: SnapshotProcessor
        Load snapshot
        Specified by:
        processLoadSnapshot in interface SnapshotProcessor
        Parameters:
        snapshotDir - Load snapshot from here
        Throws:
        org.apache.thrift.TException - Exception occurred during the thrift deserialize struct
        java.io.IOException - Exception related to file read and write
      • reset

        public void reset()
        Description copied from interface: IUserAccessor
        Re-initialize this object.
        Specified by:
        reset in interface IUserAccessor
      • getDirPath

        public java.lang.String getDirPath()
        Description copied from interface: IUserAccessor
        get UserDirPath
        Specified by:
        getDirPath in interface IUserAccessor
        Returns:
        userDirPath