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 SummaryConstructorsConstructorDescriptionModuleDatabase(ModuleContainerAdaptor adaptor) Constructs a new empty database.
- 
Method SummaryModifier and TypeMethodDescriptionfinal longAtomically increments by one the next module ID.final longreturns the next module ID.final longReturns the current timestamp for the revisions of this database.final longReturns the current timestamp for this database.final voidload(DataInputStream in) Loads information into this database from the input data stream.final voidreadLock()Acquires the read lock for this database.final voidAttempts to release the read lock for this database.protected voidremoveCapabilities(ModuleRevision revision) Removes thecapabilitiesprovided by the specified revision from this database.final voidstore(DataOutputStream out, boolean persistWirings) Writes this database in a format suitable for using theload(DataInputStream)method.final voidAcquires the write lock for this database.final voidAttempts to release the write lock for this database.
- 
Constructor Details- 
ModuleDatabaseConstructs a new empty database.- Parameters:
- adaptor- the module container adaptor
 
 
- 
- 
Method Details- 
getNextIdpublic final long getNextId()returns the next module ID.A read operation protected by the readlock.- Returns:
- the next module ID
 
- 
getAndIncrementNextIdpublic 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
 
- 
getRevisionsTimestamppublic 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 readlock.- Returns:
- the current timestamp of this database.
 
- 
getTimestamppublic 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 timestampand 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 readlock.- Returns:
- the current timestamp of this database.
 
- 
readLockpublic final void readLock()Acquires the read lock for this database.- See Also:
 
- 
writeLockpublic 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:
 
- 
readUnlockpublic final void readUnlock()Attempts to release the read lock for this database.- See Also:
 
- 
writeUnlockpublic final void writeUnlock()Attempts to release the write lock for this database.- See Also:
 
- 
removeCapabilitiesRemoves thecapabilitiesprovided 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 writelock.
- 
storeWrites 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 thewiringof each current revision may be stored. Wiring can only be stored if there are noremoval pendingrevisions.This method acquires the readlock 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 are- removal pendingrevisions.
- Throws:
- IOException- if writing this database to the specified output stream throws an IOException
 
- 
loadLoads information into this database from the input data stream. This data base must be empty and never been modified (thetimestampis 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 writelock 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.
 
 
-