Class ModuleDatabase
Concurrent Semantics
Implementations must be thread safe. The database allows for concurrent read
operations and all read operations are protected by the read
lock. All write operations are protected by the write
lock. The read and write locks are reentrant and follow the semantics
of the ReentrantReadWriteLock
. Just like the
ReentrantReadWriteLock
the lock on a database can not be upgraded
from a read to a write. Doing so will result in an
IllegalMonitorStateException
being thrown. This is behavior is
different from the ReentrantReadWriteLock
which results in a deadlock
if an attempt is made to upgrade from a read to a write lock.
A database is associated with a container
. The
container associated with a database provides public API for manipulating the
modules and their wiring states. For example, installing, updating,
uninstalling, resolving and unresolving modules. Except for the
load(DataInputStream)
, all other methods that perform write
operations are intended to be used by the associated container.
- Since:
- 3.10
-
Constructor Summary
ConstructorDescriptionModuleDatabase
(ModuleContainerAdaptor adaptor) Constructs a new empty database. -
Method Summary
Modifier and TypeMethodDescriptionfinal long
Atomically increments by one the next module ID.final long
returns the next module ID.final long
Returns the current timestamp for the revisions of this database.final long
Returns the current timestamp for this database.final void
load
(DataInputStream in) Loads information into this database from the input data stream.final void
readLock()
Acquires the read lock for this database.final void
Attempts to release the read lock for this database.protected void
removeCapabilities
(ModuleRevision revision) Removes thecapabilities
provided by the specified revision from this database.final void
store
(DataOutputStream out, boolean persistWirings) Writes this database in a format suitable for using theload(DataInputStream)
method.final void
Acquires the write lock for this database.final void
Attempts to release the write lock for this database.
-
Constructor Details
-
ModuleDatabase
Constructs a new empty database.- Parameters:
adaptor
- the module container adaptor
-
-
Method Details
-
getNextId
public final long getNextId()returns the next module ID.A read operation protected by the
read
lock.- Returns:
- the next module ID
-
getAndIncrementNextId
public final long getAndIncrementNextId()Atomically increments by one the next module ID.A write operation protected by the
writeLock()
lock.- Returns:
- the previous module ID
- Since:
- 3.13
-
getRevisionsTimestamp
public final long getRevisionsTimestamp()Returns the current timestamp for the revisions of this database. The timestamp is incremented any time a modification is made to the revisions in this database. For example:- installing a module
- updating a module
- uninstalling a module
- modifying the wirings
A read operation protected by the
read
lock.- Returns:
- the current timestamp of this database.
-
getTimestamp
public final long getTimestamp()Returns the current timestamp for this database. The timestamp is incremented any time a modification is made to this database. This includes the modifications described inrevisions timestamp
and the following modifications related to modules:- modifying the initial module start level
- modifying a module start level
- modifying a module settings
A read operation protected by the
read
lock.- Returns:
- the current timestamp of this database.
-
readLock
public final void readLock()Acquires the read lock for this database.- See Also:
-
writeLock
public final void writeLock()Acquires the write lock for this database. Same asReentrantReadWriteLock.WriteLock.lock()
except an illegal state exception is thrown if the current thread holds one or more read locks.- Throws:
IllegalMonitorStateException
- if the current thread holds one or more read locks.- See Also:
-
readUnlock
public final void readUnlock()Attempts to release the read lock for this database.- See Also:
-
writeUnlock
public final void writeUnlock()Attempts to release the write lock for this database. -
removeCapabilities
Removes thecapabilities
provided by the specified revision from this database. These capabilities must no longer be available for lookup with thefindCapabilities(Requirement)
method.This method must be called while holding the
write
lock. -
store
Writes this database in a format suitable for using theload(DataInputStream)
method. All modules are stored which have a currentrevision
. Only the current revision of each module is stored (no removal pending revisions are stored). Optionally thewiring
of each current revision may be stored. Wiring can only be stored if there are noremoval pending
revisions.This method acquires the
read
lock while writing this database.After this database have been written, the output stream is flushed. The output stream remains open after this method returns.
- Parameters:
out
- the data output steam.persistWirings
- true if wirings should be persisted. This option will be ignored if there areremoval pending
revisions.- Throws:
IOException
- if writing this database to the specified output stream throws an IOException
-
load
Loads information into this database from the input data stream. This data base must be empty and never been modified (thetimestamp
is zero). All stored modules are loaded into this database. If the input stream contains wiring then it will also be loaded into this database.Since this method modifies this database it is considered a write operation. This method acquires the
write
lock while loading the information into this database.The specified stream remains open after this method returns.
- Parameters:
in
- the data input stream.- Throws:
IOException
- if an error occurred when reading from the input stream.IllegalStateException
- if this database is not empty.
-