Package gamedata
Class Lock
- java.lang.Object
-
- gamedata.Lock
-
public class Lock extends java.lang.Object
Maintains a lock on the game data. When game data is locked, trying to add or modify game data will fail by throwing anIllegalStateException
. Game data is normally locked after extensions are loaded to ensure that the application remains in a consistent state. Developers may find it useful to unlock the game data while debugging so that fewer application restarts are required.Some kinds of game data may not require locking to remain consistent, in which case they can be modified freely. Future versions may lessen the locking constraints on a kind of game data, but will not increase them.
- Since:
- 3.0
- Author:
- Chris Jennings
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addLockingTask(java.lang.Runnable task)
Adds a new runnable task that will be executed just after the database is locked.static void
fail(java.lang.String message, java.lang.String suffix)
Throws an exception as if a test had been failed.static boolean
hasBeenLocked()
Returnstrue
if the game data has ever been locked during this run of the application.static boolean
isLocked()
Returnstrue
if the game data has been locked.static void
setLocked(boolean lock)
Locks or unlocks the game data.static void
test()
Test the lock, and if locked throw an IllegalStateException using a default message.static void
test(java.lang.String message)
Test the lock, and if locked throw an IllegalStateException using a custom message.static void
test(java.lang.String message, java.lang.String suffix)
Test the lock, and if locked throw an IllegalStateException by composing a message from the message and suffix.
-
-
-
Method Detail
-
isLocked
public static boolean isLocked()
Returnstrue
if the game data has been locked.- Returns:
true
if lock tests will fail
-
setLocked
public static void setLocked(boolean lock)
Locks or unlocks the game data.- Parameters:
lock
- iftrue
, lock game data so that future tests fail
-
hasBeenLocked
public static boolean hasBeenLocked()
Returnstrue
if the game data has ever been locked during this run of the application.- Returns:
true
ifisLocked()
has ever been true
-
test
public static void test()
Test the lock, and if locked throw an IllegalStateException using a default message.
-
test
public static void test(java.lang.String message)
Test the lock, and if locked throw an IllegalStateException using a custom message.- Parameters:
message
- the base message, may benull
for a default message
-
test
public static void test(java.lang.String message, java.lang.String suffix)
Test the lock, and if locked throw an IllegalStateException by composing a message from the message and suffix. (This allows you to add a parameter to the message without having to create a concatenated string in the normal case where the test passes.)- Parameters:
message
- the base message, may benull
for a default messagesuffix
- an optional suffix to be appended as if by message + ": " + suffix
-
fail
public static void fail(java.lang.String message, java.lang.String suffix)
Throws an exception as if a test had been failed.- Parameters:
message
- the base message, may benull
for a default messagesuffix
- an optional suffix to be appended as if by message + ": " + suffix
-
addLockingTask
public static void addLockingTask(java.lang.Runnable task)
Adds a new runnable task that will be executed just after the database is locked. Game plug-ins may use this to normalize their own internal game databases after all extension plug-ins have had a chance to run.- Parameters:
task
- the task to be executed after the database is locked
-
-