Class WriteableBeanDatabaseImpl
- java.lang.Object
-
- org.glassfish.hk2.configuration.hub.internal.WriteableBeanDatabaseImpl
-
- All Implemented Interfaces:
BeanDatabase,WriteableBeanDatabase
public class WriteableBeanDatabaseImpl extends java.lang.Object implements WriteableBeanDatabase
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classWriteableBeanDatabaseImpl.TwoPhaseResourceImpl
-
Field Summary
Fields Modifier and Type Field Description private longbaseRevisionprivate java.util.LinkedList<Change>changesprivate java.lang.ObjectcommitMessageprivate booleancommittedprivate HubImplhubprivate java.util.LinkedList<WriteableTypeImpl>removedTypesprivate WriteableBeanDatabaseImpl.TwoPhaseResourceImplresourceprivate java.util.HashMap<java.lang.String,WriteableTypeImpl>types
-
Constructor Summary
Constructors Constructor Description WriteableBeanDatabaseImpl(HubImpl hub, BeanDatabaseImpl currentDatabase)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidaddChange(Change change)WriteableTypeaddType(java.lang.String typeName)Adds a type of the given nameprivate voidcheckState()voidcommit()This method should be called when the writeable database should become the current database.voidcommit(java.lang.Object commitMessage)This method should be called when the writeable database should become the current database.voiddumpDatabase()Dumps the type and instance names to stderrvoiddumpDatabase(java.io.PrintStream output)Dumps the type and instance names to the given streamjava.lang.StringdumpDatabaseAsString()Dumps the type and instance names to a String for debuggingWriteableTypefindOrAddWriteableType(java.lang.String typeName)Gets or creates a writeable type with the given namejava.util.Set<Type>getAllTypes()Gets an unmodifiable set of all the types in the bean databasejava.util.Set<WriteableType>getAllWriteableTypes()Gets an unmodifiable set of all the types in the bean database(package private) longgetBaseRevision()private java.lang.StringgetChanges()java.lang.ObjectgetCommitMessage()Gets the commit message for this writeable bean databaseInstancegetInstance(java.lang.String type, java.lang.String instanceKey)Returns the instance with the given instanceKey from the type with the given nameTwoPhaseResourcegetTwoPhaseResource()Returns a two-phase resource that can be used by a DynamicConfiguration to tie the transaction done by this WriteableBeanDatabase into a commit done by the DynamicConfiguration.TypegetType(java.lang.String type)Gets the type with the given nameWriteableTypegetWriteableType(java.lang.String typeName)Gets a writeable type of the given nameTyperemoveType(java.lang.String typeName)Removed the given type and all of its instances from the database.voidsetCommitMessage(java.lang.Object commitMessage)Sets the commit message for this writeable bean databasejava.lang.StringtoString()
-
-
-
Field Detail
-
baseRevision
private final long baseRevision
-
types
private final java.util.HashMap<java.lang.String,WriteableTypeImpl> types
-
hub
private final HubImpl hub
-
resource
private final WriteableBeanDatabaseImpl.TwoPhaseResourceImpl resource
-
changes
private final java.util.LinkedList<Change> changes
-
removedTypes
private final java.util.LinkedList<WriteableTypeImpl> removedTypes
-
committed
private boolean committed
-
commitMessage
private java.lang.Object commitMessage
-
-
Constructor Detail
-
WriteableBeanDatabaseImpl
WriteableBeanDatabaseImpl(HubImpl hub, BeanDatabaseImpl currentDatabase)
-
-
Method Detail
-
getAllTypes
public java.util.Set<Type> getAllTypes()
Description copied from interface:BeanDatabaseGets an unmodifiable set of all the types in the bean database- Specified by:
getAllTypesin interfaceBeanDatabase- Returns:
- A non-null unmodifiable and possibly empty set of all the types in the database
-
getAllWriteableTypes
public java.util.Set<WriteableType> getAllWriteableTypes()
Description copied from interface:WriteableBeanDatabaseGets an unmodifiable set of all the types in the bean database- Specified by:
getAllWriteableTypesin interfaceWriteableBeanDatabase- Returns:
- A non-null unmodifiable and possibly empty set of all the types in the database
-
getType
public Type getType(java.lang.String type)
Description copied from interface:BeanDatabaseGets the type with the given name- Specified by:
getTypein interfaceBeanDatabase- Parameters:
type- The non-null name- Returns:
- The type corresponding to the given name. May return null
-
getInstance
public Instance getInstance(java.lang.String type, java.lang.String instanceKey)
Description copied from interface:BeanDatabaseReturns the instance with the given instanceKey from the type with the given name- Specified by:
getInstancein interfaceBeanDatabase- Parameters:
type- The non-null name of the type to get the instance frominstanceKey- The non-null key of the instance- Returns:
- The bean from the given type with the given name. Will return null if the type does not exist or an instance with that key does not exist
-
checkState
private void checkState()
-
addType
public WriteableType addType(java.lang.String typeName)
Description copied from interface:WriteableBeanDatabaseAdds a type of the given name- Specified by:
addTypein interfaceWriteableBeanDatabase- Parameters:
typeName- The name of the type to add- Returns:
- The non-null type that has been added to the database
-
removeType
public Type removeType(java.lang.String typeName)
Description copied from interface:WriteableBeanDatabaseRemoved the given type and all of its instances from the database. The set of changes will include the instances removed prior to the change indicating that the type was removed- Specified by:
removeTypein interfaceWriteableBeanDatabase- Parameters:
typeName- The non-null type name- Returns:
- The type that was removed
-
getWriteableType
public WriteableType getWriteableType(java.lang.String typeName)
Description copied from interface:WriteableBeanDatabaseGets a writeable type of the given name- Specified by:
getWriteableTypein interfaceWriteableBeanDatabase- Parameters:
typeName- The non-null name of the type to fetch- Returns:
- The existing type, or null if the type does not already exist
-
findOrAddWriteableType
public WriteableType findOrAddWriteableType(java.lang.String typeName)
Description copied from interface:WriteableBeanDatabaseGets or creates a writeable type with the given name- Specified by:
findOrAddWriteableTypein interfaceWriteableBeanDatabase- Parameters:
typeName- The non-null name of the type to find or create- Returns:
- The non-null writeable type that was created or found
-
commit
public void commit()
Description copied from interface:WriteableBeanDatabaseThis method should be called when the writeable database should become the current database. All changes will be communicated to the listeners. If the current database has been modified since this writeable database was created then this method will throw an IllegalStateException. This version of commit will use the commit message set on this writeable bean database- Specified by:
commitin interfaceWriteableBeanDatabase
-
commit
public void commit(java.lang.Object commitMessage)
Description copied from interface:WriteableBeanDatabaseThis method should be called when the writeable database should become the current database. All changes will be communicated to the listeners. If the current database has been modified since this writeable database was created then this method will throw an IllegalStateException. This version of commit will use the commit message passed in rather than the one set on this writeable bean database- Specified by:
commitin interfaceWriteableBeanDatabase- Parameters:
commitMessage- An object to pass to anyBeanDatabaseUpdateListenerthat is registered
-
getBaseRevision
long getBaseRevision()
-
addChange
void addChange(Change change)
-
dumpDatabase
public void dumpDatabase()
Description copied from interface:BeanDatabaseDumps the type and instance names to stderr- Specified by:
dumpDatabasein interfaceBeanDatabase
-
dumpDatabase
public void dumpDatabase(java.io.PrintStream output)
Description copied from interface:BeanDatabaseDumps the type and instance names to the given stream- Specified by:
dumpDatabasein interfaceBeanDatabase- Parameters:
output- - The non-null outut stream to write the database to
-
dumpDatabaseAsString
public java.lang.String dumpDatabaseAsString()
Description copied from interface:BeanDatabaseDumps the type and instance names to a String for debugging- Specified by:
dumpDatabaseAsStringin interfaceBeanDatabase- Returns:
- A string with all type and instance names
-
getTwoPhaseResource
public TwoPhaseResource getTwoPhaseResource()
Description copied from interface:WriteableBeanDatabaseReturns a two-phase resource that can be used by a DynamicConfiguration to tie the transaction done by this WriteableBeanDatabase into a commit done by the DynamicConfiguration. When the DynamicConfiguration calls commit this WriteableBeanDatabase will be part of the transaction- Specified by:
getTwoPhaseResourcein interfaceWriteableBeanDatabase- Returns:
- A non-null TwoPhaseResource to be used by a DynamicConfiguration
-
getCommitMessage
public java.lang.Object getCommitMessage()
Description copied from interface:WriteableBeanDatabaseGets the commit message for this writeable bean database- Specified by:
getCommitMessagein interfaceWriteableBeanDatabase- Returns:
- The possibly null commit message for this writeable bean database
-
setCommitMessage
public void setCommitMessage(java.lang.Object commitMessage)
Description copied from interface:WriteableBeanDatabaseSets the commit message for this writeable bean database- Specified by:
setCommitMessagein interfaceWriteableBeanDatabase- Parameters:
commitMessage- The possibly null commit message for this writeable bean database
-
getChanges
private java.lang.String getChanges()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-