Change Notification

Database Considerations

The change notification support of TMCore allows any thread to monitor the database for changes made by other threads to a specific topic map. The thread receives notification of the addition, removal or modification of all topics and associations in a topic map. Any changes to an object contained by a topic or association, including creation and removal are reported as a modification of the containing topic or association object.

The interface IChangeNotifier defines an abstract interface for this change notification system. This interface defines two events, AssociationChange and TopicChange. These two events are both of type ObjectChangeNotification which have the following signature:

VB:
Public Delegate Sub ObjectChangeNotification( _
   ByVal objectID As String, _
   ByVal topicmapID As String, _
   ByVal changeType As ChangeType, _
   ByVal changeID As Integer _
)

C#:
public delegate void ObjectChangeNotification(
   string objectID,
   string topicmapID,
   ChangeType changeType,
   int changeID
);

The objectID and topicmapID parameters specify the unique identifier of the object that was modified and of the topic map that contains the modified object. The changeType parameter is an enumerated type with the values CREATE, UPDATE and DELETE to notify creation, modification and removal events respectively. The changeID integer is a unique identifier for this change event. The identifier is a simple incrementing integer and so can be used to track the last event notified across multiple sessions (e.g. to determine if the listener missed an event for some reason).

The IChangeNotifier interface also defines methods for starting and stopping the polling of the database. The method StartPolling(long interval) begins the polling of the database with an interval between polls specified in milliseconds by the parameter interval. When the startPolling() method is invoked, the first poll will be performed immediately, with subsequent polls ocurring each time the polling interval elapses. The method StopPolling() can be used to halt polling immediately. The method SetPollingInterval(long interval) can be used to modify the polling interval while the polling loop is running. The IChangeNotifier implementation is responsible for its own thread management, so the calling application does not need to create a new thread to run the IChangeNotifier instance in.