com.cloudbees.sdk.utils
Class PersistedStore<V>

java.lang.Object
  extended by java.util.AbstractMap<String,V>
      extended by com.cloudbees.sdk.utils.PersistedStore<V>
All Implemented Interfaces:
Map<String,V>
Direct Known Subclasses:
PersistedGAVStore

public abstract class PersistedStore<V>
extends AbstractMap<String,V>

Persisted configuration store of Map<String,V> (for arbitrary V) for configuration data.

The contents is persisted as a directory where the key name is the file name and V as the content of the file. This format allows users to add/remove these things easily from shell. It also simplifies the 3rd party to instruct users to tweak the configuration, as well as making it easy to programmatically modify them without losing comments.

Author:
Kohsuke Kawaguchi

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
PersistedStore()
           
 
Method Summary
protected  V _write(File f, V value)
           
 void clear()
           
 boolean containsKey(Object key)
           
 Set<Map.Entry<String,V>> entrySet()
           
 V get(Object key)
           
 V get(String key)
           
protected abstract  File getStorageDirectory()
          Returns the directory that serves as the persistent storage.
 Set<String> keySet()
           
 V put(String key, V value)
           
protected abstract  V read(File f)
          Reads a data file 'f' into the value.
 V remove(Object key)
           
 V remove(String key)
           
protected abstract  void write(File f, V data)
          Writes the given value to the file
 
Methods inherited from class java.util.AbstractMap
clone, containsValue, equals, hashCode, isEmpty, putAll, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PersistedStore

public PersistedStore()
Method Detail

getStorageDirectory

protected abstract File getStorageDirectory()
Returns the directory that serves as the persistent storage.


read

protected abstract V read(File f)
                   throws IllegalArgumentException
Reads a data file 'f' into the value.

Returns:
null if the file doesn't exist or the content is empty.
Throws:
IllegalArgumentException - if you fail to read it because the content is invalid

write

protected abstract void write(File f,
                              V data)
Writes the given value to the file

Parameters:
data - Never null.

get

public V get(Object key)
Specified by:
get in interface Map<String,V>
Overrides:
get in class AbstractMap<String,V>

get

public V get(String key)

containsKey

public boolean containsKey(Object key)
Specified by:
containsKey in interface Map<String,V>
Overrides:
containsKey in class AbstractMap<String,V>

put

public V put(String key,
             V value)
Specified by:
put in interface Map<String,V>
Overrides:
put in class AbstractMap<String,V>

remove

public V remove(Object key)
Specified by:
remove in interface Map<String,V>
Overrides:
remove in class AbstractMap<String,V>

remove

public V remove(String key)

clear

public void clear()
Specified by:
clear in interface Map<String,V>
Overrides:
clear in class AbstractMap<String,V>

_write

protected V _write(File f,
                   V value)

entrySet

public Set<Map.Entry<String,V>> entrySet()
Specified by:
entrySet in interface Map<String,V>
Specified by:
entrySet in class AbstractMap<String,V>

keySet

public Set<String> keySet()
Specified by:
keySet in interface Map<String,V>
Overrides:
keySet in class AbstractMap<String,V>


Copyright © 2011-2014. All Rights Reserved.