Class SessionStorage

java.lang.Object
de.craftsblock.craftsnet.api.session.SessionStorage

public class SessionStorage extends Object
Handles the persistence of session data by providing functionality for loading, saving, and destroying session files. The session data is serialized to a file and deserialized back into memory, allowing for session state preservation between application runs.

The SessionStorage class ensures data integrity through file locking mechanisms and supports thread-safe operations by preventing concurrent modifications.

Session files are stored in a predefined directory, and their filenames are constructed using the session identifier.

Since:
3.3.0-SNAPSHOT
See Also:
  • Constructor Details

    • SessionStorage

      public SessionStorage(Session session)
      Constructs a new SessionStorage instance for managing the specified session.
      Parameters:
      session - the session associated with this file handler.
  • Method Details

    • setDefaultDriver

      @Experimental public static void setDefaultDriver(SessionDriver defaultDriver)
      Changes the default SessionDriver that will be used when creating sessions.

      NOTE: This method will change in future releases so use with caution.

      Parameters:
      defaultDriver - The new default SessionDriver.
      Since:
      3.3.5-SNAPSHOT
    • exists

      public boolean exists()
      Checks if the session exists in the underlying driver.
      Returns:
      true if the session exists in the driver, false otherwise.
      Since:
      3.4.0-SNAPSHOT
    • load

      public void load()
      Loads the sessions data using the currently set driver. If the storage is currently busy, the load action will be queued and performed later on.
    • save

      public void save()
      Saves the sessions data using the currently set driver. If the storage is currently busy, the save action will be queued and performed later on.
    • destroy

      protected void destroy()
      Deletes the persistent session data holder using the currently set driver. If the storage is currently busy, the destroy action will be queued and performed later on.
    • migrate

      public void migrate(SessionDriver driver)
      Migrates this session from the currently set driver to another driver. If the storage is currently busy, the migrate action will be queued and performed later on.
      Parameters:
      driver - The new SessionDriver.
      Since:
      3.3.5-SNAPSHOT
    • availableOrQueue

      public boolean availableOrQueue(SessionStorage.JobType type, Object... args)
      Checks if the session file is busy. If busy, queues the action for execution once the current job is completed.
      Parameters:
      type - The action to queue for later execution.
      args - The args which should be passed to the driver.
      Returns:
      true if the runnable was queued, false if the manager was not busy and no action was queued.
    • isBusy

      public boolean isBusy()
      Checks whether the session file is currently busy with an operation.
      Returns:
      true if the session file is busy, otherwise false.
    • getDriver

      public SessionDriver getDriver()
      Retrieves the SessionDriver instance associated with this session file.
      Returns:
      The associated SessionDriver.
      Since:
      3.3.5-SNAPSHOT
    • getSession

      public Session getSession()
      Retrieves the Session instance associated with this session file.
      Returns:
      The associated Session.