Class FileSessionDriver

java.lang.Object
de.craftsblock.craftsnet.api.session.drivers.builtin.FileSessionDriver
All Implemented Interfaces:
SessionDriver

public class FileSessionDriver extends Object implements SessionDriver
A file based implementation of SessionDriver that persists session data to disk.

This implementation stores session data in files located in the STORAGE_LOCATION directory. Each session is saved as a file with a name based on its session ID appended with the STORAGE_EXTENSION.

Since:
3.3.5-SNAPSHOT
See Also:
  • Field Details

    • STORAGE_LOCATION

      public static final String STORAGE_LOCATION
      The default directory where session files are stored.
      See Also:
    • STORAGE_EXTENSION

      public static final String STORAGE_EXTENSION
      The file extension used for session files.
      See Also:
  • Constructor Details

    • FileSessionDriver

      public FileSessionDriver()
  • Method Details

    • exists

      public boolean exists(Session session, String sessionID)
      Check if the corresponding session file exists on the hard drive.
      Specified by:
      exists in interface SessionDriver
      Parameters:
      session - The Session instance to be populated with data.
      sessionID - The unique identifier of the session.
      Returns:
      Returns true if the session exists in the underlying storage, false otherwise.
      Since:
      3.4.0-SNAPSHOT
    • load

      public void load(Session session, String sessionID)
      Loads the session data from a file corresponding to the sessions ID.
      Specified by:
      load in interface SessionDriver
      Parameters:
      session - The session instance to populate with stored data.
      sessionID - The unique identifier of the session (the session's own ID is used to determine the file).
      Throws:
      RuntimeException - If an I/O error occurs or deserialization fails.
    • save

      public void save(Session session, String sessionID) throws IOException
      Saves the session data to a file corresponding to the sessions ID.
      Specified by:
      save in interface SessionDriver
      Parameters:
      session - The session instance containing data to be saved.
      sessionID - The unique identifier of the session (the session's own ID is used to determine the file).
      Throws:
      IOException - If an error occurs during the file write operation.
    • destroy

      public void destroy(Session session, String sessionID)
      Deletes the session file corresponding to the given session ID.
      Specified by:
      destroy in interface SessionDriver
      Parameters:
      session - The session instance (not used directly in deletion).
      sessionID - The unique identifier of the session whose file should be deleted.