Esempio n. 1
0
 public CachedGrainLocator(
     GrainDirectoryResolver grainDirectoryResolver,
     IClusterMembershipService clusterMembershipService)
 {
     this.grainDirectoryResolver   = grainDirectoryResolver;
     this.clusterMembershipService = clusterMembershipService;
     this.cache = new LRUBasedGrainDirectoryCache(GrainDirectoryOptions.DEFAULT_CACHE_SIZE, GrainDirectoryOptions.DEFAULT_MAXIMUM_CACHE_TTL);
 }
        private long lastNumHits;           // for stats

        internal AdaptiveDirectoryCacheMaintainer(ILocalGrainDirectory router, IGrainDirectoryCache <TValue> cache)
        {
            this.router = (LocalGrainDirectory)router;
            this.cache  = (AdaptiveGrainDirectoryCache <TValue>)cache;

            lastNumAccesses = 0;
            lastNumHits     = 0;
            OnFault         = FaultBehavior.RestartOnFault;
        }
Esempio n. 3
0
 public GrainLocator(
     IGrainDirectory grainDirectory,
     DhtGrainLocator inClusterGrainLocator,
     IClusterMembershipService clusterMembershipService)
 {
     this.grainDirectory           = grainDirectory;
     this.inClusterGrainLocator    = inClusterGrainLocator;
     this.clusterMembershipService = clusterMembershipService;
     this.cache = new LRUBasedGrainDirectoryCache(GrainDirectoryOptions.DEFAULT_CACHE_SIZE, GrainDirectoryOptions.DEFAULT_MAXIMUM_CACHE_TTL);
 }
        internal static AsynchAgent CreateGrainDirectoryCacheMaintainer(
            LocalGrainDirectory router,
            IGrainDirectoryCache <TValue> cache,
            Func <List <ActivationAddress>, TValue> updateFunc)
        {
            var adaptiveCache = cache as AdaptiveGrainDirectoryCache <TValue>;

            return(adaptiveCache != null
                ? new AdaptiveDirectoryCacheMaintainer <TValue>(router, adaptiveCache, updateFunc)
                : null);
        }
Esempio n. 5
0
        internal static AdaptiveDirectoryCacheMaintainer CreateGrainDirectoryCacheMaintainer(
            LocalGrainDirectory router,
            IGrainDirectoryCache cache,
            IInternalGrainFactory grainFactory,
            ILoggerFactory loggerFactory)
        {
            var adaptiveCache = cache as AdaptiveGrainDirectoryCache;

            return(adaptiveCache != null
                ? new AdaptiveDirectoryCacheMaintainer(router, adaptiveCache, grainFactory, loggerFactory)
                : null);
        }
        internal static DedicatedAsynchAgent CreateGrainDirectoryCacheMaintainer(
            LocalGrainDirectory router,
            IGrainDirectoryCache cache,
            IInternalGrainFactory grainFactory,
            ExecutorService executorService,
            ILoggerFactory loggerFactory)
        {
            var adaptiveCache = cache as AdaptiveGrainDirectoryCache;

            return(adaptiveCache != null
                ? new AdaptiveDirectoryCacheMaintainer(router, adaptiveCache, grainFactory, executorService, loggerFactory)
                : null);
        }
Esempio n. 7
0
        internal static DedicatedAsynchAgent CreateGrainDirectoryCacheMaintainer(
            LocalGrainDirectory router,
            IGrainDirectoryCache <TValue> cache,
            Func <List <ActivationAddress>, TValue> updateFunc,
            IInternalGrainFactory grainFactory,
            ExecutorService executorService,
            ILoggerFactory loggerFactory)
        {
            var adaptiveCache = cache as AdaptiveGrainDirectoryCache <TValue>;

            return(adaptiveCache != null
                ? new AdaptiveDirectoryCacheMaintainer <TValue>(router, adaptiveCache, updateFunc, grainFactory, executorService, loggerFactory)
                : null);
        }
Esempio n. 8
0
        private static void RemoveActivations(IGrainDirectoryCache <IReadOnlyList <Tuple <SiloAddress, ActivationId> > > directoryCache, GrainId key, IReadOnlyList <Tuple <SiloAddress, ActivationId> > activations, int version, Func <Tuple <SiloAddress, ActivationId>, bool> doRemove)
        {
            int removeCount = activations.Count(doRemove);

            if (removeCount == 0)
            {
                return; // nothing to remove, done here
            }

            if (activations.Count > removeCount) // still some left, update activation list.  Note: Most of the time there should be only one activation
            {
                var newList = new List <Tuple <SiloAddress, ActivationId> >(activations.Count - removeCount);
                newList.AddRange(activations.Where(t => !doRemove(t)));
                directoryCache.AddOrUpdate(key, newList, version);
            }
            else // no activations left, remove from cache
            {
                directoryCache.Remove(key);
            }
        }
Esempio n. 9
0
        internal static DedicatedAsynchAgent CreateGrainDirectoryCacheMaintainer(
            ILocalSiloDetails localSiloDetails,
            LocalGrainDirectory localGrainDirectory,
            IGrainDirectoryCache <TValue> cache,
            Func <List <ActivationAddress>, TValue> updateFunc,
            IInternalGrainFactory grainFactory,
            ExecutorService executorService,
            ILoggerFactory loggerFactory)
        {
            var adaptiveCache = cache as AdaptiveGrainDirectoryCache <TValue>;

            if (adaptiveCache is null)
            {
                return(null);
            }
            return(new AdaptiveDirectoryCacheMaintainer <TValue>(
                       localSiloDetails,
                       localGrainDirectory,
                       adaptiveCache,
                       updateFunc,
                       grainFactory,
                       executorService,
                       loggerFactory));
        }
Esempio n. 10
0
        /// <summary>
        /// Looks up the cached value by the given key.
        /// </summary>
        /// <param name="cache">grain directory cache to look up results from</param>
        /// <param name="key">key for the lookup</param>
        /// <param name="result">value if the key is found, undefined otherwise</param>
        /// <returns>true iff the the given key is in the cache</returns>
        public static bool LookUp <TValue>(this IGrainDirectoryCache <TValue> cache, GrainId key, out TValue result)
        {
            int version;

            return(cache.LookUp(key, out result, out version));
        }
Esempio n. 11
0
 /// <summary>
 /// Looks up the cached value by the given key.
 /// </summary>
 /// <param name="cache">grain directory cache to look up results from</param>
 /// <param name="key">key for the lookup</param>
 /// <param name="result">value if the key is found, undefined otherwise</param>
 /// <returns>true if the given key is in the cache</returns>
 public static bool LookUp(this IGrainDirectoryCache cache, GrainId key, out GrainAddress result)
 {
     return(cache.LookUp(key, out result, out _));
 }
Esempio n. 12
0
 internal static AsynchAgent CreateGrainDirectoryCacheMaintainer(LocalGrainDirectory router, IGrainDirectoryCache <TValue> cache)
 {
     return(cache is AdaptiveGrainDirectoryCache <TValue>?
            new AdaptiveDirectoryCacheMaintainer <TValue>(router, cache) : null);
 }
Esempio n. 13
0
        /// <summary>
        /// Looks up the cached value by the given key.
        /// </summary>
        /// <param name="cache">grain directory cache to look up results from</param>
        /// <param name="key">key for the lookup</param>
        /// <param name="result">value if the key is found, undefined otherwise</param>
        /// <returns>true if the given key is in the cache</returns>
        public static bool LookUp(this IGrainDirectoryCache cache, GrainId key, out IReadOnlyList <Tuple <SiloAddress, ActivationId> > result)
        {
            int version;

            return(cache.LookUp(key, out result, out version));
        }
Esempio n. 14
0
        private static void RemoveActivations(IGrainDirectoryCache<IReadOnlyList<Tuple<SiloAddress, ActivationId>>> directoryCache, GrainId key, IReadOnlyList<Tuple<SiloAddress, ActivationId>> activations, int version, Func<Tuple<SiloAddress, ActivationId>, bool> doRemove)
        {
            int removeCount = activations.Count(doRemove);
            if (removeCount == 0)
            {
                return; // nothing to remove, done here
            }

            if (activations.Count > removeCount) // still some left, update activation list.  Note: Most of the time there should be only one activation
            {
                var newList = new List<Tuple<SiloAddress, ActivationId>>(activations.Count - removeCount);
                newList.AddRange(activations.Where(t => !doRemove(t)));
                directoryCache.AddOrUpdate(key, newList, version);
            }
            else // no activations left, remove from cache
            {
                directoryCache.Remove(key);
            }
        }
Esempio n. 15
0
 public GrainLocator(IGrainDirectory grainDirectory, InClusterGrainLocator inClusterGrainLocator)
 {
     this.grainDirectory        = grainDirectory;
     this.inClusterGrainLocator = inClusterGrainLocator;
     this.cache = new LRUBasedGrainDirectoryCache(GrainDirectoryOptions.DEFAULT_CACHE_SIZE, GrainDirectoryOptions.DEFAULT_MAXIMUM_CACHE_TTL);
 }