Package rs.baselib.prefs
Class AbstractPreferencesService
java.lang.Object
rs.baselib.prefs.AbstractPreferencesService
- All Implemented Interfaces:
IPreferencesService
- Direct Known Subclasses:
PreferencesService
public abstract class AbstractPreferencesService extends java.lang.Object implements IPreferencesService
Common functionality of a preferences service.
The service organizes all preferences in this scheme:
/@application1/@USER - user preferences of application 1
/@application1/@SYSTEM - system preferences of application 1
/@application2/@USER - user preferences of application 2
/@application2/@SYSTEM - system preferences of application 2
- Author:
- ralph
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classAbstractPreferencesService.FlushingThreadA thread running all flushs. -
Constructor Summary
Constructors Constructor Description AbstractPreferencesService()Constructor. -
Method Summary
Modifier and Type Method Description protected static voidcheckNodeName(java.lang.String s)Checks the name of the node to be correct.protected java.util.concurrent.locks.ReadWriteLockcreateReadWriteLock()Creates a newReadWriteLock.protected abstract IPreferencescreateRootNode()Creates the root node.voidflush(IPreferences node)Flushes any changes made in this node.protected abstract voidflushSystemPreferences(IPreferences node, java.lang.String applicationName)Flushes the system preferences from the given node.protected abstract voidflushUserPreferences(IPreferences node, java.lang.String applicationName)Flushes the user preferences from the given node.protected java.lang.StringgetApplicationName(IPreferences node)Returns the application name of the given node.protected IPreferencesgetApplicationNode(IPreferences node)Returns the application node rom the given nodeprotected IPreferencesgetApplicationPreferences(java.lang.String applicationName)Returns the application preferences.protected IPreferencesgetLockNode(IPreferences node)Returns the node where locks will be placed upon.java.util.concurrent.locks.LockgetReadLock(IPreferences node)Returns the read lock object for the given node.protected java.util.concurrent.locks.ReadWriteLockgetReadWriteLock(IPreferences node)Returns the correct lock for the given node.IPreferencesgetSystemPreferences(java.lang.String applicationName)Returns the system preferences for the given application.IPreferencesgetUserPreferences(java.lang.String applicationName)Returns the user preferences for the given application.java.util.concurrent.locks.LockgetWriteLock(IPreferences node)Returns the write lock object for the given node.protected abstract voidloadSystemPreferences(IPreferences node, java.lang.String applicationName)Loads the system preferences into the given node.protected abstract voidloadUserPreferences(IPreferences node, java.lang.String applicationName)Loads the user preferences into the given node.voidnodeChanged(IPreferences node)A node changed.voidsync(IPreferences node)Wait for any modifications to be flushed.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface rs.baselib.prefs.IPreferencesService
getSystemPreferencesHome, getUserPreferencesHome
-
Constructor Details
-
AbstractPreferencesService
public AbstractPreferencesService()Constructor.
-
-
Method Details
-
createRootNode
Creates the root node.- Returns:
- the root node for the service
-
getApplicationPreferences
protected IPreferences getApplicationPreferences(java.lang.String applicationName) throws java.util.prefs.BackingStoreExceptionReturns the application preferences.- Parameters:
applicationName- name of application- Returns:
- the root node for this application
- Throws:
java.util.prefs.BackingStoreException- when the storage fails
-
createReadWriteLock
protected java.util.concurrent.locks.ReadWriteLock createReadWriteLock()Creates a newReadWriteLock.- Returns:
- a new
ReentrantReadWriteLock
-
getReadLock
Returns the read lock object for the given node.- Specified by:
getReadLockin interfaceIPreferencesService- Parameters:
node- the node that requires a read lock- Returns:
- the responsible
Lockobject
-
getWriteLock
Returns the write lock object for the given node.- Specified by:
getWriteLockin interfaceIPreferencesService- Parameters:
node- the node that requires a write lock- Returns:
- the responsible
Lockobject
-
getReadWriteLock
Returns the correct lock for the given node.- Parameters:
node- node to get the lock for- Returns:
- the
ReadWriteLock
-
getLockNode
Returns the node where locks will be placed upon.- Parameters:
node- the node where a lock is required- Returns:
- the node that needs to be locked
-
loadUserPreferences
protected abstract void loadUserPreferences(IPreferences node, java.lang.String applicationName) throws java.util.prefs.BackingStoreExceptionLoads the user preferences into the given node.- Parameters:
node- node that shall be populatedapplicationName- name of application to be loaded- Throws:
java.util.prefs.BackingStoreException- when the storage fails
-
loadSystemPreferences
protected abstract void loadSystemPreferences(IPreferences node, java.lang.String applicationName) throws java.util.prefs.BackingStoreExceptionLoads the system preferences into the given node.- Parameters:
node- node that shall be populatedapplicationName- name of application to be loaded- Throws:
java.util.prefs.BackingStoreException- when the storage fails
-
flushUserPreferences
protected abstract void flushUserPreferences(IPreferences node, java.lang.String applicationName) throws java.util.prefs.BackingStoreExceptionFlushes the user preferences from the given node.- Parameters:
node- node that shall be flushedapplicationName- name of application to be flushed- Throws:
java.util.prefs.BackingStoreException- when the storage fails
-
flushSystemPreferences
protected abstract void flushSystemPreferences(IPreferences node, java.lang.String applicationName) throws java.util.prefs.BackingStoreExceptionFlushes the system preferences from the given node.- Parameters:
node- node that shall be flushedapplicationName- name of application to be flushed- Throws:
java.util.prefs.BackingStoreException- when the storage fails
-
getUserPreferences
public IPreferences getUserPreferences(java.lang.String applicationName) throws java.util.prefs.BackingStoreExceptionReturns the user preferences for the given application.- Specified by:
getUserPreferencesin interfaceIPreferencesService- Parameters:
applicationName- name of application- Returns:
- the preferences object
- Throws:
java.util.prefs.BackingStoreException- when the storage fails
-
getSystemPreferences
public IPreferences getSystemPreferences(java.lang.String applicationName) throws java.util.prefs.BackingStoreExceptionReturns the system preferences for the given application.- Specified by:
getSystemPreferencesin interfaceIPreferencesService- Parameters:
applicationName- name of application- Returns:
- the preferences object
- Throws:
java.util.prefs.BackingStoreException- when the storage fails
-
checkNodeName
protected static void checkNodeName(java.lang.String s)Checks the name of the node to be correct. A node name must not contain whitespaces or special characters other than '@', '-' or '-' or '.'.- Parameters:
s- string to be checked
-
nodeChanged
A node changed. Schedules a flush.- Parameters:
node- the node that changed
-
flush
Flushes any changes made in this node. The method does not return before the flush has been completed.- Specified by:
flushin interfaceIPreferencesService- Parameters:
node- the node to be flushed- Throws:
java.util.prefs.BackingStoreException- when there has been a communication problem with the backing store.
-
getApplicationNode
Returns the application node rom the given node- Parameters:
node- child node- Returns:
- the application node
-
getApplicationName
Returns the application name of the given node.- Parameters:
node- any child node- Returns:
- the application name this node belongs to
-
sync
Wait for any modifications to be flushed. The method does not return before the next flush has been completed (in case modifications are pending).- Specified by:
syncin interfaceIPreferencesService- Parameters:
node- the node to be flushed- Throws:
java.util.prefs.BackingStoreException- when there has been a communication problem with the backing store.
-