Package gamedata

Class 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 an IllegalStateException. 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()
      Returns true if the game data has ever been locked during this run of the application.
      static boolean isLocked()
      Returns true 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isLocked

        public static boolean isLocked()
        Returns true 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 - if true, lock game data so that future tests fail
      • hasBeenLocked

        public static boolean hasBeenLocked()
        Returns true if the game data has ever been locked during this run of the application.
        Returns:
        true if isLocked() 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 be null 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 be null for a default message
        suffix - 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 be null for a default message
        suffix - 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