/// <summary> /// Handles a cache event for the <see cref="TcmCDService.CacheClient.RMI.CacheConnector" /> /// </summary> /// <param name="region">Cache region</param> /// <param name="key">Cache key</param> /// <param name="eventType">Cache event type</param> void com.tridion.tcmcdservice.rmi.CacheChannelEventListener.onCacheEvent(String region, String key, int eventType) { CacheRegion cacheRegion = CacheRegionExtensions.ToCacheRegion(region); CacheEventType cacheEventType = (CacheEventType)eventType; base.OnCacheEvent(cacheRegion, key, cacheEventType); }
/// <summary> /// Trigger a CacheEvent for the <see cref="P:region" />, <see cref="P:key" /> and <see cref="P:eventType" /> /// </summary> /// <param name="region"><see cref="T:TcmCDService.CacheClient.CacheRegion" /></param> /// <param name="key">Cache item key</param> /// <param name="eventType"><see cref="T:TcmCDService.CacheClient.CacheEventType" /></param> protected void OnCacheEvent(CacheRegion region, String key, CacheEventType eventType) { if (CacheEvent != null) { CacheEvent(null, new CacheEventArgs(region, key, eventType)); } }
/// <summary> /// Processes a cache event and trigger the dependent dependencies /// </summary> /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheClient.CacheRegion" /></param> /// <param name="cacheEventType"><see cref="T:TcmCDService.CacheClient.CacheEventType" /></param> /// <param name="key">Cache item key</param> public static void ProcessCacheEvent(CacheRegion cacheRegion, CacheEventType cacheEventType, String key) { Logger.Debug("Processing cache event: region \"{0}\", key \"{1}\", type \"{2}\".", cacheRegion, key, cacheEventType); foreach (TridionDependency dependency in mDependencies) { if (dependency.CacheRegion.HasFlag(cacheRegion)) { Logger.Debug("\tDependency: {0}", dependency); Logger.Debug("\tComparison: {0} vs {1}", dependency.Key, key); switch (cacheEventType) { // Instruction to flush all entries from a CacheRegion case CacheEventType.Flush: dependency.TriggerDependency(); break; // Instruction to invalidate a specific entry from a CacheRegion case CacheEventType.Invalidate: if (key.StartsWith(dependency.Key, StringComparison.OrdinalIgnoreCase)) { dependency.TriggerDependency(); } break; } } } }
/// <summary> /// Initializes a new instance of the <see cref="CacheEvent" /> class. /// </summary> /// <param name="regionPath">Cache region path.</param> /// <param name="key">Cache key as <see cref="T:System.Int32" /></param> /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType" /></param> public CacheEvent(string regionPath, int key, CacheEventType eventType) : base(JNIHandle.NULL) { jvalue[] args = new jvalue[3]; using (JavaMethodArguments arguments = new JavaMethodArguments(args).Add(regionPath).Add(new Java.Lang.Integer(key)).Add((int)eventType)) { base.JObject = (long)mConstructor.CallObject(this, arguments); } }
/// <summary> /// Constructs a new FilterEventArgs. /// </summary> /// <param name="cache"> /// The <see cref="IObservableCache"/> object that fired the /// event. /// </param> /// <param name="type"> /// This event's type. /// </param> /// <param name="key"> /// The key into the cache. /// </param> /// <param name="valueOld"> /// The old value. /// </param> /// <param name="valueNew"> /// The new value. /// </param> /// <param name="isSynthetic"> /// <b>true</b> if the event is caused by the cache internal /// processing such as eviction or loading. /// </param> /// <param name="filters"> /// An array of filters caused this event. /// </param> public FilterEventArgs(IObservableCache cache, CacheEventType type, object key, object valueOld, object valueNew, bool isSynthetic, IFilter[] filters) : base(cache, type, key, valueOld, valueNew, isSynthetic, TransformationState.TRANSFORMABLE, false) { Debug.Assert(filters != null); m_filters = filters; }
/// <summary> /// Constructs a new FilterEventArgs. /// </summary> /// <param name="cache"> /// The IObservableCache object that fired the event /// </param> /// <param name="type"> /// This event's type. /// </param> /// <param name="key"> /// The key into the cache. /// </param> /// <param name="valueOld"> /// The old value. /// </param> /// <param name="valueNew"> /// The new value. /// </param> /// <param name="isSynthetic"> /// <b>true</b> if the event is caused by the cache internal /// processing such as eviction or loading. /// </param> /// <param name="transformState"> /// The TransformationState state describing /// how this event has been or should be transformed. /// </param> /// <param name="filters"> /// An array of filters that caused this event. /// </param> /// <param name="isPriming"> /// <b>true</b> if the event is a priming event. /// </param> /// <since>Coherence 12.2.1.3.2</since> public FilterEventArgs(IObservableCache cache, CacheEventType type, object key, object valueOld, object valueNew, bool isSynthetic, TransformationState transformState, bool isPriming, IFilter[] filters) : base(cache, type, key, valueOld, valueNew, isSynthetic, transformState, isPriming) { Debug.Assert(filters != null); m_filters = filters; m_event = null; }
/// <summary> /// Processes the cache event. /// </summary> /// <param name="cacheEventType">Type of the cache event.</param> /// <param name="subscriptionConfiguration">The subscription group.</param> /// <returns></returns> private async Task ProcessCacheEvent(CacheEventType cacheEventType, SubscriptionConfiguration subscriptionConfiguration) { if (cacheEventType == CacheEventType.Added) { // Create a new subscription ISubscription subscription = this.SubscriptionResolver(); // Start this subscription await subscription.StartSubscription(subscriptionConfiguration.SubscriptionId, subscriptionConfiguration.StreamName, subscriptionConfiguration.GroupName); // Add this to the cached subscription list this.SubscriptionList.Add(subscription); } else if (cacheEventType == CacheEventType.Removed) { // Find the item that has been removed based on the event argument ISubscription subscription = this.SubscriptionList.Single(x => x.SubscriptionId == subscriptionConfiguration.SubscriptionId); // Stop the subscription await subscription.StopSubscription(); // Now remove the item this.SubscriptionList.Remove(subscription); } else if (cacheEventType == CacheEventType.Updated) { // Find the item that has been updated based on the event argument ISubscription subscription = this.SubscriptionList.SingleOrDefault(x => x.SubscriptionId == subscriptionConfiguration.SubscriptionId); if (subscription != null) { // Stop the current subscription await subscription.StopSubscription(); // Re-Create the subscription // Start this subscription await subscription.StartSubscription(subscriptionConfiguration.SubscriptionId, subscriptionConfiguration.StreamName, subscriptionConfiguration.GroupName, subscriptionConfiguration.StreamPositionToRestartFrom); // Update the repository position INewConfigurationRepository configRepository = this.RepositoryResolver(); await configRepository.ResetSubscriptionStreamPosition(subscriptionConfiguration.SubscriptionId, CancellationToken.None); } } }
/// <summary> /// Constructs a new CacheEventArgs. /// </summary> /// <param name="source"> /// The <see cref="IObservableCache"/> object that fired the /// event. /// </param> /// <param name="eventType"> /// This event's type, one of <see cref="CacheEventType"/> /// values. /// </param> /// <param name="key"> /// The key into the cache. /// </param> /// <param name="valueOld"> /// The old value (for update and delete events). /// </param> /// <param name="valueNew"> /// The new value (for insert and update events). /// </param> /// <param name="isSynthetic"> /// <b>true</b> if the event is caused by the cache internal /// processing such as eviction or loading. /// </param> /// <param name="transformState"> /// <b>true</b> if the event is a priming event. /// has been or should be transformed. /// </param> /// <param name="isPriming"> /// <b>true</b> if the event is a priming event. /// </param> public CacheEventArgs(IObservableCache source, CacheEventType eventType, object key, object valueOld, object valueNew, bool isSynthetic, TransformationState transformState, bool isPriming) { m_source = source; m_eventType = eventType; m_key = key; m_valueOld = valueOld; m_valueNew = valueNew; m_isSynthetic = isSynthetic; m_transformState = transformState; m_isPriming = isPriming; }
/// <summary> /// Generates an object from its XML representation. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader" /> stream from which the object is deserialized.</param> public void ReadXml(XmlReader reader) { if (reader.MoveToAttribute("regionPath")) { mRegionPath = reader.Value; } if (reader.MoveToAttribute("key")) { mKey = reader.Value; } if (reader.MoveToAttribute("type")) { mEventType = (CacheEventType)int.Parse(reader.Value); } }
/// <summary> /// Constructs a new lite (no values are speicifed) FilterEventArgs. /// </summary> /// <param name="map"> /// The <see cref="IObservableCache"/> object that fired the /// event. /// </param> /// <param name="id"> /// This event's id. /// </param> /// <param name="key"> /// The key into the cache. /// </param> /// <param name="isSynthetic"> /// <b>true</b> if the event is caused by the cache internal /// processing such as eviction or loading. /// </param> /// <param name="filters"> /// An array of filters that caused this event. /// </param> public FilterEventArgs(IObservableCache map, CacheEventType id, object key, bool isSynthetic, IFilter[] filters) : this(map, id, key, null, null, isSynthetic, TransformationState.TRANSFORMABLE, false, filters) { }
/// <summary> /// Broadcasts a cache event to all other connected clients /// </summary> /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param> /// <param name="key">Cache key as <see cref="T:System.Int32" /></param> /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType" /></param> public override void BroadcastEvent(CacheRegion cacheRegion, int key, CacheEventType eventType) { mConnector.BroadcastEvent(new CacheEvent(CacheRegionExtensions.FromCacheRegion(cacheRegion), key, eventType)); }
/// <summary> /// Broadcasts a cache event to all other connected clients /// </summary> /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param> /// <param name="key">Cache key as <see cref="T:System.Int32" /></param> /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType" /></param> public override void BroadcastEvent(CacheRegion cacheRegion, int key, CacheEventType eventType) { XmlCacheEvent cacheEvent = new XmlCacheEvent(cacheRegion, key, eventType); BroadcastEvent(cacheEvent); }
public CacheEntryChangedEventArgs(CacheEventType eventType, object key) { EventType = eventType; Key = key; }
/// <summary> /// Initializes a new instance of the <see cref="XmlCacheEvent" /> class. /// </summary> /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param> /// <param name="key">Cache Key as <see cref="T:System.Int32" /></param> /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType"/></param> public XmlCacheEvent(CacheRegion cacheRegion, int key, CacheEventType eventType) { mRegionPath = CacheRegionExtensions.FromCacheRegion(cacheRegion); mKey = key.ToString(); mEventType = eventType; }
/// <summary> /// Initializes a new instance of the <see cref="CacheEventArgs" /> class. /// </summary> /// <param name="region"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param> /// <param name="key">Cache item Key.</param> /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType" /></param> public CacheEventArgs(CacheRegion region, String key, CacheEventType eventType) { mRegion = region; mKey = key; mEventType = eventType; }
/// <summary> /// Constructs a new CacheEventArgs. /// </summary> /// <param name="source"> /// The <see cref="IObservableCache"/> object that fired the /// event. /// </param> /// <param name="eventType"> /// This event's type, one of <see cref="CacheEventType"/> /// values. /// </param> /// <param name="key"> /// The key into the cache. /// </param> /// <param name="valueOld"> /// The old value (for update and delete events). /// </param> /// <param name="valueNew"> /// The new value (for insert and update events). /// </param> /// <param name="isSynthetic"> /// <b>true</b> if the event is caused by the cache internal /// processing such as eviction or loading. /// </param> /// <param name="isPriming"> /// <b>true</b> if the event is a priming event. /// </param> public CacheEventArgs(IObservableCache source, CacheEventType eventType, object key, object valueOld, object valueNew, bool isSynthetic, bool isPriming) : this(source, eventType, key, valueOld, valueNew, isSynthetic, TransformationState.TRANSFORMABLE, isPriming) { }
/// <summary> /// Convert an event type into a human-readable string. /// </summary> /// <param name="eventType"> /// An event type, one of the <see cref="CacheEventType"/> /// enumerated values. /// </param> /// <returns> /// A corresponding human-readable string, for example "inserted". /// </returns> public static string GetDescription(CacheEventType eventType) { return(eventType.ToString()); }
/// <summary> /// Trigger a CacheEvent for the <see cref="P:region" />, <see cref="P:key" /> and <see cref="P:eventType" /> /// </summary> /// <param name="region"><see cref="T:TcmCDService.CacheClient.CacheRegion" /></param> /// <param name="key">Cache item key</param> /// <param name="eventType"><see cref="T:TcmCDService.CacheClient.CacheEventType" /></param> protected void OnCacheEvent(CacheRegion region, String key, CacheEventType eventType) { if (CacheEvent != null) CacheEvent(null, new CacheEventArgs(region, key, eventType)); }
/// <summary> /// Broadcasts a cache event to all other connected clients /// </summary> /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param> /// <param name="key">Cache key as <see cref="T:System.Int32" /></param> /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType" /></param> public virtual void BroadcastEvent(CacheRegion cacheRegion, int key, CacheEventType eventType) { }
/// <summary> /// Generates an object from its XML representation. /// </summary> /// <param name="reader">The <see cref="T:System.Xml.XmlReader" /> stream from which the object is deserialized.</param> public void ReadXml(XmlReader reader) { if (reader.MoveToAttribute("regionPath")) mRegionPath = reader.Value; if (reader.MoveToAttribute("key")) mKey = reader.Value; if (reader.MoveToAttribute("type")) mEventType = (CacheEventType)int.Parse(reader.Value); }
/// <summary> /// Broadcasts a cache event to all other connected clients /// </summary> /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param> /// <param name="key">Cache key as <see cref="T:System.Int32" /></param> /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType" /></param> public override void BroadcastEvent(CacheRegion cacheRegion, int key, CacheEventType eventType) { mConnector.broadcastEvent(new com.tridion.cache.CacheEvent(CacheRegionExtensions.FromCacheRegion(cacheRegion), new java.lang.Integer(key), (int)eventType)); }
public CacheEventMessage(string key, string memberName, CacheEventType cacheEventType) { Key = key; MemberName = memberName; CacheEventType = cacheEventType; }
/// <summary> /// Broadcasts a cache event to all other connected clients /// </summary> /// <param name="cacheRegion"><see cref="T:TcmCDService.CacheTypes.CacheRegion" /></param> /// <param name="key">Cache key as <see cref="T:System.String" /></param> /// <param name="eventType"><see cref="T:TcmCDService.CacheTypes.CacheEventType" /></param> public override void BroadcastEvent(CacheRegion cacheRegion, String key, CacheEventType eventType) { mConnector.broadcastEvent(new com.tridion.cache.CacheEvent(CacheRegionExtensions.FromCacheRegion(cacheRegion), key, (int)eventType)); }
/// <summary> /// Apply the test to the object. /// </summary> /// <param name="o"> /// An object to which the test is applied. /// </param> /// <returns> /// <b>true</b> if the test passes, <b>false</b> otherwise. /// </returns> public virtual bool Evaluate(object o) { var evt = (CacheEventArgs)o; // check if the event is of a type that the client is // interested in evaluating CacheEventType type = evt.EventType; CacheEventMask mask = EventMask; try { if ((MASK[(int)type] & mask) == 0) { return(false); } } catch (IndexOutOfRangeException) { return(false); } // check for a client-specified event filter IFilter filter = Filter; if (filter == null) { return(true); } CacheEventSyntheticMask maskSynth = m_maskSynth; bool fSynthetic = evt.IsSynthetic; if (((maskSynth & CacheEventSyntheticMask.Synthetic) == 0 && fSynthetic) || ((maskSynth & CacheEventSyntheticMask.Natural) == 0 && !fSynthetic)) { return(false); } // evaluate the filter switch (type) { case CacheEventType.Inserted: return(filter.Evaluate(evt.NewValue)); case CacheEventType.Updated: // note that the old value evaluation is deferred, because // the event itself may be deferring loading the old value, // e.g. if the event is coming from a disk-backed cache bool isNew = filter.Evaluate(evt.NewValue); switch (mask & (CacheEventMask.UpdatedEntered | CacheEventMask.UpdatedLeft | CacheEventMask.Updated | CacheEventMask.UpdatedWithin)) { case CacheEventMask.UpdatedEntered: return(isNew && !filter.Evaluate(evt.OldValue)); case CacheEventMask.UpdatedLeft: return(!isNew && filter.Evaluate(evt.OldValue)); case CacheEventMask.UpdatedEntered | CacheEventMask.UpdatedLeft: return(isNew != filter.Evaluate(evt.OldValue)); case CacheEventMask.UpdatedWithin: return(isNew && filter.Evaluate(evt.OldValue)); case CacheEventMask.UpdatedWithin | CacheEventMask.UpdatedEntered: return(isNew); case CacheEventMask.UpdatedWithin | CacheEventMask.UpdatedLeft: return(filter.Evaluate(evt.OldValue)); default: // all other combinations evaulate to the same as // CacheEventMask.Updated return(isNew || filter.Evaluate(evt.OldValue)); } case CacheEventType.Deleted: return(filter.Evaluate(evt.OldValue)); default: return(false); } }