Ejemplo n.º 1
0
        /// <summary> Delete / Clear state data function for this storage provider. </summary>
        /// <see cref="IStorageProvider.ClearStateAsync"/>
        public virtual async Task ClearStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
        {
            var keys = MakeKeys(grainType, grainReference);

            if (Log.IsVerbose2)
            {
                Log.Verbose2("Delete Keys={0} Etag={1}", StorageProviderUtils.PrintKeys(keys), grainState.ETag);
            }
            string key = HierarchicalKeyStore.MakeStoreKey(keys);
            IMemoryStorageGrain storageGrain = GetStorageGrain(key);
            await storageGrain.DeleteStateAsync(STATE_STORE_NAME, key, grainState.ETag);
        }
Ejemplo n.º 2
0
        /// <summary> Write state data function for this storage provider. </summary>
        /// <see cref="IStorageProvider.WriteStateAsync"/>
        public virtual async Task WriteStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
        {
            var    keys = MakeKeys(grainType, grainReference);
            string key  = HierarchicalKeyStore.MakeStoreKey(keys);

            if (Log.IsVerbose2)
            {
                Log.Verbose2("Write {0} ", StorageProviderUtils.PrintOneWrite(keys, grainState.State, grainState.ETag));
            }
            IMemoryStorageGrain storageGrain = GetStorageGrain(key);

            grainState.ETag = await storageGrain.WriteStateAsync(STATE_STORE_NAME, key, grainState);
        }
Ejemplo n.º 3
0
        /// <summary> Read state data function for this storage provider. </summary>
        /// <see cref="IStorageProvider#ReadStateAsync"/>
        public virtual async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
        {
            var keys = MakeKeys(grainType, grainReference);

            if (Log.IsVerbose2)
            {
                Log.Verbose2("Read Keys={0}", StorageProviderUtils.PrintKeys(keys));
            }

            string id = HierarchicalKeyStore.MakeStoreKey(keys);
            IMemoryStorageGrain          storageGrain = GetStorageGrain(id);
            IDictionary <string, object> state        = await storageGrain.ReadStateAsync(STATE_STORE_NAME, id);

            grainState.SetAll(state);
        }
Ejemplo n.º 4
0
        /// <summary> Write state data function for this storage provider. </summary>
        /// <see cref="IStorageProvider#WriteStateAsync"/>
        public virtual async Task WriteStateAsync(string grainType, GrainReference grainReference, GrainState grainState)
        {
            var    keys     = MakeKeys(grainType, grainReference);
            var    data     = grainState.AsDictionary();
            string prevEtag = grainState.Etag;

            if (Log.IsVerbose2)
            {
                Log.Verbose2("Write {0} ", StorageProviderUtils.PrintOneWrite(keys, data, prevEtag));
            }

            string key = HierarchicalKeyStore.MakeStoreKey(keys);
            IMemoryStorageGrain storageGrain = GetStorageGrain(key);
            string newEtag = await storageGrain.WriteStateAsync(STATE_STORE_NAME, key, data, prevEtag);

            grainState.Etag = newEtag;
        }
Ejemplo n.º 5
0
        /// <summary> Read state data function for this storage provider. </summary>
        /// <see cref="IGrainStorage.ReadStateAsync"/>
        public virtual async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
        {
            var keys = MakeKeys(grainType, grainReference);

            if (logger.IsEnabled(LogLevel.Trace))
            {
                logger.LogTrace("Read Keys={Keys}", StorageProviderUtils.PrintKeys(keys));
            }

            string id = HierarchicalKeyStore.MakeStoreKey(keys);
            IMemoryStorageGrain storageGrain = GetStorageGrain(id);
            var state = await storageGrain.ReadStateAsync(STATE_STORE_NAME, id);

            if (state != null)
            {
                grainState.ETag  = state.ETag;
                grainState.State = state.State;
            }
        }
Ejemplo n.º 6
0
        /// <summary> Read state data function for this storage provider. </summary>
        /// <see cref="IStorageProvider.ReadStateAsync"/>
        public virtual async Task ReadStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
        {
            IList <Tuple <string, string> > keys = MakeKeys(grainType, grainReference).ToList();

            if (Log.IsVerbose2)
            {
                Log.Verbose2("Read Keys={0}", StorageProviderUtils.PrintKeys(keys));
            }

            string id = HierarchicalKeyStore.MakeStoreKey(keys);
            IMemoryStorageGrain storageGrain = GetStorageGrain(id);
            var state = await storageGrain.ReadStateAsync(STATE_STORE_NAME, id);

            if (state != null && state.State != null)
            {
                grainState.ETag  = state.ETag;
                grainState.State = state.State;
            }
        }
Ejemplo n.º 7
0
        /// <summary> Read state data function for this storage provider. </summary>
        /// <see cref="IStorageProvider#ReadStateAsync"/>
        public virtual async Task ReadStateAsync(string grainType, GrainReference grainReference, GrainState grainState)
        {
            var keys = MakeKeys(grainType, grainReference);

            if (Log.IsVerbose2)
            {
                Log.Verbose2("Read Keys={0}", StorageProviderUtils.PrintKeys(keys));
            }

            string id = HierarchicalKeyStore.MakeStoreKey(keys);
            IMemoryStorageGrain storageGrain = GetStorageGrain(id);
            Tuple <IDictionary <string, object>, string> result = await storageGrain.ReadStateAsync(STATE_STORE_NAME, id);

            if (result != null && result.Item1 != null)
            {
                grainState.SetAll(result.Item1);
                grainState.Etag = result.Item2;
            }
        }
Ejemplo n.º 8
0
        /// <summary> Write state data function for this storage provider. </summary>
        /// <see cref="IGrainStorage.WriteStateAsync"/>
        public virtual async Task WriteStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
        {
            var    keys = MakeKeys(grainType, grainReference);
            string key  = HierarchicalKeyStore.MakeStoreKey(keys);

            if (logger.IsEnabled(LogLevel.Trace))
            {
                logger.LogTrace("Write {Write} ", StorageProviderUtils.PrintOneWrite(keys, grainState.State, grainState.ETag));
            }
            IMemoryStorageGrain storageGrain = GetStorageGrain(key);

            try
            {
                grainState.ETag = await storageGrain.WriteStateAsync(STATE_STORE_NAME, key, grainState);
            }
            catch (MemoryStorageEtagMismatchException e)
            {
                throw e.AsInconsistentStateException();
            }
        }
Ejemplo n.º 9
0
        /// <summary> Write state data function for this storage provider. </summary>
        /// <see cref="IStorageProvider.WriteStateAsync"/>
        public virtual async Task WriteStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
        {
            IList <Tuple <string, string> > keys = MakeKeys(grainType, grainReference).ToList();
            string key = HierarchicalKeyStore.MakeStoreKey(keys);

            if (Log.IsVerbose2)
            {
                Log.Verbose2("Write {0} ", StorageProviderUtils.PrintOneWrite(keys, grainState.State, grainState.ETag));
            }
            IMemoryStorageGrain storageGrain = GetStorageGrain(key);

            try
            {
                grainState.ETag = await storageGrain.WriteStateAsync(STATE_STORE_NAME, key, grainState);
            }
            catch (MemoryStorageEtagMismatchException e)
            {
                throw e.AsInconsistentStateException();
            }
        }
Ejemplo n.º 10
0
        /// <summary> Delete / Clear state data function for this storage provider. </summary>
        /// <see cref="IStorageProvider#ClearStateAsync"/>
        public virtual async Task ClearStateAsync(string grainType, GrainReference grainReference, GrainState grainState)
        {
            var    keys = MakeKeys(grainType, grainReference);
            string eTag = grainState.Etag; // TOD: Should this be 'null' for always Delete?

            if (Log.IsVerbose2)
            {
                Log.Verbose2("Delete Keys={0} Etag={1}", StorageProviderUtils.PrintKeys(keys), eTag);
            }

            if (eTag != null && eTag != etag)
            {
                throw new InconsistentStateException(string.Format("Etag mismatch durign Delete: Expected = {0} Received = {1}", this.etag, eTag));
            }

            string key = HierarchicalKeyStore.MakeStoreKey(keys);
            IMemoryStorageGrain storageGrain = GetStorageGrain(key);
            await storageGrain.DeleteStateAsync(STATE_STORE_NAME, key);

            etag = NewEtag();
        }
Ejemplo n.º 11
0
        /// <summary> Delete / Clear state data function for this storage provider. </summary>
        /// <see cref="IGrainStorage.ClearStateAsync"/>
        public virtual async Task ClearStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
        {
            var keys = MakeKeys(grainType, grainReference);

            if (logger.IsEnabled(LogLevel.Trace))
            {
                logger.LogTrace("Delete Keys={Keys} Etag={Etag}", StorageProviderUtils.PrintKeys(keys), grainState.ETag);
            }
            string key = HierarchicalKeyStore.MakeStoreKey(keys);
            IMemoryStorageGrain storageGrain = GetStorageGrain(key);

            try
            {
                await storageGrain.DeleteStateAsync(STATE_STORE_NAME, key, grainState.ETag);

                grainState.ETag = null;
            }
            catch (MemoryStorageEtagMismatchException e)
            {
                throw e.AsInconsistentStateException();
            }
        }
Ejemplo n.º 12
0
        /// <summary> Write state data function for this storage provider. </summary>
        /// <see cref="IStorageProvider#WriteStateAsync"/>
        public virtual async Task WriteStateAsync(string grainType, GrainReference grainReference, GrainState grainState)
        {
            var    keys         = MakeKeys(grainType, grainReference);
            var    data         = grainState.AsDictionary();
            string receivedEtag = grainState.Etag;

            if (Log.IsVerbose2)
            {
                Log.Verbose2("Write {0} ", StorageProviderUtils.PrintOneWrite(keys, data, receivedEtag));
            }

            if (receivedEtag != null && receivedEtag != etag)
            {
                throw new InconsistentStateException(string.Format("Etag mismatch durign Write: Expected = {0} Received = {1}", etag, receivedEtag));
            }

            string key = HierarchicalKeyStore.MakeStoreKey(keys);
            IMemoryStorageGrain storageGrain = GetStorageGrain(key);
            await storageGrain.WriteStateAsync(STATE_STORE_NAME, key, data);

            etag = NewEtag();
        }
Ejemplo n.º 13
0
        /// <summary> Delete / Clear state data function for this storage provider. </summary>
        /// <see cref="IStorageProvider.ClearStateAsync"/>
        public virtual async Task ClearStateAsync(string grainType, GrainReference grainReference, IGrainState grainState)
        {
            IList <Tuple <string, string> > keys = MakeKeys(grainType, grainReference).ToList();

            if (Log.IsVerbose2)
            {
                Log.Verbose2("Delete Keys={0} Etag={1}", StorageProviderUtils.PrintKeys(keys), grainState.ETag);
            }
            string key = HierarchicalKeyStore.MakeStoreKey(keys);
            IMemoryStorageGrain storageGrain = GetStorageGrain(key);

            try
            {
                await storageGrain.DeleteStateAsync(STATE_STORE_NAME, key, grainState.ETag);

                grainState.ETag = null;
            }
            catch (MemoryStorageEtagMismatchException e)
            {
                throw e.AsInconsistentStateException();
            }
        }