Class SessionStorage
java.lang.Object
de.craftsblock.craftsnet.api.session.SessionStorage
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumIndicating the type of job theSessionStorageis performing. -
Constructor Summary
ConstructorsConstructorDescriptionSessionStorage(Session session) Constructs a newSessionStorageinstance for managing the specified session. -
Method Summary
Modifier and TypeMethodDescriptionbooleanavailableOrQueue(SessionStorage.JobType type, Object... args) Checks if the session file is busy.protected voiddestroy()Deletes the persistent session data holder using the currently setdriver.booleanexists()Checks if the session exists in the underlyingdriver.Retrieves theSessionDriverinstance associated with this session file.Retrieves theSessioninstance associated with this session file.booleanisBusy()Checks whether the session file is currently busy with an operation.voidload()Loads the sessions data using the currently setdriver.voidmigrate(SessionDriver driver) voidsave()Saves the sessions data using the currently setdriver.static voidsetDefaultDriver(SessionDriver defaultDriver) Changes the defaultSessionDriverthat will be used when creating sessions.
-
Constructor Details
-
SessionStorage
Constructs a newSessionStorageinstance for managing the specified session.- Parameters:
session- the session associated with this file handler.
-
-
Method Details
-
setDefaultDriver
Changes the defaultSessionDriverthat will be used when creating sessions.NOTE: This method will change in future releases so use with caution.
- Parameters:
defaultDriver- The new defaultSessionDriver.- Since:
- 3.3.5-SNAPSHOT
-
exists
public boolean exists()Checks if the session exists in the underlyingdriver.- Returns:
trueif the session exists in thedriver,falseotherwise.- Since:
- 3.4.0-SNAPSHOT
-
load
public void load() -
save
public void save() -
destroy
protected void destroy() -
migrate
Migrates this session from the currently setdriverto anotherdriver. If thestorageis currently busy, the migrate action will be queued and performed later on.- Parameters:
driver- The newSessionDriver.- Since:
- 3.3.5-SNAPSHOT
-
availableOrQueue
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:
trueif the runnable was queued,falseif 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:
trueif the session file is busy, otherwisefalse.
-
getDriver
Retrieves theSessionDriverinstance associated with this session file.- Returns:
- The associated
SessionDriver. - Since:
- 3.3.5-SNAPSHOT
-
getSession
Retrieves theSessioninstance associated with this session file.- Returns:
- The associated
Session.
-