Preferences
| Modifier and Type | Class and Description |
|---|---|
| private abstract static class | FileSystemPreferences.
Represents a change to a preference. |
| private static class | FileSystemPreferences.
Represents the creation of this node. |
| private class | FileSystemPreferences.
Represents a preference put. |
| private class | FileSystemPreferences.
Represents a preference remove. |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv final List | changeLog
A list of all uncommitted preference changes. |
| private final File | dir
The directory representing this preference node. |
| private static final int | EACCES
Unix error code for denied access. |
| private static final int | EAGAIN
Unix error code for locked file. |
| private static final String[] | |
| private static final int | |
| private static final int | INIT_SLEEP_TIME
Initial time between lock attempts, in ms. |
| private static boolean | |
| private static boolean | |
| private final boolean | |
| private static boolean | isUserRootModified
Flag, which indicated whether userRoot was modified by another VM |
| private static boolean | |
| private long | lastSyncTime
The last modification time of the file backing this node at the time that prefCache was last synchronized (or initially read). |
| private static final int | |
| private static final int | MAX_ATTEMPTS
Maximum number of lock attempts. |
| pack-priv FileSystemPreferences. | nodeCreate
NodeCreate object for this node. |
| private Map | prefsCache
Locally cached preferences for this node (includes uncommitted changes). |
| private final File | prefsFile
The file representing this preference node's preferences. |
| private static final int | SYNC_INTERVAL
Sync interval in seconds. |
| private static final Timer | |
| pack-priv static File | systemLockFile
The lock file for the system tree. |
| private static volatile Preferences | systemRoot
The system root. |
| private static File | systemRootDir
Directory for system preferences. |
| private static int | systemRootLockHandle
Unix lock handle for systemRoot. |
| private static File | |
| private static long | systemRootModTime
Keeps track of systemRoot modification time. |
| private final File | tmpFile
A temporary file used for saving changes to preferences. |
| private static final int | USER_READ_WRITE
Unix user write/read permission |
| private static final int | |
| private static final int | |
| private static final int | |
| pack-priv static File | userLockFile
The lock file for the user tree. |
| private static volatile Preferences | userRoot
The user root. |
| private static File | userRootDir
Directory for user preferences. |
| private static int | userRootLockHandle
Unix lock handle for userRoot. |
| private static File | userRootModFile
File, which keeps track of global modifications of userRoot. |
| private static long | userRootModTime
Keeps track of userRoot modification time. |
| Access | Constructor and Description |
|---|---|
| private | |
| private | FileSystemPreferences(FileSystemPreferences parent, String name)
Construct a new FileSystemPreferences instance with the specified parent node and name. |
| Modifier and Type | Method and Description |
|---|---|
| private static void | |
| private static byte[] | |
| private void | |
| protected String[] | childrenNamesSpi()
Implements abstract java. Returns the names of the children of this preference node. |
| protected AbstractPreferences | childSpi(String name)
Implements abstract java. Returns the named child of this preference node, creating it if it does not already exist. |
| private static native int | |
| private static String | |
| public void | flush()
Overrides java. Implements the |
| protected void | flushSpi()
Implements abstract java. This method is invoked with this node locked. |
| private static PlatformLogger | |
| protected String | getSpi(String key)
Implements abstract java. Return the value associated with the specified key at this preference
node, or |
| pack-priv static Preferences | |
| pack-priv static Preferences | |
| private void | |
| private static boolean | isDirChar(char ch)
Returns true if the specified character is appropriate for use in Unix directory names. |
| public boolean | isUserNode()
Overrides java. Implements the |
| protected String[] | keysSpi()
Implements abstract java. Returns all of the keys that have an associated value in this preference node. |
| private void | |
| private static void | |
| private boolean | |
| private static native int[] | |
| private static String | |
| protected void | putSpi(String key, String value)
Implements abstract java. Put the given key-value association into this preference node. |
| public void | removeNode()
Overrides java. Implements the |
| protected void | removeNodeSpi()
Implements abstract java. Called with file lock held (in addition to node locks). |
| protected void | removeSpi(String key)
Implements abstract java. Remove the association (if any) for the specified key at this preference node. |
| private void | |
| private static void | |
| private static void | |
| public synchronized void | sync()
Overrides java. Implements the |
| protected void | syncSpi()
Implements abstract java. This method is invoked with this node locked. |
| private static void | |
| private void | |
| private static native int | Returns: Returns zero if OK, UNIX error code if failure.Handle to the file lock. lockHandle)Unlocks file previously locked by lockFile0(). |
| private void |
| changeLog | back to summary |
|---|---|
| pack-priv final List<FileSystemPreferences. A list of all uncommitted preference changes. The elements in this list are of type PrefChange. If this node is concurrently modified on disk by another VM, the two sets of changes are merged when this node is sync'ed by overwriting our prefsCache with the preference map last written out to disk (by the other VM), and then replaying this change log against that map. The resulting map is then written back to the disk. | |
| dir | back to summary |
|---|---|
| private final File dir The directory representing this preference node. There is no guarantee that this directory exits, as another VM can delete it at any time that it (the other VM) holds the file-lock. While the root node cannot be deleted, it may not yet have been created, or the underlying directory could have been deleted accidentally. | |
| EACCES | back to summary |
|---|---|
| private static final int EACCES Unix error code for denied access. | |
| EAGAIN | back to summary |
|---|---|
| private static final int EAGAIN Unix error code for locked file. | |
| EMPTY_STRING_ARRAY | back to summary |
|---|---|
| private static final String[] EMPTY_STRING_ARRAY Hides java. | |
| ERROR_CODE | back to summary |
|---|---|
| private static final int ERROR_CODE | |
| INIT_SLEEP_TIME | back to summary |
|---|---|
| private static final int INIT_SLEEP_TIME Initial time between lock attempts, in ms. The time is doubled after each failing attempt (except the first). | |
| isSystemRootModified | back to summary |
|---|---|
| private static boolean isSystemRootModified | |
| isSystemRootWritable | back to summary |
|---|---|
| private static boolean isSystemRootWritable | |
| isUserNode | back to summary |
|---|---|
| private final boolean isUserNode | |
| isUserRootModified | back to summary |
|---|---|
| private static boolean isUserRootModified Flag, which indicated whether userRoot was modified by another VM | |
| isUserRootWritable | back to summary |
|---|---|
| private static boolean isUserRootWritable | |
| lastSyncTime | back to summary |
|---|---|
| private long lastSyncTime The last modification time of the file backing this node at the time that prefCache was last synchronized (or initially read). This value is set *before* reading the file, so it's conservative; the actual timestamp could be (slightly) higher. A value of zero indicates that we were unable to initialize prefsCache from the disk, or have not yet attempted to do so. (If prefsCache is non-null, it indicates the former; if it's null, the latter.) | |
| LOCK_HANDLE | back to summary |
|---|---|
| private static final int LOCK_HANDLE | |
| MAX_ATTEMPTS | back to summary |
|---|---|
| private static final int MAX_ATTEMPTS Maximum number of lock attempts. | |
| nodeCreate | back to summary |
|---|---|
| pack-priv FileSystemPreferences. NodeCreate object for this node. | |
| prefsCache | back to summary |
|---|---|
| private Map<String, String> prefsCache Locally cached preferences for this node (includes uncommitted changes). This map is initialized with from disk when the first get or put operation occurs on this node. It is synchronized with the corresponding disk file (prefsFile) by the sync operation. The initial value is read *without* acquiring the file-lock. | |
| prefsFile | back to summary |
|---|---|
| private final File prefsFile The file representing this preference node's preferences. The file format is undocumented, and subject to change from release to release, but I'm sure that you can figure it out if you try real hard. | |
| SYNC_INTERVAL | back to summary |
|---|---|
| private static final int SYNC_INTERVAL Sync interval in seconds. | |
| syncTimer | back to summary |
|---|---|
| private static final Timer syncTimer | |
| systemLockFile | back to summary |
|---|---|
| pack-priv static File systemLockFile The lock file for the system tree. | |
| systemRoot | back to summary |
|---|---|
| private static volatile Preferences systemRoot The system root. | |
| systemRootDir | back to summary |
|---|---|
| private static File systemRootDir Directory for system preferences. | |
| systemRootLockHandle | back to summary |
|---|---|
| private static int systemRootLockHandle Unix lock handle for systemRoot. Zero, if unlocked. | |
| systemRootModFile | back to summary |
|---|---|
| private static File systemRootModFile | |
| systemRootModTime | back to summary |
|---|---|
| private static long systemRootModTime Keeps track of systemRoot modification time. This time is reset to zero after system reboot, and is increased by 1 second each time systemRoot is modified. | |
| tmpFile | back to summary |
|---|---|
| private final File tmpFile A temporary file used for saving changes to preferences. As part of the sync operation, changes are first saved into this file, and then atomically renamed to prefsFile. This results in an atomic state change from one valid set of preferences to another. The file-lock is held for the duration of this transformation. | |
| USER_READ_WRITE | back to summary |
|---|---|
| private static final int USER_READ_WRITE Unix user write/read permission | |
| USER_RW_ALL_READ | back to summary |
|---|---|
| private static final int USER_RW_ALL_READ | |
| USER_RWX | back to summary |
|---|---|
| private static final int USER_RWX | |
| USER_RWX_ALL_RX | back to summary |
|---|---|
| private static final int USER_RWX_ALL_RX | |
| userLockFile | back to summary |
|---|---|
| pack-priv static File userLockFile The lock file for the user tree. | |
| userRoot | back to summary |
|---|---|
| private static volatile Preferences userRoot The user root. | |
| userRootDir | back to summary |
|---|---|
| private static File userRootDir Directory for user preferences. | |
| userRootLockHandle | back to summary |
|---|---|
| private static int userRootLockHandle Unix lock handle for userRoot. Zero, if unlocked. | |
| userRootModFile | back to summary |
|---|---|
| private static File userRootModFile File, which keeps track of global modifications of userRoot. | |
| userRootModTime | back to summary |
|---|---|
| private static long userRootModTime Keeps track of userRoot modification time. This time is reset to zero after UNIX reboot, and is increased by 1 second each time userRoot is modified. | |
| FileSystemPreferences | back to summary |
|---|---|
| private FileSystemPreferences(boolean user) Special constructor for roots (both user and system). This constructor will only be called twice, by the static initializer. | |
| FileSystemPreferences | back to summary |
|---|---|
| private FileSystemPreferences(FileSystemPreferences parent, String name) Construct a new FileSystemPreferences instance with the specified parent node and name. This constructor, called from childSpi, is used to make every node except for the two //roots. | |
| addShutdownHook | back to summary |
|---|---|
| private static void addShutdownHook() | |
| byteArray | back to summary |
|---|---|
| private static byte[] byteArray(String s) Translate a string into a byte array by translating each character into two bytes, high-byte first ("big-endian"). | |
| checkLockFile0ErrorCode | back to summary |
|---|---|
| private void checkLockFile0ErrorCode(int errorCode) throws SecurityException Checks if unlockFile0() returned an error. Throws a SecurityException, if access denied. Logs a warning otherwise. | |
| childrenNamesSpi | back to summary |
|---|---|
| protected String[] childrenNamesSpi() Implements abstract java. Doc from java. Returns the names of the children of this preference node. (The returned array will be of size zero if this node has no children.) This method need not return the names of any nodes already cached, but may do so without harm. This method is invoked with the lock on this node held. If this node throws a | |
| childSpi | back to summary |
|---|---|
| protected AbstractPreferences childSpi(String name) Implements abstract java. Doc from java. Returns the named child of this preference node, creating it if it does
not already exist. It is guaranteed that Finally, it is guaranteed that the named node has not been returned
by a previous invocation of this method or The implementer must ensure that the returned node has not been
removed. If a like-named child of this node was previously removed, the
implementer must return a newly constructed If this method causes a node to be created, this node is not
guaranteed to be persistent until the This method is invoked with the lock on this node held. | |
| chmod | back to summary |
|---|---|
| private static native int chmod(String fileName, int permission) Changes UNIX file permissions. | |
| dirName | back to summary |
|---|---|
| private static String dirName(String nodeName) Returns the directory name corresponding to the specified node name. Generally, this is just the node name. If the node name includes inappropriate characters (as per isDirChar) it is translated to Base64. with the underscore character ('_', 0x5f) prepended. | |
| flush | back to summary |
|---|---|
| public void flush() throws BackingStoreException Overrides java. Doc from java. Implements the This implementation calls a recursive helper method that locks this node, invokes flushSpi() on it, unlocks this node, and recursively invokes this method on each "cached child." A cached child is a child of this node that has been created in this VM and not subsequently removed. In effect, this method does a depth first traversal of the "cached subtree" rooted at this node, calling flushSpi() on each node in the subTree while only that node is locked. Note that flushSpi() is invoked top-down. If this method is invoked on a node that has been removed with
the
| |
| flushSpi | back to summary |
|---|---|
| protected void flushSpi() throws BackingStoreException Implements abstract java. Doc from java. This method is invoked with this node locked. The contract of this method is to force any cached changes in the contents of this preference node to the backing store, guaranteeing their persistence. (It is perfectly possible that this node does not exist on the backing store, either because it has been deleted by another VM, or because it has not yet been created.) Note that this method should not flush the preferences in any subnodes of this node. If the backing store naturally flushes an entire subtree at once, the implementer is encouraged to override flush(), rather than merely overriding this method. If this node throws a
| |
| getLogger | back to summary |
|---|---|
| private static PlatformLogger getLogger() Returns logger for error messages. Backing store exceptions are logged at WARNING level. | |
| getSpi | back to summary |
|---|---|
| protected String getSpi(String key) Implements abstract java. Doc from java. Return the value associated with the specified key at this preference
node, or Generally speaking, this method should not throw an exception
under any circumstances. If, however, if it does throw an exception,
the exception will be intercepted and treated as a This method is invoked with the lock on this node held. | |
| getSystemRoot | back to summary |
|---|---|
| pack-priv static Preferences getSystemRoot() | |
| getUserRoot | back to summary |
|---|---|
| pack-priv static Preferences getUserRoot() | |
| initCacheIfNecessary | back to summary |
|---|---|
| private void initCacheIfNecessary() Initialize prefsCache if it has yet to be initialized. When this method returns, prefsCache will be non-null. If the data was successfully read from the file, lastSyncTime will be updated. If prefsCache was null, but it was impossible to read the file (because it didn't exist or for any other reason) prefsCache will be initialized to an empty, modifiable Map, and lastSyncTime remain zero. | |
| isDirChar | back to summary |
|---|---|
| private static boolean isDirChar(char ch) Returns true if the specified character is appropriate for use in Unix directory names. A character is appropriate if it's a printable ASCII character (> 0x1f && < 0x7f) and unequal to slash ('/', 0x2f), dot ('.', 0x2e), or underscore ('_', 0x5f). | |
| isUserNode | back to summary |
|---|---|
| public boolean isUserNode() Overrides java. Doc from java. Implements the This implementation compares this node's root node (which is stored
in a private field) with the value returned by
| |
| keysSpi | back to summary |
|---|---|
| protected String[] keysSpi() Implements abstract java. Doc from java. Returns all of the keys that have an associated value in this preference node. (The returned array will be of size zero if this node has no preferences.) It is guaranteed that this node has not been removed. This method is invoked with the lock on this node held. If this node throws a | |
| loadCache | back to summary |
|---|---|
| private void loadCache() throws BackingStoreException Attempt to load prefsCache from the backing store. If the attempt succeeds, lastSyncTime will be updated (the new value will typically correspond to the data loaded into the map, but it may be less, if another VM is updating this node concurrently). If the attempt fails, a BackingStoreException is thrown and both prefsCache and lastSyncTime are unaffected by the call. | |
| loadPrefsLib | back to summary |
|---|---|
private static void loadPrefsLib()
| |
| lockFile | back to summary |
|---|---|
| private boolean lockFile(boolean shared) throws SecurityException Try to acquire the appropriate file lock (user or system). If the initial attempt fails, several more attempts are made using an exponential backoff strategy. If all attempts fail, this method returns false.
| |
| lockFile0 | back to summary |
|---|---|
| private static native int[] lockFile0(String fileName, int permission, boolean shared) Locks file using UNIX file locking.
| |
| nodeName | back to summary |
|---|---|
| private static String nodeName(String dirName) Returns the node name corresponding to the specified directory name. (Inverts the transformation of dirName(String). | |
| putSpi | back to summary |
|---|---|
| protected void putSpi(String key, String value) Implements abstract java. Doc from java. Put the given key-value association into this preference node. It is
guaranteed that This method is invoked with the lock on this node held. | |
| removeNode | back to summary |
|---|---|
| public void removeNode() throws BackingStoreException Overrides java. Doc from java. Implements the This implementation checks to see that this node is the root; if so,
it throws an appropriate exception. Then, it locks this node's parent,
and calls a recursive helper method that traverses the subtree rooted at
this node. The recursive method locks the node on which it was called,
checks that it has not already been removed, and then ensures that all
of its children are cached: The Note that the helper method is always invoked with all ancestors up to the "closest non-removed ancestor" locked.
| |
| removeNodeSpi | back to summary |
|---|---|
| protected void removeNodeSpi() throws BackingStoreException Implements abstract java. Called with file lock held (in addition to node locks).
| |
| removeSpi | back to summary |
|---|---|
| protected void removeSpi(String key) Implements abstract java. Doc from java. Remove the association (if any) for the specified key at this
preference node. It is guaranteed that This method is invoked with the lock on this node held. | |
| replayChanges | back to summary |
|---|---|
| private void replayChanges() Replay changeLog against prefsCache. | |
| setupSystemRoot | back to summary |
|---|---|
| private static void setupSystemRoot() | |
| setupUserRoot | back to summary |
|---|---|
| private static void setupUserRoot() | |
| sync | back to summary |
|---|---|
| public synchronized void sync() throws BackingStoreException Overrides java. Doc from java. Implements the This implementation calls a recursive helper method that locks this node, invokes syncSpi() on it, unlocks this node, and recursively invokes this method on each "cached child." A cached child is a child of this node that has been created in this VM and not subsequently removed. In effect, this method does a depth first traversal of the "cached subtree" rooted at this node, calling syncSpi() on each node in the subTree while only that node is locked. Note that syncSpi() is invoked top-down.
| |
| syncSpi | back to summary |
|---|---|
| protected void syncSpi() throws BackingStoreException Implements abstract java. Doc from java. This method is invoked with this node locked. The contract of this method is to synchronize any cached preferences stored at this node with any stored in the backing store. (It is perfectly possible that this node does not exist on the backing store, either because it has been deleted by another VM, or because it has not yet been created.) Note that this method should not synchronize the preferences in any subnodes of this node. If the backing store naturally syncs an entire subtree at once, the implementer is encouraged to override sync(), rather than merely overriding this method. If this node throws a
| |
| syncWorld | back to summary |
|---|---|
| private static void syncWorld() | |
| unlockFile | back to summary |
|---|---|
| private void unlockFile() Release the appropriate file lock (user or system).
| |
| unlockFile0 | back to summary |
|---|---|
| private static native int unlockFile0(int lockHandle) Unlocks file previously locked by lockFile0().
| |
| writeBackCache | back to summary |
|---|---|
| private void writeBackCache() throws BackingStoreException Attempt to write back prefsCache to the backing store. If the attempt succeeds, lastSyncTime will be updated (the new value will correspond exactly to the data thust written back, as we hold the file lock, which prevents a concurrent write. If the attempt fails, a BackingStoreException is thrown and both the backing store (prefsFile) and lastSyncTime will be unaffected by this call. This call will NEVER leave prefsFile in a corrupt state. | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv abstract void |
| Change | back to summary |
|---|---|
| private Change() | |
| replay | back to summary |
|---|---|
| pack-priv abstract void replay() Reapplies the change to prefsCache. | |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | replay()
Implements abstract java. Performs no action, but the presence of this object in changeLog will force the node and its ancestors to be made permanent at the next sync. |
| NodeCreate | back to summary |
|---|---|
| private NodeCreate() | |
| replay | back to summary |
|---|---|
| pack-priv void replay() Implements abstract java. Performs no action, but the presence of this object in changeLog will force the node and its ancestors to be made permanent at the next sync. | |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | replay()
Implements abstract java. Reapplies the change to prefsCache. |
| Put | back to summary |
|---|---|
| pack-priv Put(String key, String value) | |
| replay | back to summary |
|---|---|
| pack-priv void replay() Implements abstract java. Doc from java. Reapplies the change to prefsCache. | |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | replay()
Implements abstract java. Reapplies the change to prefsCache. |
| key | back to summary |
|---|---|
| pack-priv String key | |
| Remove | back to summary |
|---|---|
| pack-priv Remove(String key) | |
| replay | back to summary |
|---|---|
| pack-priv void replay() Implements abstract java. Doc from java. Reapplies the change to prefsCache. | |