/// <inheritdoc /> public async Task ReadStateAsync() { const string what = "ReadState"; Stopwatch sw = Stopwatch.StartNew(); try { GrainRuntime.CheckRuntimeContext(RuntimeContext.Current); await store.ReadStateAsync(name, grainRef, grainState); StorageStatisticsGroup.OnStorageRead(name, grainRef, sw.Elapsed); } catch (Exception exc) { StorageStatisticsGroup.OnStorageReadError(name, grainRef); string errMsg = MakeErrorMsg(what, exc); this.logger.LogError((int)ErrorCode.StorageProvider_ReadFailed, exc, "{Message}", errMsg); if (!(exc is OrleansException)) { throw new OrleansException(errMsg, exc); } throw; } finally { sw.Stop(); } }
/// <summary> /// Async method to cause write of the current grain state data into backing store. /// </summary> public async Task WriteStateAsync() { const string what = "WriteState"; try { GrainRuntime.CheckRuntimeContext(RuntimeContext.Current); Stopwatch sw = Stopwatch.StartNew(); await store.WriteStateAsync(name, grainRef, grainState); sw.Stop(); StorageStatisticsGroup.OnStorageWrite(name, grainRef, sw.Elapsed); } catch (Exception exc) { StorageStatisticsGroup.OnStorageWriteError(name, grainRef); string errMsgToLog = MakeErrorMsg(what, exc); this.logger.Error((int)ErrorCode.StorageProvider_WriteFailed, errMsgToLog, exc); // If error is not specialization of OrleansException, wrap it if (!(exc is OrleansException)) { throw new OrleansException(errMsgToLog, exc); } throw; } }
/// <inheritdoc /> public async Task ClearStateAsync() { const string what = "ClearState"; try { GrainRuntime.CheckRuntimeContext(RuntimeContext.Current); Stopwatch sw = Stopwatch.StartNew(); // Clear (most likely Delete) state from external storage await store.ClearStateAsync(name, grainRef, grainState); sw.Stop(); // Reset the in-memory copy of the state grainState.State = Activator.CreateInstance <TState>(); // Update counters StorageStatisticsGroup.OnStorageDelete(name, grainRef, sw.Elapsed); } catch (Exception exc) { StorageStatisticsGroup.OnStorageDeleteError(name, grainRef); string errMsg = MakeErrorMsg(what, exc); this.logger.LogError((int)ErrorCode.StorageProvider_DeleteFailed, exc, "{Message}", errMsg); if (!(exc is OrleansException)) { throw new OrleansException(errMsg, exc); } throw; } }
/// <summary> /// Static constructor. /// </summary> static GrainClient() { GrainClient.GrainFactory = new GrainFactory(); GrainClient.Runtime = new GrainRuntime(GrainClient.GrainFactory); string assemblyPath = Path.GetDirectoryName(Assembly.GetCallingAssembly().Location); ProxyFactory = ActorModel.Runtime.CreateMachine(typeof(OrleansGrainFactory), new ActorFactory.InitEvent(assemblyPath)); ActorModel.RegisterCleanUpAction(() => { ProxyFactory = ActorModel.Runtime.CreateMachine(typeof(OrleansGrainFactory), new ActorFactory.InitEvent(assemblyPath)); }); }