Esempio n. 1
0
 public static bool TryGet(int id, out InMemoryDataStore dataStore)
 {
     lock (_dataStoreMap)
     {
         return(_dataStoreMap.TryGetValue(id, out dataStore));
     }
 }
Esempio n. 2
0
 public InMemoryFabricConnector(
     InMemoryDataStore dataStore,
     ISerializer serializer,
     string serializerFormat)
 {
     _dataStore        = dataStore;
     _serializer       = serializer;
     _serializerFormat = serializerFormat;
 }
Esempio n. 3
0
        public InMemoryFabric(ITransitionRunner transitionRunner,
                              IInMemoryFabricSerializerFactoryAdvisor serializerFactoryAdvisor)
        {
            _transitionRunner = transitionRunner;
            DataStore         = InMemoryDataStore.Create(ScheduleMessage);
            var serializerFactory = serializerFactoryAdvisor.Advise();

            _serializationFormat = serializerFactory.Format;
            Serializer           = serializerFactory.Create();
            Connector            = new InMemoryFabricConnector(DataStore, Serializer, _serializationFormat);
        }
        public Task PublishEventAsync(RaiseEventIntent intent, CancellationToken ct)
        {
            var message = new Message
            {
                IsEvent             = true,
                [nameof(ServiceId)] = _serializer.SerializeToString(intent.ServiceId),
                [nameof(EventId)]   = _serializer.SerializeToString(intent.EventId),
                ["Parameters"]      = _serializer.SerializeToString(intent.Parameters)
            };

            InMemoryDataStore.BroadcastMessage(message);

            return(Task.FromResult(0));
        }
Esempio n. 5
0
        public static InMemoryDataStore Create(Action <Message> scheduleMessageAction)
        {
            var id        = Interlocked.Increment(ref _idCounter);
            var dataStore = new InMemoryDataStore
            {
                Id = id,
                ScheduleMessage = scheduleMessageAction
            };

            lock (_dataStoreMap)
            {
                _dataStoreMap.Add(id, dataStore);
            }
            return(dataStore);
        }
Esempio n. 6
0
        public InMemoryFabric(ITransitionRunner transitionRunner,
                              IInMemoryFabricSerializerFactoryAdvisor serializerFactoryAdvisor,
                              IUniqueIdGenerator numericIdGenerator,
                              IServiceProviderScope serviceProviderScope)
        {
            _transitionRunner     = transitionRunner;
            _uniqueIdGenerator    = numericIdGenerator;
            _serviceProviderScope = serviceProviderScope;

            DataStore = InMemoryDataStore.Create(ScheduleMessage);
            var serializerFactory = serializerFactoryAdvisor.Advise();

            _serializationFormat = serializerFactory.Format;
            Serializer           = serializerFactory.Create();
            Connector            = new InMemoryFabricConnector(DataStore, Serializer, _serializationFormat);
        }
        public IFabricConnector Create(ServiceId serviceId, object configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var config = (InMemoryFabricConnectorConfiguration)configuration;

            if (!InMemoryDataStore.TryGet(config.DataStoreId, out var dataStore))
            {
                throw new InvalidOperationException($"In-memory data store with ID '{config.DataStoreId}' does not exist.");
            }

            var serializerFactory = _serializerFactorySelector.Select(config.SerializerFormat);
            var serializer        = serializerFactory.Create();

            return(new InMemoryFabricConnector(dataStore, serializer, config.SerializerFormat));
        }