/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
MacOSXPreferencesFile synchronization:
Everything is synchronized on MacOSXPreferencesFile.class. This prevents:
* simultaneous updates to cachedFiles or changedFiles
* simultaneous creation of two objects for the same name+user+host triplet
* simultaneous modifications to the same file
* modifications during syncWorld/flushWorld
* (in MacOSXPreferences.removeNodeSpi()) modification or sync during
multi-step node removal process
... among other things.
*/
/*
Timers. There are two timers that control synchronization of prefs data to
and from disk.
* Sync timer periodically calls syncWorld() to force external disk changes
(e.g. from another VM) into the memory cache. The sync timer runs even
if there are no outstanding local changes. The sync timer syncs all live
MacOSXPreferencesFile objects (the cachedFiles list).
The sync timer period is controlled by the java.util.prefs.syncInterval
property (same as FileSystemPreferences). By default there is *no*
sync timer (unlike FileSystemPreferences); it is only enabled if the
syncInterval property is set. The minimum interval is 5 seconds.
* Flush timer calls flushWorld() to force local changes to disk.
The flush timer is scheduled to fire some time after each pref change,
unless it's already scheduled to fire before that. syncWorld and
flushWorld will cancel any outstanding flush timer as unnecessary.
The flush timer flushes all changed files (the changedFiles list).
The time between pref write and flush timer call is controlled by the
java.util.prefs.flushDelay property (unlike FileSystemPreferences).
The default is 60 seconds and the minimum is 5 seconds.
The flush timer's behavior is required by the Java Preferences spec
("changes will eventually propagate to the persistent backing store with
an implementation-dependent delay"). The sync timer is not required by
the spec (multiple VMs are only required to not corrupt the prefs), but
the periodic sync is implemented by FileSystemPreferences and may be
useful to some programs. The sync timer is disabled by default because
it's expensive and is usually not necessary.
*/
class MacOSXPreferencesFile {
static {
}
public void run() {
}
}
public void run() {
}
}
// Maps string -> weak reference to MacOSXPreferencesFile
// Files that may have unflushed changes
// Timer and pending sync and flush tasks (which are both scheduled
// on the same timer)
private long user;
private long host;
// private contructor - use factory method getFile() instead
{
}
// Factory method
// Always returns the same object for the given name+user+host
static synchronized MacOSXPreferencesFile
{
}
// Java user node == CF current user, any host
// Java system node == CF any user, current host
}
// Don't schedule this file for flushing until some nodes or
// keys are added to it.
// Do set up the sync timer if requested; sync timer affects reads
// as well as writes.
return result;
}
// Write all prefs changes to disk and clear all cached prefs values
// (so the next read will read from disk).
static synchronized boolean syncWorld()
{
boolean ok = true;
if (f != null) {
if (!f.synchronize()) ok = false;
} else {
}
}
}
// Kill any pending flush
if (flushTimerTask != null) {
}
// Clear changed file list. The changed files were guaranteed to
// have been in the cached file list (because there was a strong
// reference from changedFiles.
return ok;
}
// Sync only current user preferences
static synchronized boolean syncUser() {
boolean ok = true;
if (!f.synchronize()) {
ok = false;
}
} else {
}
}
}
// Remove synchronized file from changed file list. The changed files were
// guaranteed to have been in the cached file list (because there was a strong
// reference from changedFiles.
if (changedFiles != null) {
while (iterChanged.hasNext()) {
}
}
return ok;
}
//Flush only current user preferences
static synchronized boolean flushUser() {
boolean ok = true;
if (f.user == cfCurrentUser) {
if (!f.synchronize())
ok = false;
else
}
}
}
return ok;
}
// Write all prefs changes to disk, but do not clear all cached prefs
// values. Also kills any scheduled flush task.
// There's no CFPreferencesFlush() (<rdar://problem/3049129>), so lots of cached prefs
// are cleared anyway.
static synchronized boolean flushWorld()
{
boolean ok = true;
if (!f.synchronize()) ok = false;
}
}
if (flushTimerTask != null) {
}
return ok;
}
// Mark this prefs file as changed. The changes will be flushed in
// at most flushDelay() seconds.
// Must be called when synchronized on MacOSXPreferencesFile.class
private void markChanged()
{
// Add this file to the changed file list
changedFiles.add(this);
// Schedule a new flush and a shutdown hook, if necessary
if (flushTimerTask == null) {
flushTimerTask = new FlushTask();
}
}
// Return the flush delay, initializing from a property if necessary.
private static synchronized long flushDelay()
{
if (flushDelay == -1) {
try {
// flush delay >= 5, default 60
} catch (NumberFormatException e) {
flushDelay = 60;
}
}
return flushDelay;
}
// Initialize and run the sync timer, if the sync timer property is set
// and the sync timer hasn't already been started.
private static synchronized void initSyncTimerIfNeeded()
{
// syncInterval: -1 is uninitialized, other negative is off,
// positive is seconds between syncs (min 5).
if (syncInterval == -1) {
try {
if (syncInterval >= 0) {
// minimum of 5 seconds
} else {
}
} catch (NumberFormatException e) {
}
if (syncInterval > 0) {
} else {
// syncInterval property not set. No sync timer ever.
}
}
}
// Return the timer used for flush and sync, creating it if necessary.
{
public void run() {
flushWorld();
}
};
/* Set context class loader to null in order to avoid
* keeping a strong reference to an application classloader.
*/
}
return timer;
}
// Node manipulation
{
synchronized(MacOSXPreferencesFile.class) {
markChanged();
}
}
{
synchronized(MacOSXPreferencesFile.class) {
markChanged();
}
}
{
synchronized(MacOSXPreferencesFile.class) {
markChanged();
}
}
{
synchronized(MacOSXPreferencesFile.class) {
markChanged();
}
}
// Key manipulation
{
synchronized(MacOSXPreferencesFile.class) {
markChanged();
}
}
{
synchronized(MacOSXPreferencesFile.class) {
markChanged();
}
}
{
synchronized(MacOSXPreferencesFile.class) {
}
}
// Enumerators
{
synchronized(MacOSXPreferencesFile.class) {
}
}
{
synchronized(MacOSXPreferencesFile.class) {
}
}
// Synchronization
boolean synchronize()
{
synchronized(MacOSXPreferencesFile.class) {
}
}
// CF functions
// Must be called when synchronized on MacOSXPreferencesFile.class
private static final native boolean
private static final native void
private static final native boolean
private static final native void
private static final native void
private static final native void
private static final native String
private static final native String[]
private static final native String[]
private static final native boolean
// CFPreferences host and user values (CFStringRefs)
// CFPreferences constant accessors
private static final native long currentUser();
private static final native long anyUser();
private static final native long currentHost();
private static final native long anyHost();
}