private void SetCacheListener(string regionName, ICacheListener <string, string> listener) { GIRegion region = CacheHelper.GetVerifyRegion <string, string>(regionName); AttributesMutator <string, string> attrMutator = region.AttributesMutator; attrMutator.SetCacheListener(listener); }
/// <summary> /// Dispatch the specified <see cref="CacheEvent"/> to all /// <see cref="Support.CacheListenerSupport.ISynchronousListener"/> /// objects and add to the specified <see cref="Queue"/> for deferred /// execution for standard ones. /// </summary> /// <param name="evt"> /// <b>CacheEvent</b> to dispatch. /// </param> /// <param name="listeners"> /// <b>Listeners</b> to which the event is dispatched. /// </param> /// <param name="queue"> /// <b>Queue</b> to which event will be added. /// </param> public static void DispatchSafe(CacheEventArgs evt, Listeners listeners, Queue queue) { if (listeners != null) { object[] listenersArray = listeners.ListenersArray; for (int i = 0, c = listenersArray.Length; i < c; i++) { ICacheListener listener = (ICacheListener)listenersArray[i]; if (listener is CacheListenerSupport.ISynchronousListener) { try { CacheListenerSupport.Dispatch(evt, listener); } catch (Exception e) { CacheFactory.Log("An exception occured while dispatching synchronous event:" + evt, CacheFactory.LogLevel.Error); CacheFactory.Log(e, CacheFactory.LogLevel.Error); CacheFactory.Log("(The exception has been logged and execution is continuing.)", CacheFactory.LogLevel.Error); } } else { queue.Add(Instantiate(evt, listener)); } } } }
public static void CreateClient <TKey, TValue>(string regionName, string locators, string authInit, Properties <string, string> credentials, bool caching, bool clientNotification, int redundancyLevel, int numConnections, ICacheListener <TKey, TValue> listener, ExpectedResult expect) { CreateClient <TKey, TValue>(regionName, locators, authInit, credentials, true, true, redundancyLevel, numConnections, null, expect, false, null, false, false); }
/// <summary> /// Add an index to the given dictionary of indexes, keyed by the given /// extractor. Also add the index as a listener to the given cache. /// </summary> /// <param name="extractor"> /// The IValueExtractor object that is used to extract an indexable /// property value from a cache entry. /// </param> /// <param name="ordered"> /// True if the contents of the indexed information should be ordered; /// false otherwise /// </param> /// <param name="comparator"> /// The IComparer object which imposes an ordering on entries in the /// indexed cache or <c>null</c> if the entries' values natural /// ordering should be used. /// </param> /// <param name="cache"> /// The cache that the newly created ICacheIndex will use for /// initialization and listen to for changes. /// </param> /// <param name="dictIndex"> /// The dictionary of indexes that the newly created ICacheIndex will /// be added to. /// </param> public static void AddIndex(IValueExtractor extractor, bool ordered, IComparer comparator, IObservableCache cache, IDictionary dictIndex) { var index = (ICacheIndex)dictIndex[extractor]; if (index == null) { for (int cAttempts = 4; ;) { if (extractor is IIndexAwareExtractor) { index = ((IIndexAwareExtractor)extractor). CreateIndex(ordered, comparator, dictIndex); if (index == null) { return; } } else { index = new SimpleCacheIndex(extractor, ordered, comparator); dictIndex[extractor] = index; } ICacheListener listener = EnsureListener(index); cache.AddCacheListener(listener, null, false); try { // build the index foreach (ICacheEntry entry in cache) { index.Insert(entry); } break; } catch (InvalidOperationException ioe) //collection was modified { cache.RemoveCacheListener(listener); if (--cAttempts == 0) { RemoveIndex(extractor, cache, dictIndex); CacheFactory.Log("Exception occured during index rebuild: " + ioe, CacheFactory.LogLevel.Error); throw; } } } } else if (!(ordered == index.IsOrdered && Equals(comparator, index.Comparer))) { throw new InvalidOperationException("Index for " + extractor + " already exists;" + " remove the index and add it with the new settings"); } }
/// <summary> /// Create RunnableCacheEvent instance with specified <b>CacheEvent</b> /// and <b>ICacheListener</b> objects. /// </summary> /// <param name="evt"> /// <b>CacheEvent</b> object. /// </param> /// <param name="listener"> /// <b>ICacheListener</b> object. /// </param> /// <returns> /// <b>RunnableCacheEvent</b> instance. /// </returns> public static RunnableCacheEvent Instantiate(CacheEventArgs evt, ICacheListener listener) { Debug.Assert(evt != null && listener != null); RunnableCacheEvent task = new RunnableCacheEvent(); task.CacheEvent = evt; task.CacheListener = listener; return(task); }
/// <summary> /// Set the array of listeners (sync or async) that corresponds to the /// specified listener. For example, if the specified listener is a /// SynchronousListener, set the synchronous listener array to the specified /// listener list. /// </summary> /// <param name="listener"> /// The <see cref="ICacheListener"/> to ser the array for /// </param> /// <param name="listenerArray"> /// The array of listeners /// </param> private void SetListenerListFor(ICacheListener listener, ICacheListener[] listenerArray) { if (listener is ISynchronousListener) { SynchronousListeners = listenerArray; } else { AsynchronousListeners = listenerArray; } }
/// <summary> /// Locate a listener is in the list of listeners. /// </summary> /// <param name="listenerArray"> /// The array of listeners to sarch /// </param> /// <param name="listener"> /// The <see cref="ICacheListener"/> to search for. /// </param> /// <returns> /// The index of the listener in the list of listeners. /// </returns> private int IndexOf(ICacheListener[] listenerArray, ICacheListener listener) { for (int i = 0, c = listenerArray.Length; i < c; ++i) { if (listener.Equals(listenerArray[i])) { return(i); } } return(-1); }
/// <summary> /// Remove a listener. /// </summary> /// <param name="listener"> /// The <see cref="ICacheListener"/> to remove. /// </param> public virtual void Remove(ICacheListener listener) { lock (this) { // Swing (Kestrel) will add/remove null listeners if (listener == null) { return; } ICacheListener[] oldArray = GetListenerListFor(listener); int count = oldArray.Length; // most common case - exactly one listener if (count == 1) { if (listener.Equals(oldArray[0])) { SetListenerListFor(listener, BLANKLIST); } return; } if (count > 0) { // locate the listener in the list int index = IndexOf(oldArray, listener); if (index >= 0) { // remove the listener from the list ICacheListener[] newArray = new ICacheListener[count - 1]; if (index > 0) { Array.Copy(oldArray, newArray, index); } if (index + 1 < count) { Array.Copy(oldArray, index + 1, newArray, index, count - index - 1); } SetListenerListFor(listener, newArray); } } } }
/// <summary> /// Dispatch this event to the specified MapListener. /// </summary> /// <param name="listener"> /// The <b>ICacheListener</b>. /// </param> /// <since>12.2.1</since> public void Dispatch(ICacheListener listener) { if (ShouldDispatch(listener)) { switch (EventType) { case CacheEventType.Inserted: listener.EntryInserted(this); break; case CacheEventType.Updated: listener.EntryUpdated(this); break; case CacheEventType.Deleted: listener.EntryDeleted(this); break; } } }
/// <summary> /// Add a listener. /// </summary> /// <param name="listener"> /// The <see cref="ICacheListener"/> to add. /// </param> public virtual void Add(ICacheListener listener) { lock (this) { // Swing (Kestrel) will add/remove null listeners if (listener == null) { return; } if (!Contains(listener)) { ICacheListener[] oldArray = GetListenerListFor(listener); int count = oldArray.Length; ICacheListener[] newArray = new ICacheListener[count + 1]; Array.Copy(oldArray, newArray, count); newArray[count] = listener; SetListenerListFor(listener, newArray); } } }
public void TestCustomEventTransformer() { INamedCache cache = CacheFactory.GetCache("dist-cache"); cache.Clear(); // add data var obj1 = new EventTransformerTestObject(); obj1.ID = 1; obj1.Name = "A"; cache.Add(1, obj1); // add two listeners ICacheListener listener1 = AddListener(cache); ICacheListener listener2 = AddListener(cache); Thread.Sleep(100); // add more data var obj2 = new EventTransformerTestObject(); var obj3 = new EventTransformerTestObject(); obj2.ID = 2; obj2.Name = "B"; obj3.ID = 3; obj3.Name = "C"; cache.Add(2, obj2); cache.Add(3, obj3); // remove an entry cache.Remove(1); Thread.Sleep(1000); Assert.AreEqual(4, cInsertCalled); Assert.AreEqual(2, cDeleteCalled); }
/// <summary> /// Remove a cache listener that previously signed up for events /// based on a filter evaluation. /// </summary> /// <param name="listener"> /// The <see cref="ICacheListener"/> to remove. /// </param> /// <param name="filter"> /// A filter used to evaluate events; <c>null</c> is equivalent to a /// filter that alway returns <b>true</b>. /// </param> public virtual void RemoveCacheListener(ICacheListener listener, IFilter filter) { NamedCache.RemoveCacheListener(listener, filter); }
/// <summary> /// Add a cache listener that receives events based on a filter /// evaluation. /// </summary> /// <remarks> /// <p> /// The listeners will receive <see cref="CacheEventArgs"/> objects, /// but if <paramref name="isLite"/> is passed as <b>true</b>, they /// <i>might</i> not contain the <b>OldValue</b> and <b>NewValue</b> /// properties.</p> /// <p> /// To unregister the <see cref="ICacheListener"/>, use the /// <see cref="RemoveCacheListener(ICacheListener, IFilter)"/> /// method.</p> /// </remarks> /// <param name="listener"> /// The <see cref="ICacheListener"/> to add.</param> /// <param name="filter"> /// A filter that will be passed <b>CacheEvent</b> objects to /// select from; a <b>CacheEvent</b> will be delivered to the /// listener only if the filter evaluates to <b>true</b> for that /// <b>CacheEvent</b>; <c>null</c> is equivalent to a filter /// that alway returns <b>true</b>. /// </param> /// <param name="isLite"> /// <b>true</b> to indicate that the <see cref="CacheEventArgs"/> /// objects do not have to include the <b>OldValue</b> and /// <b>NewValue</b> property values in order to allow optimizations. /// </param> public virtual void AddCacheListener(ICacheListener listener, IFilter filter, bool isLite) { NamedCache.AddCacheListener(listener, filter, isLite); }
/// <summary> /// Remove a cache listener that previously signed up for events /// about a specific key. /// </summary> /// <param name="listener"> /// The listener to remove. /// </param> /// <param name="key"> /// The key that identifies the entry for which to raise events. /// </param> public virtual void RemoveCacheListener(ICacheListener listener, object key) { NamedCache.RemoveCacheListener(listener, key); }
/// <summary> /// Add a cache listener for a specific key. /// </summary> /// <remarks> /// <p> /// The listeners will receive <see cref="CacheEventArgs"/> objects, /// but if <paramref name="isLite"/> is passed as <b>true</b>, they /// <i>might</i> not contain the /// <see cref="CacheEventArgs.OldValue"/> and /// <see cref="CacheEventArgs.NewValue"/> properties.</p> /// <p> /// To unregister the ICacheListener, use the /// <see cref="RemoveCacheListener(ICacheListener, object)"/> /// method.</p> /// </remarks> /// <param name="listener"> /// The <see cref="ICacheListener"/> to add. /// </param> /// <param name="key"> /// The key that identifies the entry for which to raise events. /// </param> /// <param name="isLite"> /// <b>true</b> to indicate that the <see cref="CacheEventArgs"/> /// objects do not have to include the <b>OldValue</b> and /// <b>NewValue</b> property values in order to allow optimizations. /// </param> public virtual void AddCacheListener(ICacheListener listener, object key, bool isLite) { NamedCache.AddCacheListener(listener, key, isLite); }
/// <summary> /// Remove a standard cache listener that previously signed up for /// all events. /// </summary> /// <remarks> /// This has the same result as the following call: /// <pre> /// RemoveCacheListener(listener, (IFilter) null); /// </pre> /// </remarks> /// <param name="listener"> /// The <see cref="ICacheListener"/> to remove. /// </param> public virtual void RemoveCacheListener(ICacheListener listener) { RemoveCacheListener(listener, null); }
/// <summary> /// Add a standard cache listener that will receive all events /// (inserts, updates, deletes) that occur against the cache, with /// the key, old-value and new-value included. /// </summary> /// <remarks> /// This has the same result as the following call: /// <pre> /// AddCacheListener(listener, (IFilter) null, false); /// </pre> /// </remarks> /// <param name="listener"> /// The <see cref="ICacheListener"/> to add. /// </param> public virtual void AddCacheListener(ICacheListener listener) { AddCacheListener(listener, null, false); }
public void Subscribe(ICacheListener listener) { _coherenceCache.AddCacheListener(listener); }
/// <summary> /// Remove a standard cache listener that previously signed up for /// all events. /// </summary> /// <remarks> /// This has the same result as the following call: /// <pre> /// RemoveCacheListener(listener, (IFilter) null); /// </pre> /// </remarks> /// <param name="listener"> /// The <see cref="ICacheListener"/> to remove. /// </param> public virtual void RemoveCacheListener(ICacheListener listener) { LocalCache.RemoveCacheListener(listener); }
/// <summary> /// Add a cache listener for a specific key. /// </summary> /// <remarks> /// <p> /// The listeners will receive <see cref="CacheEventArgs"/> objects, /// but if <paramref name="isLite"/> is passed as <b>true</b>, they /// <i>might</i> not contain the /// <see cref="CacheEventArgs.OldValue"/> and /// <see cref="CacheEventArgs.NewValue"/> properties.</p> /// <p> /// To unregister the ICacheListener, use the /// <see cref="RemoveCacheListener(ICacheListener, object)"/> /// method.</p> /// </remarks> /// <param name="listener"> /// The <see cref="ICacheListener"/> to add. /// </param> /// <param name="key"> /// The key that identifies the entry for which to raise events. /// </param> /// <param name="isLite"> /// <b>true</b> to indicate that the <see cref="CacheEventArgs"/> /// objects do not have to include the <b>OldValue</b> and /// <b>NewValue</b> property values in order to allow optimizations. /// </param> public void AddCacheListener(ICacheListener listener, object key, bool isLite) { }
/// <summary> /// Add a standard cache listener that will receive all events /// (inserts, updates, deletes) that occur against the cache, with /// the key, old-value and new-value included. /// </summary> /// <remarks> /// This has the same result as the following call: /// <pre> /// AddCacheListener(listener, (IFilter) null, false); /// </pre> /// </remarks> /// <param name="listener"> /// The <see cref="ICacheListener"/> to add. /// </param> public void AddCacheListener(ICacheListener listener) { }
/// <summary> /// Add a cache listener that receives events based on a filter /// evaluation. /// </summary> /// <remarks> /// <p> /// The listeners will receive <see cref="CacheEventArgs"/> objects, /// but if <paramref name="isLite"/> is passed as <b>true</b>, they /// <i>might</i> not contain the <b>OldValue</b> and <b>NewValue</b> /// properties.</p> /// <p> /// To unregister the <see cref="ICacheListener"/>, use the /// <see cref="RemoveCacheListener(ICacheListener, IFilter)"/> /// method.</p> /// </remarks> /// <param name="listener"> /// The <see cref="ICacheListener"/> to add.</param> /// <param name="filter"> /// A filter that will be passed <b>CacheEventArgs</b> objects to /// select from; a <b>CacheEventArgs</b> will be delivered to the /// listener only if the filter evaluates to <b>true</b> for that /// <b>CacheEventArgs</b>; <c>null</c> is equivalent to a filter /// that alway returns <b>true</b>. /// </param> /// <param name="isLite"> /// <b>true</b> to indicate that the <see cref="CacheEventArgs"/> /// objects do not have to include the <b>OldValue</b> and /// <b>NewValue</b> property values in order to allow optimizations. /// </param> public void AddCacheListener(ICacheListener listener, IFilter filter, bool isLite) { }
public static ICacheListener <TKey, TVal> CreateDurablePerfListener() { g_perflistener = new DurablePerfListener <TKey, TVal>(); return(g_perflistener); }
public static ICacheListener <TKey, TVal> CreateConflationTestCacheListenerDC() { g_listener = new ConflationTestCacheListenerDC <TKey, TVal>(); return(g_listener); }
/// <summary> /// Remove a cache listener that previously signed up for events /// based on a filter evaluation. /// </summary> /// <param name="listener"> /// The <see cref="ICacheListener"/> to remove. /// </param> /// <param name="filter"> /// A filter used to evaluate events; <c>null</c> is equivalent to a /// filter that alway returns <b>true</b>. /// </param> public void RemoveCacheListener(ICacheListener listener, IFilter filter) { }
/// <summary> /// Add a standard cache listener that will receive all events /// (inserts, updates, deletes) that occur against the cache, with /// the key, old-value and new-value included. /// </summary> /// <remarks> /// Expensive: Listening always occurs on the back cache. /// </remarks> /// <param name="listener"> /// The <see cref="ICacheListener"/> to add. /// </param> public virtual void AddCacheListener(ICacheListener listener) { BackCache.AddCacheListener(listener); }
/// <summary> /// Remove a standard cache listener that previously signed up for /// all events. /// </summary> /// <remarks> /// This has the same result as the following call: /// <pre> /// RemoveCacheListener(listener, (IFilter) null); /// </pre> /// </remarks> /// <param name="listener"> /// The <see cref="ICacheListener"/> to remove. /// </param> public void RemoveCacheListener(ICacheListener listener) { }
/// <summary> /// Remove a standard cache listener that previously signed up for /// all events. /// </summary> /// <param name="listener"> /// The <see cref="ICacheListener"/> to remove. /// </param> public virtual void RemoveCacheListener(ICacheListener listener) { BackCache.RemoveCacheListener(listener); }
/// <summary> /// Remove a cache listener that previously signed up for events /// about a specific key. /// </summary> /// <param name="listener"> /// The listener to remove. /// </param> /// <param name="key"> /// The key that identifies the entry for which to raise events. /// </param> public void RemoveCacheListener(ICacheListener listener, object key) { }
/// <summary> /// The ICacheListener that will receive all events, including those that /// result from the initial population of the view. /// </summary> /// <param name="listener"> /// the ICacheListener that will receive all the events from /// the view, including those corresponding to its initial /// population. /// </param> /// <returns>This ViewBuilder.</returns> public ViewBuilder Listener(ICacheListener listener) { m_listener = listener; return(this); }