Class ServerProfileManager
java.lang.Object
net.joseplay.allianceutils.api.playerProfile.data.ServerProfileManager
Manages the lifecycle, synchronization, and persistence of a single
ServerProfile.
Core rules:
- The internal profile must only be modified via
modifyProfile(ProfileModifier) getSnapshot()returns a safe copy (read-only usage)- Thread-safety is enforced using a
ReentrantReadWriteLock - Persistence is asynchronous
This manager is designed for a single shared server-wide profile.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface used to modify the profile safely. -
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanIndicates whether the profile has been loaded from the database. -
Constructor Summary
ConstructorsConstructorDescriptionCreates the manager and starts async loading from database. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyRemoteProfile(ServerProfile remoteProfile) Applies a remote profile update (e.g., from another server).@NotNull ServerProfileReturns a snapshot (safe copy) of the current profile.voidLoads the profile asynchronously from the database.voidThe ONLY valid entry point to modify the server profile.voidSchedules an async save if the profile is marked as dirty.voidshutdown()Forces a synchronous save (used on shutdown).
-
Field Details
-
isLoadded
public boolean isLoaddedIndicates whether the profile has been loaded from the database.
-
-
Constructor Details
-
ServerProfileManager
public ServerProfileManager()Creates the manager and starts async loading from database.
-
-
Method Details
-
loadFromDataBaseAsync
public void loadFromDataBaseAsync()Loads the profile asynchronously from the database. -
getSnapshot
Returns a snapshot (safe copy) of the current profile.The returned object must NOT be modified outside the manager.
- Returns:
- cloned server profile
-
modifyProfile
The ONLY valid entry point to modify the server profile.- Parameters:
modifier- logic to apply changes
-
saveIfDirtyAsync
public void saveIfDirtyAsync()Schedules an async save if the profile is marked as dirty. -
shutdown
public void shutdown()Forces a synchronous save (used on shutdown). -
applyRemoteProfile
Applies a remote profile update (e.g., from another server).- Parameters:
remoteProfile- incoming profile
-