Example #1
0
 public TransactionalState(
     ITransactionalStateConfiguration transactionalStateConfiguration,
     IGrainActivationContext context,
     ITransactionDataCopier <TState> copier,
     IProviderRuntime runtime,
     IGrainRuntime grainRuntime,
     ILoggerFactory loggerFactory,
     JsonSerializerSettings serializerSettings
     )
 {
     this.config             = transactionalStateConfiguration;
     this.context            = context;
     this.copier             = copier;
     this.runtime            = runtime;
     this.grainRuntime       = grainRuntime;
     this.loggerFactory      = loggerFactory;
     this.serializerSettings = serializerSettings;
     this.copiers            = new Dictionary <Type, object>();
     this.copiers.Add(typeof(TState), copier);
 }
Example #2
0
        public Grain CreateGrainInstance(IGrainActivationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var grain = (Grain)_activator.Create(context);

            var participant = grain as ILifecycleParticipant <IGrainLifecycle>;

            participant?.Participate(context.ObservableLifecycle);

            //Set the runtime and identity. This is equivalent to what Orleans' GrainCreator does
            //when creating new grains. It is messier but easier than trying to wrangle the values
            //in via a constructor which may or may exist on types inheriting from Grain.
            _runtimeProperty.SetValue(grain, _runtime);
            _identityField.SetValue(grain, context.GrainIdentity);

            return(grain);
        }
Example #3
0
        /// <inheritdoc />
        public virtual object Create(IGrainActivationContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var grainType = context.GrainType;

            if (grainType == null)
            {
                throw new ArgumentException(
                          string.Format(
                              CultureInfo.InvariantCulture, "The '{0}' property of '{1}' must not be null.",
                              nameof(context.GrainType),
                              nameof(IGrainActivationContext)));
            }

            var serviceProvider = context.ActivationServices;
            var activator       = this.typeActivatorCache.GetOrAdd(grainType, this.CreateFactory);
            var grain           = activator(serviceProvider, this.argumentFactory.CreateArguments(context));

            return(grain);
        }
 public TransactionManagerExtension(IGrainActivationContext context)
 {
     this.factories = context.GetResourceFactoryRegistry <ITransactionManager>();
     this.managers  = new Dictionary <string, ITransactionManager>();
 }
        private static void SetGrainActivationContextInScopedServices(IServiceProvider sp, IGrainActivationContext context)
        {
            var contextFactory = sp.GetRequiredService <GrainActivationContextFactory>();

            contextFactory.Context = context;
        }
        public static void RegisterResourceFactory <T>(this IGrainActivationContext context, string name, Func <T> factory)
        {
            ResourceFactoryRegistry <T> registry = context.GetResourceFactoryRegistry <T>(true);

            registry[name] = factory;
        }
 public NamedTransactionalStateStorageFactory(IGrainActivationContext context)
 {
     this.context = context;
 }
 public NamedTransactionalStateStorageFactory(IGrainActivationContext context, ILoggerFactory loggerFactory)
 {
     this.context       = context;
     this.loggerFactory = loggerFactory;
 }
Example #9
0
 public GrainWithSimpleService(IGrainActivationContext context, ISimpleGrainServiceClient client)
 {
     SimpleGrainServiceClient = client;
 }
Example #10
0
        private object Create(IGrainActivationContext context, MethodInfo genericCreate, object[] args)
        {
            IFaultInjectionTransactionalStateFactory factory = context.ActivationServices.GetRequiredService <IFaultInjectionTransactionalStateFactory>();

            return(genericCreate.Invoke(factory, args));
        }
Example #11
0
 public FaultInjectionTransactionalStateFactory(IGrainActivationContext context, ITypeResolver typeResolver, IGrainFactory grainFactory)
 {
     this.context            = context;
     this.serializerSettings =
         TransactionalStateFactory.GetJsonSerializerSettings(typeResolver, grainFactory);
 }
Example #12
0
 public TransactionCommitterFactory(IGrainActivationContext context)
 {
     this.context = context;
 }
Example #13
0
 public ActivationLifetime(IGrainActivationContext activationContext)
 {
     activationContext.ObservableLifecycle.Subscribe(GrainLifecycleStage.First, this);
     activationContext.ObservableLifecycle.Subscribe(GrainLifecycleStage.Last, this);
 }
Example #14
0
 public SagaGrain(IGrainActivationContext grainContext, IServiceProvider serviceProvider, ILogger <SagaGrain> logger)
 {
     this.grainContext    = grainContext;
     this.serviceProvider = serviceProvider;
     this.logger          = logger;
 }
Example #15
0
 public GrainControlExtension(IGrainActivationContext context, IGrainRuntime runtime)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
     _runtime = runtime ?? throw new ArgumentNullException(nameof(runtime));
 }
 public PersistentStateBridge(string fullStateName, IGrainActivationContext context, IGrainStorage storageProvider)
 {
     this.fullStateName   = fullStateName;
     this.context         = context;
     this.storageProvider = storageProvider;
 }
Example #17
0
 public BlobExampleStorageFactory(IGrainActivationContext context)
 {
     this.context = context;
 }
 public override Task Execute(Guid sagaId, IGrainFactory grainFactory, IGrainActivationContext grainContext)
 {
     throw new NotImplementedException();
 }
Example #19
0
 public void Release(IGrainActivationContext context, object grain)
 {
     this.grainActivator.Release(context, grain);
 }
 public TransactionalStateStorageProviderWrapper(IStorageProvider storageProvider, IGrainActivationContext context)
 {
     this.storageProvider = storageProvider;
     this.context         = context;
     this.stateStorages   = new ConcurrentDictionary <string, IStorage <TransactionalStateRecord <TState> > >();
 }
Example #21
0
 public SagaGrain(IGrainActivationContext grainContext, ILogger <SagaGrain> logger)
 {
     this.grainContext = grainContext;
     this.logger       = logger;
 }
Example #22
0
 public override Task Compensate(Guid sagaId, IGrainFactory grainFactory, IGrainActivationContext grainContext)
 {
     return(Task.CompletedTask);
 }
Example #23
0
 public ITransactionalStateStorage <TState> Create <TState>(string stateName, IGrainActivationContext context) where TState : class, new()
 {
     return(ActivatorUtilities.CreateInstance <MongoDBTransactionalStateStorage <TState> >(
                context.ActivationServices,
                this.db.GetCollection <BsonDocument>("tsr_" + stateName), jsonSettings));
 }
Example #24
0
 public override Task Execute(Guid sagaId, IGrainFactory grainFactory, IGrainActivationContext grainContext)
 {
     // comment in to test compensation.
     //throw new SeatUnavailableException();
     return(Task.CompletedTask);
 }
Example #25
0
 public ActivationLimit(IGrainActivationContext context, IActivationLimiter limiter)
 {
     this.context = context;
     this.limiter = limiter;
 }
Example #26
0
 public IndexedStateFactory(IGrainActivationContext activationContext, ITypeResolver typeResolver, IGrainFactory grainFactory)
 => this.activationContext = activationContext;
Example #27
0
 public TransactionalState(ITransactionalStateConfiguration transactionalStateConfiguration, IGrainActivationContext context, ITransactionDataCopier <TState> copier, ITransactionAgent transactionAgent, IProviderRuntime runtime, ILoggerFactory loggerFactory)
 {
     this.config           = transactionalStateConfiguration;
     this.context          = context;
     this.copier           = copier;
     this.transactionAgent = transactionAgent;
     this.runtime          = runtime;
     this.logger           = loggerFactory.CreateLogger($"{this.GetType().FullName}.{this.context.GrainIdentity}.{this.config.StateName}");
     this.transactionCopy  = new Dictionary <long, TState>();
     this.storageExecutor  = new AsyncSerialExecutor <bool>();
     this.log = new SortedDictionary <long, LogRecord <TState> >();
 }
Example #28
0
        public ITransactionalStateStorage <TState> Create <TState>(string stateName, IGrainActivationContext context) where TState : class, new()
        {
            string partitionKey = MakePartitionKey(context, stateName);

            return(ActivatorUtilities.CreateInstance <AzureTableTransactionalStateStorage <TState> >(context.ActivationServices, this.table, partitionKey, stateName, this.jsonSettings));
        }
Example #29
0
        private object Create(IGrainActivationContext context, MethodInfo genericCreate, object[] args)
        {
            INamedExampleStorageFactory factory = context.ActivationServices.GetRequiredService <INamedExampleStorageFactory>();

            return(genericCreate.Invoke(factory, args));
        }
 protected virtual string GetFullStateName(IGrainActivationContext context, IPersistentStateConfiguration cfg)
 {
     return($"{RuntimeTypeNameFormatter.Format(context.GrainType)}.{cfg.StateName}");
 }