public static async Task<StateManagerLease> GetOrCreateAsync( IReliableStateManager StateManager, IReliableDictionary<string, string> StateDictionary, string EntryName, string partitionId) { using (ITransaction tx = StateManager.CreateTransaction()) { StateManagerLease lease; // if something has been saved before load it ConditionalResult<string> cResults = await StateDictionary.TryGetValueAsync(tx, EntryName); if (cResults.HasValue) { lease = FromJsonString(cResults.Value); lease.m_EntryName = EntryName; lease.m_StateDictionary = StateDictionary; lease.m_StateManager = StateManager; } else { // if not create new lease = new StateManagerLease(StateManager, StateDictionary, EntryName, partitionId); } await tx.CommitAsync(); return lease; } }
public OrderWSSession(IReliableStateManager stateManager, Microsoft.Owin.IOwinContext context, IWebSocketSessionManager<IWebSocketSession> factory, CancellationToken cancelToken) : base(stateManager, context, factory, cancelToken) { }
public ServiceFabricSocketSessionBase(IReliableStateManager stateManager, IOwinContext context, IWebSocketSessionManager<IWebSocketSession> factory, CancellationToken cancelToken) : base(context, factory, cancelToken) { StateManager = stateManager; }
public BackupUtility(ref IReliableStateManager stateManager, BackupConfig config, ElapsedEventHandler callback) { _stateManager = stateManager; _backupConfig = config; _timer = new Timer(); _timer.Elapsed += callback; _timer.Interval = _backupConfig.BackupInterval; }
public EventHubCommunicationListener(string connectionString, string eventHubName, string consumerGroupName, IReliableStateManager reliableStateManager, Uri serviceName, Guid partitionId) { _connectionString = connectionString; _eventHubName = eventHubName; _consumerGroupName = consumerGroupName; _reliableStateManager = reliableStateManager; _serviceName = serviceName; _partitionId = partitionId; }
/// <summary> /// Creates a new service class instance with the given state manager and service parameters. /// </summary> /// <param name="stateManager"></param> /// <param name="serviceParameters"></param> public ApplicationDeployService( IReliableStateManager stateManager, IApplicationOperator applicationOperator, StatefulServiceParameters serviceParameters) { this.StateManager = stateManager; this.serviceParameters = serviceParameters; this.applicationOperator = applicationOperator; this.ConfigureService(); }
public StockEventsHandler(IReliableStateManager stateMgr, string productsCollectionName) { if (stateMgr == null) { throw new ArgumentNullException(nameof(this.stateManager)); } this.stateManager = stateMgr; this.productsCollectionName = productsCollectionName; }
private StateManagerLease( IReliableStateManager StateManager, IReliableDictionary<string, string> StateDictionary, string EntryName, string partitionId) { this.m_StateManager = StateManager; this.m_StateDictionary = StateDictionary; this.m_EntryName = EntryName; this.PartitionId = partitionId; }
public static Task<StateManagerLease> GetOrCreateAsync( IReliableStateManager StateManager, IReliableDictionary<string, string> StateDictionary, string ServiceBusNamespace, string ConsumerGroupName, string EventHubName, string PartitionId) { string defaultEntryName = GetDefaultLeaseEntryName(ServiceBusNamespace, ConsumerGroupName, EventHubName, PartitionId); return GetOrCreateAsync(StateManager, StateDictionary, defaultEntryName, PartitionId); }
public static void RegisterComponents(HttpConfiguration config, IReliableStateManager stateManager) { UnityContainer container = new UnityContainer(); // The default controller needs a state manager to perform operations. // Using the DI container, we can inject it as a dependency. // This allows use to write unit tests against the controller using a mock state manager. container.RegisterType<DefaultController>( new TransientLifetimeManager(), new InjectionConstructor(stateManager)); config.DependencyResolver = new UnityDependencyResolver(container); }
/// <summary> /// Creates a new instance of the service class. /// </summary> /// <param name="clusterOperator"></param> /// <param name="mailer"></param> /// <param name="stateManager"></param> /// <param name="serviceContext"></param> /// <param name="config"></param> public ClusterService( IClusterOperator clusterOperator, ISendMail mailer, IApplicationDeployService applicationDeployService, IReliableStateManager stateManager, StatefulServiceContext serviceContext, ClusterConfig config) : base(serviceContext, stateManager as IReliableStateManagerReplica) { this.config = config; this.clusterOperator = clusterOperator; this.applicationDeployService = applicationDeployService; this.mailer = mailer; }
public DefaultPartitionStateFactory(IReliableStateManager stateManager, string reliableDictionaryName, string entriesPrefix) { if(null == reliableDictionaryName) throw new ArgumentNullException(nameof(reliableDictionaryName)); if (null == entriesPrefix) throw new ArgumentNullException(nameof(entriesPrefix)); mStateManager = stateManager; ReliableDictionaryName = string.Empty == reliableDictionaryName ? DEFAULT_DICTIONARY_NAME : reliableDictionaryName; EntriesPrefix = entriesPrefix; }
/// <summary> /// Creates a new instance of the service class. /// </summary> /// <param name="clusterOperator"></param> /// <param name="mailer"></param> /// <param name="stateManager"></param> /// <param name="serviceParameters"></param> /// <param name="config"></param> public ClusterService( IClusterOperator clusterOperator, ISendMail mailer, IApplicationDeployService applicationDeployService, IReliableStateManager stateManager, StatefulServiceParameters serviceParameters, ClusterConfig config) { this.config = config; this.clusterOperator = clusterOperator; this.applicationDeployService = applicationDeployService; this.mailer = mailer; this.StateManager = stateManager; this.serviceParameters = serviceParameters; this.ConfigureService(); }
public EventHubCommunicationListener( ITraceWriter TraceWriter, IReliableStateManager stateManager, IReliableDictionary<string, string> stateDictionary, ServiceInitializationParameters serviceParameters, string eventHubName, string eventHubConnectionString, string eventHubConsumerGroupName, IEventDataHandler handler) : this(TraceWriter, stateManager, stateDictionary, serviceParameters, eventHubName, eventHubConnectionString, eventHubConsumerGroupName, handler, EventHubCommunicationListenerMode.SafeDistribute, string.Empty) { }
public EventHubCommunicationListener( ITraceWriter TraceWriter, IReliableStateManager stateManager, IReliableDictionary<string, string> stateDictionary, ServiceInitializationParameters serviceParameters, string eventHubName, string eventHubConnectionString, string eventHubConsumerGroupName, IEventDataHandler handler, EventHubCommunicationListenerMode Mode, string eventHubPartitionId) { this.ListenerMode = Mode; if (this.ListenerMode == EventHubCommunicationListenerMode.Single && string.IsNullOrEmpty(eventHubPartitionId)) { throw new InvalidOperationException("Event hub communication listener in single mode requires a partition id"); } this.m_TraceWriter = TraceWriter; this.m_InitParams = serviceParameters; this.EventHubName = eventHubName; this.EventHubConnectionString = eventHubConnectionString; this.Handler = handler; this.EventHubConsumerGroupName = eventHubConsumerGroupName; this.StateManager = stateManager; this.StateDictionary = stateDictionary; this.ListenerMode = Mode; this.m_TraceWriter.TraceMessage( string.Format( "Event Hub Listener created for {0} on {1} group:{2} mode:{3}", this.EventHubName, this.Namespace, this.EventHubConsumerGroupName, this.ListenerMode.ToString())); }
public ServiceFabricReliableConcurrentQueuePublisher(IReliableStateManager stateManager, string queueName, TimeSpan?timeout = null) { _stateManager = stateManager ?? throw new ArgumentNullException(nameof(stateManager)); _queueName = queueName ?? throw new ArgumentNullException(nameof(queueName)); _timeout = timeout; }
public ServiceFabricPerReleaseService(IReliableStateManager stateManager) { _stateManager = stateManager; }
public FakeClusterOperator(IReliableStateManager stateManager) { this.stateManager = stateManager; }
public DefaultController(IReliableStateManager stateManager) { this.stateManager = stateManager; }
public DeviceRegistryRepository(IReliableStateManager stateManager) { _stateManager = stateManager; }
public ReliableStateLeaseRepository(IReliableStateManager stateManager) { _stateManager = stateManager; }
public ServiceFabricReliableDictionaryBlobStorageProvider(IReliableStateManager stateManager, string collectionName) { _stateManager = stateManager ?? throw new ArgumentNullException(nameof(stateManager)); _collectionName = collectionName ?? throw new ArgumentNullException(nameof(collectionName)); }
public static async Task <IReliableConcurrentQueue <Guid> > GetPendingArchiveGroupQueue(IReliableStateManager stateManager) { return(await stateManager.GetOrAddAsync <IReliableConcurrentQueue <Guid> >(PendingArchiveGroupQueueName)); }
public CircuitBreaker(IReliableStateManager stateManager, int resetTimeoutInMilliseconds) { this.stateManager = stateManager; this.resetTimeoutInMilliseconds = resetTimeoutInMilliseconds; }
/// <summary> /// Initializes a new instance of the DefaultController class. /// </summary> /// <param name="stateManager">Reliable object state manager.</param> public CountyHealthController(IReliableStateManager stateManager, HealthIndexCalculator indexCalculator) { this.stateManager = stateManager; this.indexCalculator = indexCalculator; }
public ProductRepository(IReliableStateManager reliableStateManager) { _reliableStateManager = reliableStateManager; }
internal ReliableDictionaryCheckpointMananger(IReliableStateManager rsm) { this.reliableStateManager = rsm; }
public static async Task <IReliableDictionary <string, Cart> > GetCartDictionary(this IReliableStateManager stateManager) { return(await stateManager.GetOrAddAsync <IReliableDictionary <string, Cart> >(Constants.CART_DICTIONARY)); }
public static async Task <List <IReliableDictionary2 <Guid, ConversationMsg> > > GetAllMessageListDictsAsync(IReliableStateManager stateManager) { var lst = new List <IReliableDictionary2 <Guid, ConversationMsg> >(); foreach (var key in StringExtensions.PartitionKeys) { lst.Add(await stateManager.GetOrAddAsync <IReliableDictionary2 <Guid, ConversationMsg> >(MessageListDictNamePrefix + "/" + key)); } return(lst); }
/// <summary> /// Delete the existing reliable collection for this index. /// This is called internally and should not be directly called. /// </summary> async Task IIndexDefinition <TKey, TValue> .RemoveIndexAsync(ITransaction tx, IReliableStateManager stateManager, Uri baseName, TimeSpan timeout) { var indexName = GetIndexName(baseName); await stateManager.RemoveAsync(tx, indexName, timeout).ConfigureAwait(false); _index = null; }
/// <summary> /// This constructor is used in unit tests to inject a different state manager for unit testing. /// </summary> /// <param name="stateManager"></param> public InventoryService(IReliableStateManager stateManager) { this.stateManager = stateManager; }
public WireMockCommunicationListener(StatefulServiceContext context, IReliableStateManager reliableStateManager) { _context = context; _reliableStateManager = reliableStateManager; }
public static async Task <IReliableConcurrentQueue <ConversationMsg> > GetMessageProcessQueue(IReliableStateManager stateManager) { return(await stateManager.GetOrAddAsync <IReliableConcurrentQueue <ConversationMsg> >(MessageProcessQueueName)); }
public DevicesController(IReliableStateManager stateManager, ServiceCancellation serviceCancellation) { this.stateManager = stateManager; this.serviceCancellationToken = serviceCancellation.Token; }
internal ServiceFabricStorageContext(PipelineExecutor pipelineExecutor, IReliableStateManager stateManager) { this.pipelineExecutor = pipelineExecutor; StateManager = stateManager; }
public HelloController(IReliableStateManager stateManager) { _stateManager = stateManager; }
public WebSocketCommunicationListener(IReliableStateManager StateManager) { m_ReliableStateManager = StateManager; }
public Publisher(IReliableStateManager stateManager, Func <EventData, IEvent> deserializer) { this.deserializer = deserializer; this.stateManager = stateManager; }
public TestActor(IReliableStateManager stateManager) { _stateManager = stateManager; }
public Startup(IReliableStateManager stateManager) { this.stateManager = stateManager; }
/// <summary> /// Constructor. Arguments break down into three groups: (1) Service Fabric objects so this library can access /// Service Fabric facilities, (2) Event Hub-related arguments which indicate what event hub to receive from and /// how to process the events, and (3) advanced, which right now consists only of the ability to replace the default /// reliable dictionary-based checkpoint manager with a user-provided implementation. /// </summary> /// <param name="serviceFabricServiceName">Service Fabric Uri found in StatefulServiceContext</param> /// <param name="serviceFabricPartitionId">Service Fabric partition id found in StatefulServiceContext</param> /// <param name="stateManager">Service Fabric-provided state manager, provides access to reliable dictionaries</param> /// <param name="partition">Service Fabric-provided partition information</param> /// <param name="userEventProcessor">User's event processor implementation</param> /// <param name="eventHubConnectionString">Connection string for user's event hub</param> /// <param name="eventHubConsumerGroup">Name of event hub consumer group to receive from</param> /// <param name="options">Optional: Options structure for ServiceFabricProcessor library</param> /// <param name="checkpointManager">Very advanced/optional: user-provided checkpoint manager implementation</param> public ServiceFabricProcessor(Uri serviceFabricServiceName, Guid serviceFabricPartitionId, IReliableStateManager stateManager, IStatefulServicePartition partition, IEventProcessor userEventProcessor, string eventHubConnectionString, string eventHubConsumerGroup, EventProcessorOptions options = null, ICheckpointMananger checkpointManager = null) { if (serviceFabricServiceName == null) { throw new ArgumentNullException("serviceFabricServiceName is null"); } if (serviceFabricPartitionId == null) { throw new ArgumentNullException("serviceFabricPartitionId is null"); } if (stateManager == null) { throw new ArgumentNullException("stateManager is null"); } if (partition == null) { throw new ArgumentNullException("partition is null"); } if (userEventProcessor == null) { throw new ArgumentNullException("userEventProcessor is null"); } if (string.IsNullOrEmpty(eventHubConnectionString)) { throw new ArgumentException("eventHubConnectionString is null or empty"); } if (string.IsNullOrEmpty(eventHubConsumerGroup)) { throw new ArgumentException("eventHubConsumerGroup is null or empty"); } this.serviceFabricServiceName = serviceFabricServiceName; this.serviceFabricPartitionId = serviceFabricPartitionId; this.serviceStateManager = stateManager; this.servicePartition = partition; this.userEventProcessor = userEventProcessor; this.ehConnectionString = new EventHubsConnectionStringBuilder(eventHubConnectionString); this.consumerGroupName = eventHubConsumerGroup; this.options = options ?? new EventProcessorOptions(); this.checkpointManager = checkpointManager ?? new ReliableDictionaryCheckpointMananger(this.serviceStateManager); this.EventHubClientFactory = new EventHubWrappers.EventHubClientFactory(); this.TestMode = false; }
public DefaultPartitionStateFactory(IReliableStateManager stateManager, string reliableDictionaryName) : this (stateManager, reliableDictionaryName, string.Empty) { }
public PartialIngestController() { _reliableStateManager = StateManagerHelper.ReliableStateManager; }
/// <summary> /// Gets the values from the reliable state as the <see cref="Entity{TKey, TValue}"/> of the collection. /// </summary> /// <param name="state">Reliable state (must implement <see cref="IReliableDictionary{TKey, TValue}"/>).</param> /// <param name="tx">Transaction to create the enumerable under.</param> /// <param name="partitionId">Partition id.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns>Values from the reliable state as <see cref="Entity{TKey, TValue}"/> values.</returns> private static async Task <IAsyncEnumerable <object> > GetAsyncEnumerable(this IReliableState state, ITransaction tx, IReliableStateManager stateManager, Guid partitionId, CancellationToken cancellationToken) { if (!state.ImplementsGenericType(typeof(IReliableDictionary <,>))) { throw new ArgumentException(nameof(state)); } var entityType = state.GetEntityType(); // Create the async enumerable. var dictionaryType = typeof(IReliableDictionary <,>).MakeGenericType(state.GetType().GetGenericArguments()); var createEnumerableAsyncTask = state.CallMethod <Task>("CreateEnumerableAsync", new[] { typeof(ITransaction) }, tx); await createEnumerableAsyncTask.ConfigureAwait(false); // Get the AsEntity method to convert to an Entity enumerable. var asyncEnumerable = createEnumerableAsyncTask.GetPropertyValue <object>("Result"); var asEntityMethod = typeof(ReliableStateExtensions).GetMethod("AsEntity", BindingFlags.NonPublic | BindingFlags.Static).MakeGenericMethod(entityType.GenericTypeArguments); return((IAsyncEnumerable <object>)asEntityMethod.Invoke(null, new object[] { asyncEnumerable, partitionId, cancellationToken })); }
public static async Task <IReliableDictionary2 <Guid, List <Guid> > > GetMessageIndexDictByIdAsync(IReliableStateManager stateManager, Guid conversationId) { var key = conversationId.ToString().Substring(0, 1).ToLower(); return(await stateManager.GetOrAddAsync <IReliableDictionary2 <Guid, List <Guid> > >(MessageIndexDictNamePrefix + "/" + key)); }
/// <summary> /// Load or create the reliable collection for this index and cache it. /// This is called internally and should not be directly called. /// </summary> async Task IIndexDefinition <TKey, TValue> .GetOrAddIndexAsync(ITransaction tx, IReliableStateManager stateManager, Uri baseName, TimeSpan timeout) { var indexName = GetIndexName(baseName); _index = await stateManager.GetOrAddAsync <IReliableDictionary2 <TFilter, TKey[]> >(tx, indexName, timeout).ConfigureAwait(false); }
protected override IReliableStateManager CreateReliableStateManager() { if (this.stateManager == null) { this.stateManager = base.CreateReliableStateManager(); } return this.stateManager; }
public ServiceFabricReliableQueueReceiver(IReliableStateManager stateManager, string queueName, TimeSpan scanInterval) : base(stateManager, queueName, scanInterval) { _stateManager = stateManager; _queueName = queueName; }
public Startup(IReliableStateManager objectManager) { this.objectManager = objectManager; }
/// <summary> /// Creates a new service class instance with the given state manager and service parameters. /// </summary> /// <param name="stateManager"></param> /// <param name="serviceContext"></param> public ApplicationDeployService( IReliableStateManager stateManager, IApplicationOperator applicationOperator, StatefulServiceContext serviceContext) : base(serviceContext, stateManager as IReliableStateManagerReplica) { this.applicationOperator = applicationOperator; }
public ServiceFabricJournal() { this.StateManager = ServiceFabricPersistence.Instance.Apply(Context.System).StateManager; }
public ValuesController(IReliableStateManager stateManager, ServiceContext serviceContext) { this.serviceContext = serviceContext; this.stateManager = stateManager; this.retry = new ReliableCollectionRetry(); }
public VoteDataController(IReliableStateManager stateManager) { this.stateManager = stateManager; }
public ServiceFabricProductRepository(IReliableStateManager stateManager) { _stateManager = stateManager; }
public ServiceFabricJournal(IReliableStateManager stateManager) { StateManager = stateManager; }
public DefaultPartitionStateFactory(IReliableStateManager stateManager) : this(stateManager,string. Empty) { }
public UserFavoriteAppService(StatefulServiceContext serviceContext, IReliableStateManager stateManager) : base(serviceContext, stateManager) { }
public DevicesController(IReliableStateManager stateManager, StatefulServiceContext context, IApplicationLifetime appLifetime) { this.stateManager = stateManager; this.appLifetime = appLifetime; this.context = context; }
/// <summary> /// Execute the operations given in <paramref name="operations"/> in a transaction. /// </summary> /// <param name="stateManager">Reliable state manager for the replica.</param> /// <param name="operations">Operations (add/update/delete) to perform against collections in the partition.</param> /// <returns>A list of status codes indicating success/failure of the operations.</returns> public static async Task <List <EntityOperationResult> > ExecuteAsync(this IReliableStateManager stateManager, EntityOperation <JToken, JToken>[] operations) { var results = new List <EntityOperationResult>(); using (var tx = stateManager.CreateTransaction()) { bool commit = true; foreach (var operation in operations) { HttpStatusCode status = HttpStatusCode.BadRequest; string description = null; try { // Get the reliable dictionary for this operation. var dictionary = await stateManager.GetQueryableState(operation.Collection).ConfigureAwait(false); // Execute operation. if (operation.Operation == Operation.Add) { status = await ExecuteAddAsync(tx, dictionary, operation).ConfigureAwait(false); } else if (operation.Operation == Operation.Update) { status = await ExecuteUpdateAsync(tx, dictionary, operation).ConfigureAwait(false); } else if (operation.Operation == Operation.Delete) { status = await ExecuteDeleteAsync(tx, dictionary, operation).ConfigureAwait(false); } } catch (QueryException e) { status = e.Status; description = e.Message; } catch (ArgumentException e) { status = HttpStatusCode.BadRequest; description = e.Message; } catch (Exception) { status = HttpStatusCode.InternalServerError; } // Add the operation result. results.Add(new EntityOperationResult { PartitionId = operation.PartitionId, Collection = operation.Collection, Key = operation.Key, Status = (int)status, Description = description, }); // If any operation failed, abort the transaction. if (!status.IsSuccessStatusCode()) { commit = false; } } // Commit or abort the transaction. if (commit) { await tx.CommitAsync().ConfigureAwait(false); } else { tx.Abort(); } } return(results); }