Class TransactionalCompositeConfiguration
- All Implemented Interfaces:
Transactional,Cloneable,Configuration,EventSource,ImmutableConfiguration,SynchronizerSupport
CompositeConfiguration of which a thread can group the accesses into a
transaction. A read-only transaction holds the read lock of this composite, so that no other
thread writes it; a writable transaction holds the write lock, so that no other thread reads or
writes it. The lock is that of the Synchronizer of this composite, which therefore
has to lock, as the ReadWriteSynchronizer set by the
ConfigurationManager does. Since a read lock cannot be upgraded, writing or starting
a writable level within a read-only transaction is refused instead of waiting forever.
If the in-memory configuration supports transactions, a transaction of this composite starts one there, which stores the changed values; otherwise the transaction only locks. The other child configurations do not take part: setting or removing a value removes it from each of them only when the outermost level of the transaction is finished, after the in-memory configuration has committed, so that rolling back the transaction leaves them unchanged.
A single setProperty or clearProperty runs within a transaction,
joining one of the calling thread, so that rolling back after a failure restores the old value of
the in-memory configuration. Outside a transaction, its own level is the outermost one, so it
removes the value from the other child configurations when it finishes and leaves them unchanged
if it fails. A subset of this composite sets and clears a value through this composite, so this
holds for the subset too.
Unlike the library's composite, this one hands a value to the in-memory configuration as it is, a collection as a whole, so that the in-memory configuration decides how to store it. A subset of this composite adds a value through this composite, so that it is handed over as a whole too.
-
Constructor Summary
ConstructorsConstructorDescriptionTransactionalCompositeConfiguration(Configuration inMemoryConfiguration) Creates a new composite configuration having the designated in-memory configuration, which stores the values changed through this composite. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddPropertyInternal(String key, Object value) protected voidbeginWrite(boolean optimize) protected voidclone()Refuses to clone this composite: a copy would share the transactions of the threads with it.voidCloses the current level of the transaction of the calling thread.voidFinishes the current level of the transaction of the calling thread.protected voidsetPropertyInternal(String key, Object value) voidstartTransaction(boolean readOnly) Starts a transaction of the calling thread on this object.Methods inherited from class org.apache.commons.configuration2.CompositeConfiguration
addConfiguration, addConfiguration, addConfigurationFirst, addConfigurationFirst, addPropertyDirect, clearInternal, containsKeyInternal, containsValueInternal, getConfiguration, getInMemoryConfiguration, getKeysInternal, getKeysInternal, getKeysInternal, getList, getNumberOfConfigurations, getPropertyInternal, getSource, getStringArray, isEmptyInternal, removeConfiguration, setListDelimiterHandlerMethods inherited from class org.apache.commons.configuration2.AbstractConfiguration
addErrorLogListener, addProperty, append, beginRead, clear, clearProperty, cloneInterpolator, contains, containsKey, containsValue, copy, endRead, endWrite, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getConfigurationDecoder, getConversionHandler, getDouble, getDouble, getDouble, getDuration, getDuration, getEncodedString, getEncodedString, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getKeys, getKeys, getList, getList, getList, getListDelimiterHandler, getLogger, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getSynchronizer, immutableSubset, initLogger, installInterpolator, interpolate, interpolate, interpolatedConfiguration, isEmpty, isScalarValue, isThrowExceptionOnMissing, lock, setConfigurationDecoder, setConversionHandler, setDefaultLookups, setInterpolator, setLogger, setParentInterpolator, setPrefixLookups, setProperty, setSynchronizer, setThrowExceptionOnMissing, size, sizeInternal, unlockMethods inherited from class org.apache.commons.configuration2.event.BaseEventSource
addEventListener, clearErrorListeners, clearEventListeners, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEventsMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration
entrySet, forEach, getEnum, getEnum
-
Constructor Details
-
TransactionalCompositeConfiguration
Creates a new composite configuration having the designated in-memory configuration, which stores the values changed through this composite.- Parameters:
inMemoryConfiguration- The configuration which stores the values changed through this composite.
-
-
Method Details
-
startTransaction
public void startTransaction(boolean readOnly) Description copied from interface:TransactionalStarts a transaction of the calling thread on this object. If the calling thread has started one already, this joins it and opens another level. A failed start leaves no level behind.- Specified by:
startTransactionin interfaceTransactional- Parameters:
readOnly- Whether the transaction only reads values. This is set by the outermost start; a nested read-only level joins a writable transaction.
-
finishTransaction
public void finishTransaction()Description copied from interface:TransactionalFinishes the current level of the transaction of the calling thread. Finishing the outermost level commits the transaction, finishing a nested level only ends that level. The level still has to be closed. If committing fails, the outermost level remains unfinished, so that closing it rolls the transaction back.- Specified by:
finishTransactionin interfaceTransactional
-
closeTransaction
public void closeTransaction()Description copied from interface:TransactionalCloses the current level of the transaction of the calling thread. Closing the outermost level rolls the transaction back unless it has been finished, and releases what the transaction holds. This belongs in afinallyblock. So as not to hide the exception which skipped finishing, a failure when rolling back or releasing is logged instead of thrown.- Specified by:
closeTransactionin interfaceTransactional
-
clone
Refuses to clone this composite: a copy would share the transactions of the threads with it.- Overrides:
clonein classCompositeConfiguration- Returns:
- Nothing, this always throws.
- Throws:
ConfigurationRuntimeException- Since this composite cannot be cloned, aConfigurationRuntimeExceptionwrapping aCloneNotSupportedExceptionwill always be thrown.
-
addPropertyInternal
- Overrides:
addPropertyInternalin classAbstractConfiguration
-
setPropertyInternal
- Overrides:
setPropertyInternalin classAbstractConfiguration
-
clearPropertyDirect
- Overrides:
clearPropertyDirectin classCompositeConfiguration
-
subset
- Specified by:
subsetin interfaceConfiguration- Overrides:
subsetin classAbstractConfiguration
-
beginWrite
protected void beginWrite(boolean optimize) - Overrides:
beginWritein classAbstractConfiguration
-