|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.microsoft.tfs.core.persistence.FilesystemPersistenceStore
public class FilesystemPersistenceStore
Implements PersistenceStore
by persisting objects to files in
directories on the filesystem. Each instance can be configured to a specific
directory, and item names map to file names in that directory. Children
created via getChildStore(String)
are always a subdirectory of the
parent. Because of the way filesystems work, a
FilesystemPersistenceStore
cannot have a child item with the same
name as a child store.
Child store and item names are case-sensitive if the underlying filesystem is.
Constructor Summary | |
---|---|
FilesystemPersistenceStore(java.io.File directory)
Creates a FilesystemPersistenceStore for the given directory. |
Method Summary | |
---|---|
boolean |
containsItem(java.lang.String itemName)
Tests whether the item exists in this store. |
boolean |
deleteItem(java.lang.String itemName)
Deletes the specified item. |
boolean |
equals(java.lang.Object obj)
|
PersistenceStore |
getChildStore(java.lang.String childName)
Gets a PersistenceStore for the given child name. |
java.io.File |
getItemFile(java.lang.String itemName)
Gets the File for the given item name. |
java.io.InputStream |
getItemInputStream(java.lang.String itemName)
Gets an InputStream for reading the specified item's data. |
AdvisoryFileLock |
getItemLock(java.lang.String itemName,
boolean block)
Gets a thread- and process-exclusive lock for a single item in this PersistenceStore . |
java.io.OutputStream |
getItemOutputStream(java.lang.String itemName)
Gets an OutputStream to write the specified item's data. |
java.io.File |
getStoreFile()
|
AdvisoryFileLock |
getStoreLock(boolean block)
Gets a thread- and process-exclusive lock for the entire PersistenceStore . |
int |
hashCode()
|
void |
initialize()
Creates any storage resources required by the implementation. |
boolean |
migrateItem(PersistenceStore oldStore,
java.lang.String oldItemName,
java.lang.String newItemName)
Copies the persisted item specified by oldItemName from the oldStore into this store with the newItemName. |
java.lang.Object |
retrieveItem(java.lang.String itemName,
LockMode lockMode,
MergeHandler mergeHandler,
ObjectSerializer serializer)
Retrieves an object that was previuosly stored via PersistenceStore.storeItem(String, Object, LockMode, MergeHandler, ObjectSerializer)
. |
boolean |
storeItem(java.lang.String itemName,
java.lang.Object object,
LockMode lockMode,
MergeHandler mergeHandler,
ObjectSerializer serializer)
|
boolean |
storeItem(java.lang.String itemName,
java.lang.Object object,
LockMode lockMode,
MergeHandler mergeHandler,
ObjectSerializer serializer,
PersistenceSecurity security)
Saves an object as the specified item name. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public FilesystemPersistenceStore(java.io.File directory)
FilesystemPersistenceStore
for the given directory.
directory
- the directory, which does not have to exist (must not be
null
)Method Detail |
---|
public PersistenceStore getChildStore(java.lang.String childName)
PersistenceStore
for the given child name.
getChildStore
in interface PersistenceStore
childName
- the child name (must not be null
or empty)
public void initialize() throws java.io.IOException
Creates any storage resources required by the implementation. For example, creates filesystem directories, inserts a key row into a database table, etc.
Calling this method externally is usually not required. This method is
public because some implementations of PersistenceStore
allow
users to interact directly with their storage (for example, files in a
filesystem), and this method ensures resource creation (intermediate
dirctories).
Implementations of this method must be able to be called multiple times
without error (subsequent calls must not fail). Other methods in this
class must call PersistenceStore.initialize()
before they do their work, if their
work requires initialization.
initialize
in interface PersistenceStore
java.io.IOException
- if an exception happened creating the storage locationpublic boolean containsItem(java.lang.String itemName)
containsItem
in interface PersistenceStore
itemName
- the item to test for existence (must not be null
or
empty)
public boolean deleteItem(java.lang.String itemName)
deleteItem
in interface PersistenceStore
itemName
- the item to delete (must not be null
or empty)
public boolean storeItem(java.lang.String itemName, java.lang.Object object, LockMode lockMode, MergeHandler mergeHandler, ObjectSerializer serializer) throws java.io.IOException, java.lang.InterruptedException
storeItem
in interface PersistenceStore
java.io.IOException
java.lang.InterruptedException
public boolean storeItem(java.lang.String itemName, java.lang.Object object, LockMode lockMode, MergeHandler mergeHandler, ObjectSerializer serializer, PersistenceSecurity security) throws java.io.IOException, java.lang.InterruptedException
PersistenceStore.retrieveItem(String, LockMode, MergeHandler, ObjectSerializer)
,
by passing the same item name.
storeItem
in interface PersistenceStore
itemName
- the desired name for the object (must not be null
or
empty)object
- the object to serialize. Access to the Java object is not
synchronized by this method during serialization. If
synchronization is required, it is the responsibility of the
caller (must not be null
)lockMode
- if LockMode.NONE
, no locking is performed. If
LockMode.WAIT_FOREVER
, a lock is obtained and held for the
identifier during the operation (and unlocked before this method
returns). If LockMode.NO_WAIT
, locking is attempted, but
if the lock was not immediately available this method must not
write the serialized object and returns false (must not be
null
)mergeHandler
- if not null
, this MergeHandler
is used to
detect and resolve merge conflicts in the persistence store. If
null, no merging is done: the given component instance will always
overwrite an existing serialized component file on disk.serializer
- specifies the serializer to use (must not be null
)security
- specifies the security with which this item will be saved.
PersistenceSecurity.PUBLIC
indicates that no effort will
be taken by the persistence store to prevent other users from
accessing this data. PersistenceStore#PRIVATE
indicates
that the persistence store will attempt to prevent other users
from accessing this data using the underlying permission model of
the persistence store. (must not be null
)
LockMode.NO_WAIT
was given and the lock could not be
obtained
java.io.IOException
- if an error occurred writing the persistent data (implementation
specific; perhaps insufficient permissions, out of disk space,
etc.).
java.lang.InterruptedException
- if this thread was interrupted while waiting on a lock when the
LockMode
specifies waiting, or while waiting on some
other resourcepublic java.lang.Object retrieveItem(java.lang.String itemName, LockMode lockMode, MergeHandler mergeHandler, ObjectSerializer serializer) throws java.io.IOException, java.lang.InterruptedException
PersistenceStore.storeItem(String, Object, LockMode, MergeHandler, ObjectSerializer)
.
retrieveItem
in interface PersistenceStore
itemName
- the name of the object. (must not be null
or empty)lockMode
- if LockMode.NONE
, no locking is performed. If
LockMode.WAIT_FOREVER
, a lock is obtained and held for the
componentName in this store's settings location during the
operation (and unlocked before this method returns). If
LockMode.NO_WAIT
, locking is attempted, but if the lock
was not immediately available this method does not read the file
and returns false. (must not be null
)mergeHandler
- if not null
, this MergeHandler
is given the
last modification date of the persisted object when it is read, so
the handler can handle future merges. If null, no such
notification is performed and the resource is still read normally.serializer
- specifies the serializer to use (must not be null
)
null
if and only if
LockMode.NO_WAIT
was given and the lock could not be
obtained
java.io.IOException
- if an error occurred reading the persistent data (implementation
specific; perhaps insufficient permissions, out of disk space,
etc.).
java.lang.InterruptedException
- if this thread was interrupted while waiting on a lock when the
LockMode
specifies waiting, or while waiting on some
other resourcepublic boolean migrateItem(PersistenceStore oldStore, java.lang.String oldItemName, java.lang.String newItemName)
Copies the persisted item specified by oldItemName from the oldStore into this store with the newItemName. If the newItemName already exists in this store, it must not be overwritten. Data is only read from the old store, and it is not translated during copying.
Implementations should not rethrow exceptions encountered during migration to make the caller's work easier. They should simply return false.
migrateItem
in interface PersistenceStore
oldStore
- the store to migrate the old item from (not
NullPointerException
, but may be this
PersistenceStore
)oldItemName
- the item to copy from the old store (must not be null
or empty)newItemName
- the item to copy into this store (must not be null
or
empty)
public java.io.InputStream getItemInputStream(java.lang.String itemName) throws java.io.IOException
Gets an InputStream
for reading the specified item's data. No
locking is done by this method.
The behavior of opening an InputStream
for an item that does not
exist is unspecified.
getItemInputStream
in interface PersistenceStore
itemName
- the item to read (must not be null
or empty)
InputStream
open for reading the item
java.io.IOException
- if an error occurred opening the item for readpublic java.io.OutputStream getItemOutputStream(java.lang.String itemName) throws java.io.IOException
Gets an OutputStream
to write the specified item's data. No
locking is done by this method.
Getting an OutputStream
for a valid item name that does not yet
exist in the store should succeed (it should be created).
getItemOutputStream
in interface PersistenceStore
itemName
- the item to write (must not be null
or empty)
OutputStream
open for writing the item
java.io.IOException
- if an error occurred opening the item for writepublic java.lang.String toString()
toString
in class java.lang.Object
public java.io.File getStoreFile()
File
that is the directory where this
PersistenceStore
saves data.public java.io.File getItemFile(java.lang.String itemName)
File
for the given item name.
itemName
- the item name (must not be null
or empty)
File
for the itempublic AdvisoryFileLock getItemLock(java.lang.String itemName, boolean block) throws java.io.IOException, java.lang.InterruptedException
Gets a thread- and process-exclusive lock for a single item in this
PersistenceStore
. A lock on an item is not prevented by a lock on
the entire store. See PersistenceStore.getStoreLock(boolean)
for details.
The lock should be released by its AdvisoryFileLock.release()
method. If you forget (you should not forget), the lock will be released
during its finalization (possibly as late as when the JVM exits).
getItemLock
in interface PersistenceStore
itemName
- the item to get a lock for (must not be null
or
empty)block
- if true, this method does not return until the lock is obtained
(or the controlling thread is interrupted). If false, the method
returns immediately; the value is null if the lock was not
immediately available or a AdvisoryFileLock
if it was.
AdvisoryFileLock
, initially owned. Returns null if and
only if block was set to false and the lock was not immediately
available.
java.io.IOException
- if an exception occured creating or acquiring the underlying lock
java.lang.InterruptedException
- if this thread was interrupted while waiting to acquire the lock.public AdvisoryFileLock getStoreLock(boolean block) throws java.io.IOException, java.lang.InterruptedException
Gets a thread- and process-exclusive lock for the entire
PersistenceStore
. This is simply a different synchronization
point than PersistenceStore.getItemLock(String, boolean)
; a lock on the entire
PersistenceStore
does not interfere (or even interact)
with locks on items.
The lock should be released by its AdvisoryFileLock.release()
method. If you forget (you should not forget), the lock will be released
during its finalization (possibly as late as when the JVM exits).
getStoreLock
in interface PersistenceStore
block
- if true, this method does not return until the lock is obtained
(or the controlling thread is interrupted). If false, the method
returns immediately; the value is null if the lock was not
immediately available or a AdvisoryFileLock
if it was.
AdvisoryFileLock
, initially owned. Returns null if and
only if block was set to false and the lock was not immediately
available.
java.io.IOException
- if an exception occured creating or acquiring the underlying lock
java.lang.InterruptedException
- if this thread was interrupted while waiting to acquire the lock.public int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |