Class Session
- All Implemented Interfaces:
Serializable,AutoCloseable,ConcurrentMap<String,,Object> Map<String,Object>
Manages session data, allowing the storage and retrieval of serialized objects
within a json file. The session data is stored in the specified location and
automatically serialized and deserialized when starting or stopping a session.
- Since:
- 3.3.0-SNAPSHOT
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.concurrent.ConcurrentHashMap
ConcurrentHashMap.KeySetView<K extends Object,V extends Object> Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Saves the session data to a persistent file.<T> TRetrieves the value associated with the specified key and attempts to cast it to the specified type.<T> TRetrieves the value associated with the specified key and attempts to cast it to the specified type.Retrieves theBaseExchangeinstance associated with this session.Retrieves theSessionInfoassociated with this session.Retrieves theSessionStorageassociated with this session.booleanChecks whether a session has been started.<T> booleanChecks if the value associated with the specified key is of the specified type.voidsetExchange(@NotNull BaseExchange exchange) Sets theBaseExchangeinstance for this session storage.voidStarts a new session and generates a session identifier.voidStops the current session and deletes the associated session file.Methods inherited from class java.util.concurrent.ConcurrentHashMap
clear, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, forEach, forEach, forEachEntry, forEachEntry, forEachKey, forEachKey, forEachValue, forEachValue, get, getOrDefault, hashCode, isEmpty, keys, keySet, keySet, mappingCount, merge, newKeySet, newKeySet, put, putAll, putIfAbsent, reduce, reduceEntries, reduceEntries, reduceEntriesToDouble, reduceEntriesToInt, reduceEntriesToLong, reduceKeys, reduceKeys, reduceKeysToDouble, reduceKeysToInt, reduceKeysToLong, reduceToDouble, reduceToInt, reduceToLong, reduceValues, reduceValues, reduceValuesToDouble, reduceValuesToInt, reduceValuesToLong, remove, remove, replace, replace, replaceAll, search, searchEntries, searchKeys, searchValues, size, toString, valuesMethods inherited from class java.util.AbstractMap
clone
-
Field Details
-
exchange
-
-
Constructor Details
-
Session
public Session()Creates a new instance ofSessionwithout an active session.
-
-
Method Details
-
setExchange
Sets theBaseExchangeinstance for this session storage.- Parameters:
exchange- The exchange used to load the session.- Throws:
IllegalStateException- if the session file does not exist.
-
getAsType
Retrieves the value associated with the specified key and attempts to cast it to the specified type.- Type Parameters:
T- The type parameter of the value.- Parameters:
key- The key for the value to retrieve.type- The expected type of the value.- Returns:
- The value associated with the key, or
nullif not found or cannot be cast.
-
getAsType
Retrieves the value associated with the specified key and attempts to cast it to the specified type.- Type Parameters:
T- The type parameter of the value.- Parameters:
key- The key for the value to retrieve.fallback- The fallback value returned when the key does not exist.type- The expected type of the value.- Returns:
- The value associated with the key, or
nullif not found or cannot be cast.
-
isType
Checks if the value associated with the specified key is of the specified type.- Type Parameters:
T- The type parameter of the value.- Parameters:
key- The key for the value to check.type- The expected type of the value.- Returns:
trueif the value exists and matches the type, otherwisefalse.
-
getExchange
Retrieves theBaseExchangeinstance associated with this session.- Returns:
- the associated
BaseExchangeinstance, ornullif none is set.
-
stopSession
public void stopSession()Stops the current session and deletes the associated session file. -
startSession
public void startSession()Starts a new session and generates a session identifier.- Throws:
RuntimeException- if the secure random passphrase generation fails.
-
isSessionStarted
public boolean isSessionStarted()Checks whether a session has been started.- Returns:
trueif a session is active, otherwisefalse.
-
close
public void close()Saves the session data to a persistent file. Automatically called when the session is closed.- Specified by:
closein interfaceAutoCloseable
-
getSessionInfo
Retrieves theSessionInfoassociated with this session.- Returns:
- the
SessionInfoinstance managing session metadata.
-
getSessionStorage
Retrieves theSessionStorageassociated with this session.- Returns:
- the
SessionStorageinstance managing session persistence.
-