|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.ov4j.hessianImpl.Container<T,C>
public class Container<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
Field Summary | |
---|---|
protected java.util.ArrayList<C> |
cachedIds
IDs kept in cache. |
protected boolean |
closed
Flag to indicate if DB is closed. |
protected boolean |
closing
Flag for closing. |
protected long |
counter
Next filename to assign. |
protected java.lang.String |
dbName
Name of the DB. |
protected static java.lang.String |
DELETED_FOLDER
Folder name where to store deleted ids. |
protected java.util.TreeMap<C,java.lang.String> |
deletedMap
Current live deleted ID to filename Map. |
protected java.util.TreeMap<C,java.lang.String> |
deletedMapWrk
Current work deleted ID to filename Map. |
protected static java.lang.Comparable<?>[] |
EMPTY_COMPARABLE_ARRAY
Empty Comparable array. |
protected static DirFileFilter |
FOLDER_FILTER
FileFilter accepting folder files. |
protected java.lang.Thread |
hookThread
Shutdown hook to make sure memory is saved to file when VM shuts down. |
protected java.util.TreeMap<C,java.lang.String> |
idMap
Current live ID to filename Map. |
protected java.util.TreeMap<C,java.lang.String> |
idMapWrk
Current work ID to filename Map. |
protected static java.lang.String |
ITEM_FOLDER
Folder name where to store items. |
protected static java.lang.String |
LIVE_FOLDER
Folder name where to store live data. |
protected java.io.File |
liveDeleted
Live deleted ids folder. |
protected java.io.File |
liveItems
Live items folder. |
protected static long |
MAX_CACHE_TIME
Maximum amount of time an item will stay cached before being uncached automatically. |
protected static int |
MAX_ITEM_CACHED
Maximum number of items to cache. |
protected static int |
MAX_LOADTHREAD
Maximum number of items to cache. |
protected static int |
MAX_RETRY
Maximum number of save retries when encountering ConcurrentModificationException. |
protected int |
pendingSaves
Number of pending save or delete operations. |
protected java.util.ArrayList<java.lang.Runnable> |
pendingTasks
List of pending tasks to execute. |
protected java.util.TreeMap<C,Item<T,C>> |
recentMap
Recently loaded cache. |
protected java.util.TreeMap<java.lang.String,C> |
revIdMap
Current live filename to ID map. |
protected java.util.TreeMap<java.lang.String,C> |
revIdMapWrk
Current work filename to ID map. |
protected boolean |
runningPendingTasks
Flag for performing pending tasks. |
protected java.lang.Object |
saveLock
Lock used to avoid concurrent saving |
protected static java.lang.String |
VERSION_FOLDER
Folder name where to store versions. |
protected static java.lang.String |
WORK_FOLDER
Folder name where to store work data not yet committed. |
protected java.io.File |
workDeleted
Work deleted ids folder. |
protected java.io.File |
workItems
Work items folder. |
Constructor Summary | |
---|---|
Container(java.lang.String dbName,
long delay,
long saveInterval)
Constructor. |
Method Summary | |
---|---|
protected void |
backup()
Backup the data and ID map databases. |
void |
batchDelete(Item<T,C>[] items,
boolean keepTrack)
Delete an array of items all at once, items which are not found will simply be ignored. |
void |
batchMerge(C[] ids)
Merge an array of items all at once, items which are not found will simply be ignored. |
void |
batchSave(Item<T,C>[] items,
boolean abortOnDuplicate)
Save array of items all at once. |
protected void |
cacheItem(C id,
Item<T,C> it)
Add an item to the cache. |
void |
clear()
Clear all data in the container. |
void |
close()
Close the container. |
void |
close(boolean removeHook)
|
void |
commit()
Commit all changes. |
void |
delete(Item<T,C> it,
boolean keepTrack)
Delete the item. |
C[] |
deletedIds()
Retrieve list of IDs that have been deleted. |
C[] |
deletedIdsSince(long timestamp)
Retrieve a list of IDs that have been deleted since the given timestamp. |
void |
duplicate(IContainer<T,C> cont)
Converts the given IContainer into an hessian implementation. |
protected C |
filenameToId(java.lang.String filename)
Generate ID from filename. |
protected java.lang.String |
idToFilename(C id)
Generate filename for given ID. |
boolean |
inUse(C id)
Determine if the given id is in use. |
boolean |
isClosed()
Determine if the container has already been closed. |
C[] |
listModifiedSince(long timestamp)
List all items modified since the given timestamp. |
Item<T,C>[] |
load(C[] ids,
boolean allVersions)
Load multiple items at once, using the specified ids. |
Item<T,C> |
load(C id,
boolean allVersions)
Load an item using its id. |
Item<T,C>[] |
modifiedSince(long timestamp,
boolean allVersions)
Load all items modified since the given timestamp. |
protected void |
populateDeletedMap()
Populate the deleted ID map from files. |
protected void |
populateIdMap()
Populate the ID map from files. |
void |
release(java.lang.Object obj)
Release the object so it can be garbage collected immediately. |
void |
rollback()
Rollback and discard all changes since last commit. |
void |
save(Item<T,C> it)
Save the item. |
java.lang.String |
toString()
Returns a string representation of this Container. |
protected void |
uncacheItem(C id)
Remove an item from cache. |
void |
waitForPendingSaves()
Wait for all saves and deletes pending tasks to finish. |
void |
waitForPendingTasks()
Wait for all tasks pending tasks to finish. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static final java.lang.Comparable<?>[] EMPTY_COMPARABLE_ARRAY
protected static final java.lang.String ITEM_FOLDER
protected static final java.lang.String VERSION_FOLDER
protected static final java.lang.String DELETED_FOLDER
protected static final java.lang.String LIVE_FOLDER
protected static final java.lang.String WORK_FOLDER
protected static final DirFileFilter FOLDER_FILTER
protected static final int MAX_ITEM_CACHED
protected static final int MAX_LOADTHREAD
protected static final int MAX_RETRY
protected static final long MAX_CACHE_TIME
protected java.lang.String dbName
protected boolean closed
protected java.io.File liveItems
protected java.io.File liveDeleted
protected java.io.File workItems
protected java.io.File workDeleted
protected java.util.TreeMap<C extends java.lang.Comparable<? super C>,java.lang.String> idMap
protected java.util.TreeMap<java.lang.String,C extends java.lang.Comparable<? super C>> revIdMap
protected java.util.TreeMap<C extends java.lang.Comparable<? super C>,java.lang.String> deletedMap
protected java.util.TreeMap<C extends java.lang.Comparable<? super C>,java.lang.String> idMapWrk
protected java.util.TreeMap<java.lang.String,C extends java.lang.Comparable<? super C>> revIdMapWrk
protected java.util.TreeMap<C extends java.lang.Comparable<? super C>,java.lang.String> deletedMapWrk
protected java.util.TreeMap<C extends java.lang.Comparable<? super C>,Item<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>> recentMap
protected java.util.ArrayList<C extends java.lang.Comparable<? super C>> cachedIds
protected long counter
protected final java.lang.Object saveLock
protected java.util.ArrayList<java.lang.Runnable> pendingTasks
protected boolean closing
protected boolean runningPendingTasks
protected int pendingSaves
protected transient java.lang.Thread hookThread
Constructor Detail |
---|
public Container(java.lang.String dbName, long delay, long saveInterval) throws java.io.IOException
dbName
- Name of the database.delay
- Delay before the first save.saveInterval
- Interval (in ms) between periodic replication to backup database.
java.io.IOException
Method Detail |
---|
protected void backup()
public void batchDelete(Item<T,C>[] items, boolean keepTrack) throws java.io.IOException
IContainer
batchDelete
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
items
- Items to be deleted.keepTrack
- Whether or not the ID should be kept in history.
java.io.IOException
org.ov4j.IContainer#batchDelete(org.ov4j.data.Item[], boolean)
public void batchMerge(C[] ids) throws java.io.IOException
IContainer
batchMerge
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
ids
- IDs to be merged.
java.io.IOException
IContainer.batchMerge(java.lang.Comparable[])
public void batchSave(Item<T,C>[] items, boolean abortOnDuplicate) throws java.io.IOException
IContainer
batchSave
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
items
- Array of items to be saved.abortOnDuplicate
- Whether or not saving should abort when an item has an ID already in use.
java.io.IOException
org.ov4j.IContainer#batchSave(org.ov4j.data.Item[], boolean)
protected void cacheItem(C id, Item<T,C> it)
id
- ID of the item.it
- Item to cache.public void clear()
IContainer
clear
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
IContainer.clear()
public void close() throws java.io.IOException
IContainer
close
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
java.io.IOException
IContainer.close()
public void close(boolean removeHook) throws java.io.IOException
java.io.IOException
IContainer.close()
public void commit()
IContainer
commit
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
IContainer.commit()
public void delete(Item<T,C> it, boolean keepTrack) throws java.io.IOException
IContainer
delete
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
it
- Item to be deleted.keepTrack
- Whether or not the ID should be kept in history.
java.io.IOException
IContainer.delete(org.ov4j.data.Item, boolean)
public C[] deletedIds()
IContainer
deletedIds
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
IContainer.deletedIds()
public C[] deletedIdsSince(long timestamp) throws java.io.IOException
IContainer
deletedIdsSince
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
timestamp
- Timestamp to use.
java.io.IOException
IContainer.deletedIdsSince(long)
public void duplicate(IContainer<T,C> cont) throws java.io.IOException
duplicate
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
cont
- IContainer to convert.
java.io.IOException
protected C filenameToId(java.lang.String filename) throws java.io.IOException
filename
- Filename from which to generate ID.
java.io.IOException
protected java.lang.String idToFilename(C id) throws java.io.IOException
id
- ID for which to generate a filename.
java.io.IOException
public boolean inUse(C id)
IContainer
inUse
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
id
- ID to check.
IContainer.inUse(java.lang.Comparable)
public boolean isClosed()
IContainer
isClosed
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
IContainer.isClosed()
public C[] listModifiedSince(long timestamp) throws java.io.IOException
IContainer
listModifiedSince
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
timestamp
- Timestamp to use.
java.io.IOException
IContainer.listModifiedSince(long)
public Item<T,C> load(C id, boolean allVersions) throws java.io.IOException
IContainer
load
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
id
- ID to look for.allVersions
- Whether or not all versions should be loaded.
java.io.IOException
IContainer.load(java.lang.Comparable, boolean)
public Item<T,C>[] load(C[] ids, boolean allVersions) throws java.io.IOException
IContainer
load
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
ids
- Array of IDs to look for.allVersions
- Whether or not all versions should be loaded.
java.io.IOException
IContainer.load(java.lang.Comparable[], boolean)
public Item<T,C>[] modifiedSince(long timestamp, boolean allVersions) throws java.io.IOException
IContainer
modifiedSince
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
timestamp
- Timestamp to use.allVersions
- Whether or not all versions should be loaded.
java.io.IOException
IContainer.modifiedSince(long, boolean)
protected void populateDeletedMap() throws java.io.IOException
java.io.IOException
protected void populateIdMap() throws java.io.IOException
java.io.IOException
public void release(java.lang.Object obj)
IContainer
release
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
obj
- Object to release.IContainer.release(java.lang.Object)
public void rollback()
IContainer
rollback
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
IContainer.rollback()
public void save(Item<T,C> it) throws java.io.IOException
IContainer
save
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
it
- Item to be saved.
java.io.IOException
IContainer.save(org.ov4j.data.Item)
public java.lang.String toString()
toString
in class java.lang.Object
protected void uncacheItem(C id)
id
- ID of the item.public void waitForPendingSaves()
IContainer
waitForPendingSaves
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
IContainer.waitForPendingSaves()
public void waitForPendingTasks()
IContainer
waitForPendingTasks
in interface IContainer<T extends java.lang.Comparable<? super T> & java.lang.Cloneable & java.io.Serializable,C extends java.lang.Comparable<? super C>>
IContainer.waitForPendingTasks()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |