public ValueTask <IStateStorage <S, K> > GetStateStorage <K, S>(Orleans.Grain grain) where S : class, IState <K>, new() { switch (grain) { case Account value: return(GetFromType(value.GetType())); default: throw new NotImplementedException(nameof(GetEventStorage)); } //通过类型获取Storage async ValueTask <IStateStorage <S, K> > GetFromType(Type type) { if (!stateStorageDict.TryGetValue(type.FullName, out var storage)) { var grainConfigTask = GetConfig(grain); if (!grainConfigTask.IsCompleted) { await grainConfigTask; } storage = stateStorageDict.GetOrAdd(type.FullName, key => { return(new SqlStateStorage <S, K>(grainConfigTask.Result)); }); } return(storage as SqlStateStorage <S, K>); } }
public async ValueTask <IProducer> GetProducer(Orleans.Grain grain) { var type = grain.GetType(); if (!ServiceDictionary.TryGetValue(type, out var service)) { if (PublisherDictionary.TryGetValue(type, out var value)) { var buildTask = value.Build(rabbitMQClient); if (!buildTask.IsCompleted) { await buildTask; } service = ServiceDictionary.GetOrAdd(type, key => { return(new RabbitMQService(value)); }); } else { throw new NotImplementedException(nameof(GetProducer)); } } return(service); }
private async ValueTask <MongoGrainConfig> GetConfig(Orleans.Grain grain) { var spilitTableStartTime = DateTime.UtcNow; MongoGrainConfig result; switch (grain) { case Account value: result = sqlGrainConfigDict.GetOrAdd(value.GetType().FullName, key => new MongoGrainConfig(mongoStorage, "Ray", "account_event", "account_state", spilitTableStartTime)); break; case AccountRep value: result = sqlGrainConfigDict.GetOrAdd(value.GetType().FullName, key => new MongoGrainConfig(mongoStorage, "Ray", "account_event", "account_state", spilitTableStartTime)); break; case AccountDb value: result = sqlGrainConfigDict.GetOrAdd(value.GetType().FullName, key => new MongoGrainConfig(mongoStorage, "Ray", "account_event", "account_db_state", spilitTableStartTime)); break; case AccountFlow value: result = sqlGrainConfigDict.GetOrAdd(value.GetType().FullName, key => new MongoGrainConfig(mongoStorage, "Ray", "account_event", "account_flow_state", spilitTableStartTime));; break; default: throw new NotImplementedException(nameof(GetEventStorage)); } var buildTask = result.Build(); if (!buildTask.IsCompleted) { await buildTask; } return(result); }
private async ValueTask <SqlGrainConfig> GetConfig(Orleans.Grain grain) { var spilitTableStartTime = DateTime.UtcNow; SqlGrainConfig result; switch (grain) { case Account value: result = sqlGrainConfigDict.GetOrAdd(value.GetType().FullName, key => new SqlGrainConfig(config.ConnectionDict["core_event"], "account_event", "account_state", spilitTableStartTime)); break; default: throw new NotImplementedException(nameof(GetEventStorage)); } var buildTask = result.Build(); if (!buildTask.IsCompleted) { await buildTask; } return(result); }