Basic holder class for registering a keys based interest in cached data.
Inheritance: AllKeysInterest, IInitializingObject
Exemplo n.º 1
0
        public void Dispose()
        {
            try
            {
                if (region != null && !CollectionUtils.IsEmpty(interests))
                {
                    foreach (AllKeysInterest interest in interests)
                    {
                        if (interest is RegexInterest)
                        {
                            RegexInterest regexInterest = (RegexInterest)interest;
                            region.UnregisterRegex(regexInterest.Regex);
                        }
                        else if (interest is KeyInterest)
                        {
                            KeyInterest keyInterest = (KeyInterest)interest;
                            region.UnregisterKeys(keyInterest.Keys);
                        }
                        else
                        {
                            region.UnregisterAllKeys();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                log.Warn("Cannot unregister cache interests", ex);
            }

            if (region != null && destroy)
            {
                region.DestroyRegion();
            }
            region = null;
        }
Exemplo n.º 2
0
 protected virtual void RegisterInterests()
 {
     if (interests == null)
     {
         return;
     }
     foreach (AllKeysInterest interest in interests)
     {
         if (interest is RegexInterest)
         {
             try
             {
                 RegexInterest regexInterest = (RegexInterest)interest;
                 if (interest.Policy == InterestResultPolicy.None)
                 {
                     region.RegisterRegex(regexInterest.Regex, interest.Durable);
                 }
                 else if (interest.Policy == InterestResultPolicy.Keys)
                 {
                     region.RegisterRegex(regexInterest.Regex, interest.Durable, null, false);
                 }
                 else if (interest.Policy == InterestResultPolicy.KeysAndValues)
                 {
                     //TODO How to make the list of keys be made accessible to client code..?
                     //     Have the List<ICacheableKey> come from the container.
                     region.RegisterRegex(regexInterest.Regex, interest.Durable, new List <ICacheableKey>());
                 }
             }
             catch (Exception e)
             {
                 log.Error("Couldn't register regex interest [" + interest + "]", e);
                 throw;
             }
         }
         else if (interest is KeyInterest)
         {
             try
             {
                 KeyInterest keyInterest = (KeyInterest)interest;
                 if (keyInterest.Policy == InterestResultPolicy.None)
                 {
                     region.RegisterKeys(keyInterest.Keys);
                 }
                 else if (interest.Policy == InterestResultPolicy.Keys)
                 {
                     region.RegisterKeys(keyInterest.Keys, keyInterest.Durable, false);
                 }
                 else if (interest.Policy == InterestResultPolicy.KeysAndValues)
                 {
                     region.RegisterKeys(keyInterest.Keys, keyInterest.Durable, true);
                 }
             }
             catch (Exception e)
             {
                 log.Error("Couldn't register key interest [" + interest + "]", e);
                 throw;
             }
         }
         else // AllKeysInterest
         {
             try
             {
                 if (interest.Policy == InterestResultPolicy.None)
                 {
                     region.RegisterAllKeys(interest.Durable);
                 }
                 else if (interest.Policy == InterestResultPolicy.Keys)
                 {
                     //TODO have the List<ICacheableKey> come from the container
                     region.RegisterAllKeys(interest.Durable, new List <ICacheableKey>(), false);
                 }
                 else if (interest.Policy == InterestResultPolicy.KeysAndValues)
                 {
                     region.RegisterAllKeys(interest.Durable, new List <ICacheableKey>(), true);
                 }
             }
             catch (Exception e)
             {
                 log.Error("Couldn't register all keys interest [" + interest + "]", e);
                 throw;
             }
         }
     }
 }