Package tigase.conf
Class ConfigurationCache
- java.lang.Object
-
- tigase.conf.ConfigurationCache
-
- All Implemented Interfaces:
java.lang.Iterable<ConfigItem>
,ConfigRepositoryIfc
,ComponentRepository<ConfigItem>
,Repository
- Direct Known Subclasses:
ConfigSQLRepository
,ConfigXMLRepository
public class ConfigurationCache extends java.lang.Object implements ConfigRepositoryIfc
Created: Dec 10, 2009 2:02:41 PM- Author:
- Artur Hefczyc
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface tigase.db.Repository
Repository.Meta, Repository.SchemaId
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONFIG_DUMP_FILE_PROP_DEF
static java.lang.String
CONFIG_DUMP_FILE_PROP_KEY
-
Fields inherited from interface tigase.db.comp.ComponentRepository
COMP_REPO_BIND
-
Fields inherited from interface tigase.conf.ConfigRepositoryIfc
RELOAD_DELAY, RESOURCE_URI
-
-
Constructor Summary
Constructors Constructor Description ConfigurationCache()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addItem(java.lang.String key, java.lang.Object value)
Method adds an Item to the configuration repository where the key is the item key constructed of component name, node name and property key name.void
addItem(java.lang.String compName, ConfigItem item)
void
addItem(ConfigItem item)
The method adds a new or updates existing Item in the repository.void
addItemNoStore(ConfigItem item)
The method adds a new or updates existing Item.void
addRepoChangeListener(RepositoryChangeListenerIfc<ConfigItem> repoChangeListener)
Adds a listener for repository Item change.java.util.Collection<ConfigItem>
allItems()
Returns a collection with all items stored in the repository.boolean
contains(java.lang.String key)
The method checks whether the item is stored in the repository.void
destroy()
Method destroys this instance of ComponentRepository releasing resources allocated for this instance of ComponentRepository if possiblejava.lang.Object
get(java.lang.String compName, java.lang.String node, java.lang.String key, java.lang.Object def)
Returns a configuration setting for a given component, node and key.java.lang.String[]
getCompNames()
Returns all component names for which there are some configuration settings available.void
getDefaults(java.util.Map<java.lang.String,java.lang.Object> defs, java.util.Map<java.lang.String,java.lang.Object> params)
Deprecated.java.lang.String
getDefHostname()
java.util.Map<java.lang.String,java.lang.Object>
getInitProperties()
ConfigItem
getItem(java.lang.String key)
The method returns all item configuration parameters for a key ornull
if the item does not exist in the repository.ConfigItem
getItem(java.lang.String compName, java.lang.String node, java.lang.String key)
ConfigItem
getItemInstance()
Creates a new, uninitialized instance of the repository Item.java.util.Set<ConfigItem>
getItemsForComponent(java.lang.String compName)
Get set of config items stored for componentjava.lang.String[]
getKeys(java.lang.String compName, java.lang.String node)
Returns an array of all configuration keys for a given component and configuration node.java.util.Map<java.lang.String,java.lang.Object>
getProperties(java.lang.String compName)
Deprecated.void
initRepository(java.lang.String resource_uri, java.util.Map<java.lang.String,java.lang.String> params)
Deprecated.java.util.Iterator<ConfigItem>
iterator()
void
putProperties(java.lang.String compName, java.util.Map<java.lang.String,java.lang.Object> props)
Sets/adds properties for the given component name.void
reload()
This method is called to reload items from the database or other permanent storage.void
remove(java.lang.String compName, java.lang.String node, java.lang.String key)
Removes a configuration setting from the configuration repository.void
removeItem(java.lang.String key)
The method is called to remove given Item from the memory cache and permanent storage.void
removeItem(java.lang.String compName, ConfigItem item)
void
removeItemNoStore(java.lang.String key)
void
removeRepoChangeListener(RepositoryChangeListenerIfc<ConfigItem> repoChangeListener)
Removes a listener for repository Item change.void
set(java.lang.String compName, java.lang.String node, java.lang.String key, java.lang.Object value)
Puts/sets/adds/updates a configuration setting to the configuration repository.void
setAutoloadTimer(long delay)
Sets autoload task to periodically reload data from database.void
setDefHostname(java.lang.String hostname)
This is used to load a configuration for a selected cluster node.void
setProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
Deprecated.int
size()
The method returns number of items in the repository.void
store()
The method is called to store all data in the database.java.lang.String
validateItem(ConfigItem item)
Performs Item validation to check whether it meets the repository policy.
-
-
-
Field Detail
-
CONFIG_DUMP_FILE_PROP_DEF
public static final java.lang.String CONFIG_DUMP_FILE_PROP_DEF
- See Also:
- Constant Field Values
-
CONFIG_DUMP_FILE_PROP_KEY
public static final java.lang.String CONFIG_DUMP_FILE_PROP_KEY
- See Also:
- Constant Field Values
-
-
Method Detail
-
addRepoChangeListener
public void addRepoChangeListener(RepositoryChangeListenerIfc<ConfigItem> repoChangeListener)
Description copied from interface:ComponentRepository
Adds a listener for repository Item change.- Specified by:
addRepoChangeListener
in interfaceComponentRepository<ConfigItem>
-
removeRepoChangeListener
public void removeRepoChangeListener(RepositoryChangeListenerIfc<ConfigItem> repoChangeListener)
Description copied from interface:ComponentRepository
Removes a listener for repository Item change.- Specified by:
removeRepoChangeListener
in interfaceComponentRepository<ConfigItem>
-
addItem
public void addItem(java.lang.String compName, ConfigItem item)
-
addItemNoStore
public void addItemNoStore(ConfigItem item)
Description copied from interface:ComponentRepository
The method adds a new or updates existing Item. It needs to have all fields set correctly. After this method call is finished a new added item must be available in the component repository. The method adds the item to memory cache but not to a permanent storage.- Specified by:
addItemNoStore
in interfaceComponentRepository<ConfigItem>
- Parameters:
item
- aItem
with all it's configuration parameters.
-
addItem
public void addItem(ConfigItem item) throws TigaseDBException
Description copied from interface:ComponentRepository
The method adds a new or updates existing Item in the repository. It needs to have all fields set correctly. After this method call is finished a new added item must be available in the component repository. The method adds the item to memory cache and permanent storage.- Specified by:
addItem
in interfaceComponentRepository<ConfigItem>
- Parameters:
item
- aItem
with all it's configuration parameters.- Throws:
TigaseDBException
-
addItem
public void addItem(java.lang.String key, java.lang.Object value) throws ConfigurationException
Description copied from interface:ConfigRepositoryIfc
Method adds an Item to the configuration repository where the key is the item key constructed of component name, node name and property key name.- Specified by:
addItem
in interfaceConfigRepositoryIfc
- Throws:
ConfigurationException
-
allItems
public java.util.Collection<ConfigItem> allItems() throws TigaseDBException
Description copied from interface:ComponentRepository
Returns a collection with all items stored in the repository.- Specified by:
allItems
in interfaceComponentRepository<ConfigItem>
- Throws:
TigaseDBException
-
contains
public boolean contains(java.lang.String key)
Description copied from interface:ComponentRepository
The method checks whether the item is stored in the repository.- Specified by:
contains
in interfaceComponentRepository<ConfigItem>
- Parameters:
key
- aString
with key to search for.- Returns:
- a
boolean
valuetrue
if the item exists in the repository orfalse
of it does not.
-
destroy
public void destroy()
Description copied from interface:ComponentRepository
Method destroys this instance of ComponentRepository releasing resources allocated for this instance of ComponentRepository if possible- Specified by:
destroy
in interfaceComponentRepository<ConfigItem>
-
get
public java.lang.Object get(java.lang.String compName, java.lang.String node, java.lang.String key, java.lang.Object def)
Description copied from interface:ConfigRepositoryIfc
Returns a configuration setting for a given component, node and key. If the configuration parameters is not found, returns given default value.- Specified by:
get
in interfaceConfigRepositoryIfc
- Returns:
- value
-
getCompNames
public java.lang.String[] getCompNames()
Description copied from interface:ConfigRepositoryIfc
Returns all component names for which there are some configuration settings available.- Specified by:
getCompNames
in interfaceConfigRepositoryIfc
- Returns:
- array of component names
-
getDefHostname
public java.lang.String getDefHostname()
-
setDefHostname
public void setDefHostname(java.lang.String hostname)
Description copied from interface:ConfigRepositoryIfc
This is used to load a configuration for a selected cluster node. The configuration repository (file or database) may contain settings for all cluster nodes, some of the settings may be exclusive to one or another cluster node. This method informs the repository what node name (hostname) it is running on.- Specified by:
setDefHostname
in interfaceConfigRepositoryIfc
-
getDefaults
@Deprecated public void getDefaults(java.util.Map<java.lang.String,java.lang.Object> defs, java.util.Map<java.lang.String,java.lang.Object> params)
Deprecated.Description copied from interface:ComponentRepository
The method is called to obtain default configuration settings if there are any for this repository implementation The configuration settings are implementation dependent and there are no defaults set by the server. Default settings returned by this method are then saved in the configuration file and presented to the admin for further adjustments.- Specified by:
getDefaults
in interfaceComponentRepository<ConfigItem>
- Parameters:
defs
- is aMap
collection where all repository configuration defaults must be put.params
- is aMap
collection with some preset properties for the server. These settings can be used to adjust repository defaults, for example they can contain database connection URL or initial list of virtual domains.
-
getInitProperties
public java.util.Map<java.lang.String,java.lang.Object> getInitProperties()
- Specified by:
getInitProperties
in interfaceConfigRepositoryIfc
-
getItem
public ConfigItem getItem(java.lang.String compName, java.lang.String node, java.lang.String key)
-
getItem
public ConfigItem getItem(java.lang.String key)
Description copied from interface:ComponentRepository
The method returns all item configuration parameters for a key ornull
if the item does not exist in the repository.- Specified by:
getItem
in interfaceComponentRepository<ConfigItem>
- Parameters:
key
- aString
with item identifier to search for.- Returns:
- a
Item
for a given key ornull
if the item is not in the repository.
-
getItemInstance
public ConfigItem getItemInstance()
Description copied from interface:ComponentRepository
Creates a new, uninitialized instance of the repository Item.- Specified by:
getItemInstance
in interfaceComponentRepository<ConfigItem>
- Returns:
- a new, uninitialized instance of the repository Item.
-
getItemsForComponent
public java.util.Set<ConfigItem> getItemsForComponent(java.lang.String compName)
Description copied from interface:ConfigRepositoryIfc
Get set of config items stored for component- Specified by:
getItemsForComponent
in interfaceConfigRepositoryIfc
- Returns:
- set of component items
-
getKeys
public java.lang.String[] getKeys(java.lang.String compName, java.lang.String node)
Description copied from interface:ConfigRepositoryIfc
Returns an array of all configuration keys for a given component and configuration node.- Specified by:
getKeys
in interfaceConfigRepositoryIfc
- Returns:
- array of keys for component and node
-
getProperties
@Deprecated public java.util.Map<java.lang.String,java.lang.Object> getProperties(java.lang.String compName) throws ConfigurationException
Deprecated.Description copied from interface:ConfigRepositoryIfc
Returns all known settings for the given component name.- Specified by:
getProperties
in interfaceConfigRepositoryIfc
- Returns:
- map with configuration
- Throws:
ConfigurationException
-
initRepository
@Deprecated public void initRepository(java.lang.String resource_uri, java.util.Map<java.lang.String,java.lang.String> params) throws DBInitException
Deprecated.Description copied from interface:Repository
Method is deprecated and should not be user any more.
The method is called to initialize the data repository. Depending on the implementation all the initialization parameters can be passed either viaresource_uri
parameter as the database connection string or viaparams
map if the required repository parameters are more complex or both.- Specified by:
initRepository
in interfaceRepository
- Parameters:
resource_uri
- value in most cases representing the database connection string.params
- is aMap
with repository properties necessary to initialize and perform all the functions. The initialization parameters are implementation dependent.- Throws:
DBInitException
- if there was an error during repository initialization. Some implementations, though, perform so called lazy initialization so even though there is a problem with the underlying repository it may not be signaled through this method call.
-
iterator
public java.util.Iterator<ConfigItem> iterator()
- Specified by:
iterator
in interfacejava.lang.Iterable<ConfigItem>
-
putProperties
public void putProperties(java.lang.String compName, java.util.Map<java.lang.String,java.lang.Object> props) throws ConfigurationException
Description copied from interface:ConfigRepositoryIfc
Sets/adds properties for the given component name.- Specified by:
putProperties
in interfaceConfigRepositoryIfc
- Throws:
ConfigurationException
-
reload
public void reload() throws TigaseDBException
Description copied from interface:ComponentRepository
This method is called to reload items from the database or other permanent storage. It is possible that items list is modified externally by third-party system. When all modifications are done this method is called to refresh the class cache. Whether the implementation load whole list or just last modifications is implementation dependent.- Specified by:
reload
in interfaceComponentRepository<ConfigItem>
- Throws:
TigaseDBException
-
remove
public void remove(java.lang.String compName, java.lang.String node, java.lang.String key)
Description copied from interface:ConfigRepositoryIfc
Removes a configuration setting from the configuration repository.- Specified by:
remove
in interfaceConfigRepositoryIfc
-
removeItem
public void removeItem(java.lang.String compName, ConfigItem item)
-
removeItem
public void removeItem(java.lang.String key) throws TigaseDBException
Description copied from interface:ComponentRepository
The method is called to remove given Item from the memory cache and permanent storage. After this method is completed the item should no longer be available in the component repository.- Specified by:
removeItem
in interfaceComponentRepository<ConfigItem>
- Parameters:
key
- aString
with domain name to remove.- Throws:
TigaseDBException
-
removeItemNoStore
public void removeItemNoStore(java.lang.String key)
- Specified by:
removeItemNoStore
in interfaceComponentRepository<ConfigItem>
-
set
public void set(java.lang.String compName, java.lang.String node, java.lang.String key, java.lang.Object value)
Description copied from interface:ConfigRepositoryIfc
Puts/sets/adds/updates a configuration setting to the configuration repository.- Specified by:
set
in interfaceConfigRepositoryIfc
-
setProperties
@Deprecated public void setProperties(java.util.Map<java.lang.String,java.lang.Object> properties)
Deprecated.Description copied from interface:ComponentRepository
The method is called to set configuration for this repository implementation. The configuration is repository implementation dependent. There are no default settings for the repository.- Specified by:
setProperties
in interfaceComponentRepository<ConfigItem>
- Parameters:
properties
- aMap
with configuration settings. Content of thisMap
must not be modified. This read-only collection.
-
size
public int size()
Description copied from interface:ComponentRepository
The method returns number of items in the repository.- Specified by:
size
in interfaceComponentRepository<ConfigItem>
- Returns:
- an
int
value with number of items in the repository.
-
store
public void store() throws TigaseDBException
Description copied from interface:ComponentRepository
The method is called to store all data in the database. It is used when the repository has been changed in some way and the changes have to be put to a permanent storage for later retrieval.- Specified by:
store
in interfaceComponentRepository<ConfigItem>
- Throws:
TigaseDBException
-
validateItem
public java.lang.String validateItem(ConfigItem item)
Description copied from interface:ComponentRepository
Performs Item validation to check whether it meets the repository policy. If validation is successful the method returnsnull
, otherwise it returns an error description.- Specified by:
validateItem
in interfaceComponentRepository<ConfigItem>
- Parameters:
item
- is anItem
object to perform validation checking upon.- Returns:
null
on success and an error message otherwise.
-
setAutoloadTimer
public void setAutoloadTimer(long delay)
Description copied from interface:ComponentRepository
Sets autoload task to periodically reload data from database.- Specified by:
setAutoloadTimer
in interfaceComponentRepository<ConfigItem>
- Parameters:
delay
- in seconds between each database reload.
-
-