Package elki.database
Class DatabaseEventManager
- java.lang.Object
-
- elki.database.DatabaseEventManager
-
public class DatabaseEventManager extends java.lang.Object
Class to manage database events such as insertions and removals.- Since:
- 0.4.0
- Author:
- Elke Achtert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DatabaseEventManager.Type
Types for aggregation.
-
Field Summary
Fields Modifier and Type Field Description private boolean
accumulateDataStoreEvents
Indicates whether DataStoreEvents should be accumulated and fired as one event on demand.private DatabaseEventManager.Type
currentDataStoreEventType
The type of the current DataStoreEvent to be accumulated.private java.util.List<DataStoreListener>
dataListenerList
Holds the listeners for data store changesprivate HashSetModifiableDBIDs
dataStoreObjects
The objects that were changed in the current DataStoreEvent.private java.util.List<ResultListener>
resultListenerList
Holds the listeners for result changes.
-
Constructor Summary
Constructors Constructor Description DatabaseEventManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accumulateDataStoreEvents()
Collects successive insertion, deletion or update events.void
addListener(DataStoreListener l)
Adds aDataStoreListener
for aDataStoreEvent
posted after the content of the database changes.void
addListener(ResultListener l)
Adds aResultListener
to be notified on new results.private void
fireObjectChanged(DBIDRef object, DatabaseEventManager.Type type)
Handles a DataStoreEvent with the specified type.void
fireObjectInserted(DBIDRef insertion)
Event when a new object was inserted.protected void
fireObjectRemoved(DBIDRef deletion)
Event when an objects was removed / deleted.private void
fireObjectsChanged(DBIDs objects, DatabaseEventManager.Type type)
Handles a DataStoreEvent with the specified type.void
fireObjectsInserted(DBIDs insertions)
Event when new objects are inserted.protected void
fireObjectsRemoved(DBIDs deletions)
Event when objects were removed / deleted.void
fireObjectsUpdated(DBIDRef update)
Event when an object was changed / updated.void
fireObjectsUpdated(DBIDs updates)
Event when objects have changed / were updated.void
fireResultAdded(java.lang.Object r, java.lang.Object parent)
Informs all registeredResultListener
that a new result was added.void
fireResultRemoved(java.lang.Object r, java.lang.Object parent)
Informs all registeredResultListener
that a new result has been removed.void
flushDataStoreEvents()
Fires all collected insertion, deletion or update events as one DataStoreEvent, i.e. notifies all registered DataStoreListener how the content of the database has been changed sinceaccumulateDataStoreEvents()
was called.void
removeListener(DataStoreListener l)
Removes aDataStoreListener
previously added withaddListener(DataStoreListener)
.void
removeListener(ResultListener l)
Removes aResultListener
previously added withaddListener(ResultListener)
.
-
-
-
Field Detail
-
dataListenerList
private java.util.List<DataStoreListener> dataListenerList
Holds the listeners for data store changes
-
resultListenerList
private java.util.List<ResultListener> resultListenerList
Holds the listeners for result changes.
-
accumulateDataStoreEvents
private boolean accumulateDataStoreEvents
Indicates whether DataStoreEvents should be accumulated and fired as one event on demand.
-
currentDataStoreEventType
private DatabaseEventManager.Type currentDataStoreEventType
The type of the current DataStoreEvent to be accumulated.
-
dataStoreObjects
private HashSetModifiableDBIDs dataStoreObjects
The objects that were changed in the current DataStoreEvent.
-
-
Method Detail
-
accumulateDataStoreEvents
public void accumulateDataStoreEvents()
Collects successive insertion, deletion or update events. The accumulated event will be fired whenflushDataStoreEvents()
is called or a different event type occurs.- See Also:
flushDataStoreEvents()
,DataStoreEvent
-
flushDataStoreEvents
public void flushDataStoreEvents()
Fires all collected insertion, deletion or update events as one DataStoreEvent, i.e. notifies all registered DataStoreListener how the content of the database has been changed sinceaccumulateDataStoreEvents()
was called.- See Also:
accumulateDataStoreEvents
,DataStoreListener
,DataStoreEvent
-
addListener
public void addListener(DataStoreListener l)
Adds aDataStoreListener
for aDataStoreEvent
posted after the content of the database changes.- Parameters:
l
- the listener to add- See Also:
removeListener(DataStoreListener)
,DataStoreListener
,DataStoreEvent
-
removeListener
public void removeListener(DataStoreListener l)
Removes aDataStoreListener
previously added withaddListener(DataStoreListener)
.- Parameters:
l
- the listener to remove- See Also:
addListener(DataStoreListener)
,DataStoreListener
,DataStoreEvent
-
addListener
public void addListener(ResultListener l)
Adds aResultListener
to be notified on new results.- Parameters:
l
- the listener to add- See Also:
removeListener(ResultListener)
,ResultListener
-
removeListener
public void removeListener(ResultListener l)
Removes aResultListener
previously added withaddListener(ResultListener)
.- Parameters:
l
- the listener to remove- See Also:
addListener(ResultListener)
,ResultListener
-
fireObjectsInserted
public void fireObjectsInserted(DBIDs insertions)
Event when new objects are inserted.- Parameters:
insertions
- the objects that have been inserted
-
fireObjectInserted
public void fireObjectInserted(DBIDRef insertion)
Event when a new object was inserted.- Parameters:
insertion
- the object that was inserted
-
fireObjectsUpdated
public void fireObjectsUpdated(DBIDs updates)
Event when objects have changed / were updated.- Parameters:
updates
- the objects that have been updated
-
fireObjectsUpdated
public void fireObjectsUpdated(DBIDRef update)
Event when an object was changed / updated.- Parameters:
update
- the object that was updated
-
fireObjectsRemoved
protected void fireObjectsRemoved(DBIDs deletions)
Event when objects were removed / deleted.- Parameters:
deletions
- the objects that have been removed
-
fireObjectRemoved
protected void fireObjectRemoved(DBIDRef deletion)
Event when an objects was removed / deleted.- Parameters:
deletion
- the object that has was removed
-
fireObjectsChanged
private void fireObjectsChanged(DBIDs objects, DatabaseEventManager.Type type)
Handles a DataStoreEvent with the specified type. If the current event type is not equal to the specified type, the events accumulated up to now will be fired first. The new event will be aggregated and fired on demand ifaccumulateDataStoreEvents
is set, otherwise all registeredDataStoreListener
will be notified immediately that the content of the database has been changed.- Parameters:
objects
- the objects that have been changed, i.e. inserted, deleted or updated
-
fireObjectChanged
private void fireObjectChanged(DBIDRef object, DatabaseEventManager.Type type)
Handles a DataStoreEvent with the specified type. If the current event type is not equal to the specified type, the events accumulated up to now will be fired first. The new event will be aggregated and fired on demand ifaccumulateDataStoreEvents
is set, otherwise all registeredDataStoreListener
will be notified immediately that the content of the database has been changed.- Parameters:
object
- the object that has been changed, i.e. inserted, deleted or updated
-
fireResultAdded
public void fireResultAdded(java.lang.Object r, java.lang.Object parent)
Informs all registeredResultListener
that a new result was added.- Parameters:
r
- New child result addedparent
- Parent result that was added to
-
fireResultRemoved
public void fireResultRemoved(java.lang.Object r, java.lang.Object parent)
Informs all registeredResultListener
that a new result has been removed.- Parameters:
r
- result that has been removedparent
- Parent result that has been removed
-
-