com.apama.correlator.memstore.notifications
Class RowChangedSubscriptionManager

java.lang.Object
  extended by com.apama.correlator.memstore.notifications.RowChangedSubscriptionManager

public abstract class RowChangedSubscriptionManager
extends java.lang.Object

A per-table helper object for managing each context's subscription to notifications about the table.

Distributed store driver writers who wish to support notifications can do so by providing an instance of this class in their provider AbstractTable subclass, which should provide implementations for addRowChangedListener and removeRowChangedListener, which are invoked on the first subscription and on the last subscription being removed respectively. After addRowChangedListener has been called, the provider should call fireRowChanged on the RowChangedSubscriptionManager.

Threading: this class is thread-safe.


Constructor Summary
RowChangedSubscriptionManager(java.lang.String storeName, java.lang.String tableName, java.lang.String[] schemaTypes)
          Create a row changed subscription manager.
 
Method Summary
abstract  void addRowChangedListener()
          Register with the distributed table so that row changed notifications can be fired on this object.
 void addSubscription(long contextId, long subscriptionId)
          Adds a subscription.
<K,V> void
fireRowChanged(RowChangedType rowChangedType, K keyObject, V oldValue, V newValue, RowKeyValueConverter<K,V> converter)
          Notifies subscribed contexts of a change to a table row, using the specified converter to translate key and value types from custom application-specific classes K and V into String, RowValue pairs.
 void fireRowChanged(RowChangedType rowChangedType, java.lang.String key, RowValue oldValue, RowValue newValue)
          Notifies subscribed contexts of a change to a table row, using key and values described using the standard String/RowValue types.
abstract  void removeRowChangedListener()
          Remove registration with the distributed table for row changed notifications.
 void removeSubscription(long contextId, long subscriptionId)
          Removes and closes this subscription so long as we are not shutting down.
 void shutdown()
          Shuts the subscription manager down.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RowChangedSubscriptionManager

public RowChangedSubscriptionManager(java.lang.String storeName,
                                     java.lang.String tableName,
                                     java.lang.String[] schemaTypes)
Create a row changed subscription manager.

Parameters:
storeName - the store name
tableName - the table name
schemaTypes - the schema types, as passed to AbstractStore.createTable
Method Detail

addRowChangedListener

public abstract void addRowChangedListener()
Register with the distributed table so that row changed notifications can be fired on this object.

Threading: Is allowed to call into provider code.


removeRowChangedListener

public abstract void removeRowChangedListener()
Remove registration with the distributed table for row changed notifications.


addSubscription

public final void addSubscription(long contextId,
                                  long subscriptionId)
Adds a subscription.

This is used by distributed MemoryStore and does not need to be overridden or called by a driver implementation.

RowChangedSubscriptionManager will reference count the subscriptions, calling addRowChangedListener on the first subscription.

None of our code should be holding locks when this method is called, since we will be calling into the 3rd party provider code and it may acquires its own locks.

Parameters:
contextId - should never be null
subscriptionId - should never be null

removeSubscription

public final void removeSubscription(long contextId,
                                     long subscriptionId)
Removes and closes this subscription so long as we are not shutting down.

This is used by distributed MemoryStore and does not need to be overridden or called by a driver implementation.

Parameters:
contextId - the id of the context from which the subscription to remove was made
subscriptionId - the id of the subscription to remove

fireRowChanged

public <K,V> void fireRowChanged(RowChangedType rowChangedType,
                                 K keyObject,
                                 V oldValue,
                                 V newValue,
                                 RowKeyValueConverter<K,V> converter)
Notifies subscribed contexts of a change to a table row, using the specified converter to translate key and value types from custom application-specific classes K and V into String, RowValue pairs.

Applications should normally use the alternative fireRowChanged(RowChangedType, String, RowValue, RowValue) override, unless they are using custom application-specific classes to represent keys and values in the map.

fireRowChanged should be called every time a row has changed, be it as a result of an insert, update or remove.

Parameters:
rowChangedType - The type of action that resulted in this change request being fired, ie. Update, Insert, remove
keyObject - The key that represents this Row. Must not be null.
oldValue - In some cases this will be set to indicate the oldValue, ie. before it was changed, eg. on updates and removes
newValue - In some cases this will be set to indicate a new value for the row, eg. on Inserts and updates
converter - Converter object for translating the specified key and values into standard String,RowValue objects.

fireRowChanged

public void fireRowChanged(RowChangedType rowChangedType,
                           java.lang.String key,
                           RowValue oldValue,
                           RowValue newValue)
Notifies subscribed contexts of a change to a table row, using key and values described using the standard String/RowValue types.

fireRowChanged should be called every time a row has changed, be it as a result of an insert, update or remove.

Parameters:
rowChangedType - The type of action that resulted in this change request being fired, ie. Update, Insert, remove
key - The key that represents this Row
oldValue - In some cases this will be set to indicate the oldValue, ie. before it was changed, eg. on updates and removes
newValue - In some cases this will be set to indicate a new value for the row, eg. on Inserts and updates

shutdown

public void shutdown()
Shuts the subscription manager down.

No more subscriptions can be added or removed after this completes, and any existing subscriptions are guaranteed to have been closed.



Submit a bug or feature
Copyright (c) 2013 Software AG, Darmstadt, Germany and/or Software AG USA Inc., Reston, VA, USA, and/or Terracotta Inc., San Francisco, CA, USA, and/or Software AG (Canada) Inc., Cambridge, Ontario, Canada, and/or, Software AG (UK) Ltd., Derby, United Kingdom, and/or Software A.G. (Israel) Ltd., Or-Yehuda, Israel and/or their licensors. Use, reproduction, transfer, publication or disclosure is prohibited except as specifically provided for in your License Agreement with Software AG