public Task Init(string name, IProviderRuntime providerUtilitiesManager, IProviderConfiguration config) { if (!stateManager.PresetState(ProviderState.Initialized)) { return(TaskDone.Done); } this.Name = name; providerRuntime = (IStreamProviderRuntime)providerUtilitiesManager; this.runtimeClient = this.providerRuntime.ServiceProvider.GetRequiredService <IRuntimeClient>(); fireAndForgetDelivery = config.GetBoolProperty(FIRE_AND_FORGET_DELIVERY, DEFAULT_VALUE_FIRE_AND_FORGET_DELIVERY); optimizeForImmutableData = config.GetBoolProperty(OPTIMIZE_FOR_IMMUTABLE_DATA, DEFAULT_VALUE_OPTIMIZE_FOR_IMMUTABLE_DATA); string pubSubTypeString; pubSubType = !config.Properties.TryGetValue(STREAM_PUBSUB_TYPE, out pubSubTypeString) ? DEFAULT_STREAM_PUBSUB_TYPE : (StreamPubSubType)Enum.Parse(typeof(StreamPubSubType), pubSubTypeString); if (pubSubType == StreamPubSubType.ExplicitGrainBasedAndImplicit || pubSubType == StreamPubSubType.ExplicitGrainBasedOnly) { this.streamSubscriptionManager = this.providerRuntime.ServiceProvider .GetService <IStreamSubscriptionManagerAdmin>().GetStreamSubscriptionManager(StreamSubscriptionManagerType.ExplicitSubscribeOnly); } logger = providerRuntime.GetLogger(this.GetType().Name); logger.Info("Initialized SimpleMessageStreamProvider with name {0} and with property FireAndForgetDelivery: {1}, OptimizeForImmutableData: {2} " + "and PubSubType: {3}", Name, fireAndForgetDelivery, optimizeForImmutableData, pubSubType); stateManager.CommitState(); return(TaskDone.Done); }
/// <summary> /// Adds a stream provider of type <see cref="SimpleMessageStreamProvider"/> /// </summary> /// <param name="config">The cluster configuration object to add provider to.</param> /// <param name="providerName">The provider name.</param> /// <param name="fireAndForgetDelivery">Specifies whether the producer waits for the consumer to process the event before continuing. Setting this to false is useful for troubleshooting serialization issues.</param> /// <param name="optimizeForImmutableData">If set to true items transfered via the stream are always wrapped in Immutable for delivery.</param>> /// <param name="pubSubType">Specifies how can grains subscribe to this stream.</param> public static void AddSimpleMessageStreamProvider(this ClientConfiguration config, string providerName, bool fireAndForgetDelivery = SimpleMessageStreamProvider.DEFAULT_VALUE_FIRE_AND_FORGET_DELIVERY, bool optimizeForImmutableData = SimpleMessageStreamProvider.DEFAULT_VALUE_OPTIMIZE_FOR_IMMUTABLE_DATA, StreamPubSubType pubSubType = SimpleMessageStreamProvider.DEFAULT_STREAM_PUBSUB_TYPE) { var properties = GetSimpleMessageStreamProviderConfiguration(providerName, fireAndForgetDelivery, optimizeForImmutableData, pubSubType); config.RegisterStreamProvider<SimpleMessageStreamProvider>(providerName, properties); }
/// <summary> /// Adds a stream provider of type <see cref="SimpleMessageStreamProvider"/> /// </summary> /// <param name="config">The cluster configuration object to add provider to.</param> /// <param name="providerName">The provider name.</param> /// <param name="fireAndForgetDelivery">Specifies whether the producer waits for the consumer to process the event before continuing. Setting this to false is useful for troubleshooting serialization issues.</param> /// <param name="optimizeForImmutableData">If set to true items transfered via the stream are always wrapped in Immutable for delivery.</param>> /// <param name="pubSubType">Specifies how can grains subscribe to this stream.</param> public static void AddSimpleMessageStreamProvider(this ClientConfiguration config, string providerName, bool fireAndForgetDelivery = SimpleMessageStreamProvider.DEFAULT_VALUE_FIRE_AND_FORGET_DELIVERY, bool optimizeForImmutableData = SimpleMessageStreamProvider.DEFAULT_VALUE_OPTIMIZE_FOR_IMMUTABLE_DATA, StreamPubSubType pubSubType = SimpleMessageStreamProvider.DEFAULT_STREAM_PUBSUB_TYPE) { var properties = GetSimpleMessageStreamProviderConfiguration(providerName, fireAndForgetDelivery, optimizeForImmutableData, pubSubType); config.RegisterStreamProvider<SimpleMessageStreamProvider>(providerName, properties); }
public PersistentStreamProviderConfig(IProviderConfiguration config) { string timePeriod; if (!config.Properties.TryGetValue(GET_QUEUE_MESSAGES_TIMER_PERIOD, out timePeriod)) { GetQueueMsgsTimerPeriod = DEFAULT_GET_QUEUE_MESSAGES_TIMER_PERIOD; } else { GetQueueMsgsTimerPeriod = ConfigUtilities.ParseTimeSpan(timePeriod, "Invalid time value for the " + GET_QUEUE_MESSAGES_TIMER_PERIOD + " property in the provider config values."); } string timeout; if (!config.Properties.TryGetValue(INIT_QUEUE_TIMEOUT, out timeout)) { InitQueueTimeout = DEFAULT_INIT_QUEUE_TIMEOUT; } else { InitQueueTimeout = ConfigUtilities.ParseTimeSpan(timeout, "Invalid time value for the " + INIT_QUEUE_TIMEOUT + " property in the provider config values."); } string balanceTypeString; BalancerType = !config.Properties.TryGetValue(QUEUE_BALANCER_TYPE, out balanceTypeString) ? DEFAULT_STREAM_QUEUE_BALANCER_TYPE : (StreamQueueBalancerType)Enum.Parse(typeof(StreamQueueBalancerType), balanceTypeString); if (!config.Properties.TryGetValue(MAX_EVENT_DELIVERY_TIME, out timeout)) { MaxEventDeliveryTime = DEFAULT_MAX_EVENT_DELIVERY_TIME; } else { MaxEventDeliveryTime = ConfigUtilities.ParseTimeSpan(timeout, "Invalid time value for the " + MAX_EVENT_DELIVERY_TIME + " property in the provider config values."); } if (!config.Properties.TryGetValue(STREAM_INACTIVITY_PERIOD, out timeout)) { StreamInactivityPeriod = DEFAULT_STREAM_INACTIVITY_PERIOD; } else { StreamInactivityPeriod = ConfigUtilities.ParseTimeSpan(timeout, "Invalid time value for the " + STREAM_INACTIVITY_PERIOD + " property in the provider config values."); } string pubSubTypeString; PubSubType = !config.Properties.TryGetValue(STREAM_PUBSUB_TYPE, out pubSubTypeString) ? DEFAULT_STREAM_PUBSUB_TYPE : (StreamPubSubType)Enum.Parse(typeof(StreamPubSubType), pubSubTypeString); }
private static Dictionary<string, string> GetSimpleMessageStreamProviderConfiguration(string providerName, bool fireAndForgetDelivery, bool optimizeForImmutableData, StreamPubSubType pubSubType) { if (string.IsNullOrWhiteSpace(providerName)) throw new ArgumentNullException(nameof(providerName)); var properties = new Dictionary<string, string> { { SimpleMessageStreamProvider.FIRE_AND_FORGET_DELIVERY, fireAndForgetDelivery.ToString() }, { SimpleMessageStreamProvider.OPTIMIZE_FOR_IMMUTABLE_DATA, optimizeForImmutableData.ToString() }, { SimpleMessageStreamProvider.STREAM_PUBSUB_TYPE, pubSubType.ToString() }, }; return properties; }
public IStreamPubSub PubSub(StreamPubSubType pubSubType) { switch (pubSubType) { case StreamPubSubType.ExplicitGrainBasedAndImplicit: return combinedGrainBasedAndImplicitPubSub; case StreamPubSubType.ExplicitGrainBasedOnly: return grainBasedPubSub; case StreamPubSubType.ImplicitOnly: return implictPubSub; default: return null; } }
public IStreamPubSub PubSub(StreamPubSubType pubSubType) { switch (pubSubType) { case StreamPubSubType.ExplicitGrainBasedAndImplicit: return(combinedGrainBasedAndImplicitPubSub); case StreamPubSubType.ExplicitGrainBasedOnly: return(grainBasedPubSub); case StreamPubSubType.ImplicitOnly: return(implictPubSub); default: return(null); } }
public Task Init(string name, IProviderRuntime providerUtilitiesManager, IProviderConfiguration config) { this.Name = name; providerRuntime = (IStreamProviderRuntime)providerUtilitiesManager; fireAndForgetDelivery = config.GetBoolProperty(FIRE_AND_FORGET_DELIVERY, DEFAULT_VALUE_FIRE_AND_FORGET_DELIVERY); optimizeForImmutableData = config.GetBoolProperty(OPTIMIZE_FOR_IMMUTABLE_DATA, DEFAULT_VALUE_OPTIMIZE_FOR_IMMUTABLE_DATA); string pubSubTypeString; pubSubType = !config.Properties.TryGetValue(STREAM_PUBSUB_TYPE, out pubSubTypeString) ? DEFAULT_STREAM_PUBSUB_TYPE : (StreamPubSubType)Enum.Parse(typeof(StreamPubSubType), pubSubTypeString); logger = providerRuntime.GetLogger(this.GetType().Name); logger.Info("Initialized SimpleMessageStreamProvider with name {0} and with property FireAndForgetDelivery: {1}, OptimizeForImmutableData: {2} " + "and PubSubType: {3}", Name, fireAndForgetDelivery, optimizeForImmutableData, pubSubType); return(TaskDone.Done); }
public Task Init(string name, IProviderRuntime providerUtilitiesManager, IProviderConfiguration config) { this.Name = name; providerRuntime = (IStreamProviderRuntime)providerUtilitiesManager; string fireAndForgetDeliveryStr; fireAndForgetDelivery = config.Properties.TryGetValue(FIRE_AND_FORGET_DELIVERY, out fireAndForgetDeliveryStr) && Boolean.Parse(fireAndForgetDeliveryStr); string pubSubTypeString; pubSubType = !config.Properties.TryGetValue(STREAM_PUBSUB_TYPE, out pubSubTypeString) ? DEFAULT_STREAM_PUBSUB_TYPE : (StreamPubSubType)Enum.Parse(typeof(StreamPubSubType), pubSubTypeString); logger = providerRuntime.GetLogger(this.GetType().Name); logger.Info("Initialized SimpleMessageStreamProvider with name {0} and with property FireAndForgetDelivery: {1} " + "and PubSubType: {2}", Name, fireAndForgetDelivery, pubSubType); return(TaskDone.Done); }
public Task InitializePullingAgents( string streamProviderName, StreamQueueBalancerType balancerType, StreamPubSubType pubSubType, IQueueAdapterFactory adapterFactory, IQueueAdapter queueAdapter, TimeSpan getQueueMsgsTimerPeriod, TimeSpan initQueueTimeout, TimeSpan maxEventDeliveryTime) { IStreamQueueBalancer queueBalancer = StreamQueueBalancerFactory.Create( balancerType, streamProviderName, Silo.CurrentSilo.LocalSiloStatusOracle, Silo.CurrentSilo.OrleansConfig, this, adapterFactory.GetStreamQueueMapper()); var managerId = GrainId.NewSystemTargetGrainIdByTypeCode(Constants.PULLING_AGENTS_MANAGER_SYSTEM_TARGET_TYPE_CODE); var manager = new PersistentStreamPullingManager(managerId, streamProviderName, this, this.PubSub(pubSubType), adapterFactory, queueBalancer, getQueueMsgsTimerPeriod, initQueueTimeout, maxEventDeliveryTime); this.RegisterSystemTarget(manager); // Init the manager only after it was registered locally. pullingAgentManager = manager.AsReference <IPersistentStreamPullingManager>(); // Need to call it as a grain reference though. return(pullingAgentManager.Initialize(queueAdapter.AsImmutable())); }
public IStreamPubSub PubSub(StreamPubSubType pubSubType) { return(pubSubType == StreamPubSubType.GrainBased ? pubSub : null); }
public static ISiloPersistentStreamConfigurator ConfigureStreamPubSub(this ISiloPersistentStreamConfigurator configurator, StreamPubSubType pubsubType = StreamPubSubOptions.DEFAULT_STREAM_PUBSUB_TYPE) { configurator.Configure <StreamPubSubOptions>(ob => ob.Configure(options => options.PubSubType = pubsubType)); return(configurator); }
private static Dictionary <string, string> GetSimpleMessageStreamProviderConfiguration(string providerName, bool fireAndForgetDelivery, bool optimizeForImmutableData, StreamPubSubType pubSubType) { if (string.IsNullOrWhiteSpace(providerName)) { throw new ArgumentNullException(nameof(providerName)); } var properties = new Dictionary <string, string> { { SimpleMessageStreamProvider.FIRE_AND_FORGET_DELIVERY, fireAndForgetDelivery.ToString() }, { SimpleMessageStreamProvider.OPTIMIZE_FOR_IMMUTABLE_DATA, optimizeForImmutableData.ToString() }, { SimpleMessageStreamProvider.STREAM_PUBSUB_TYPE, pubSubType.ToString() }, }; return(properties); }
/// <summary> /// Adds a stream provider of type <see cref="SimpleMessageStreamProvider"/> /// </summary> /// <param name="config">The cluster configuration object to add provider to.</param> /// <param name="providerName">The provider name.</param> /// <param name="fireAndForgetDelivery">Specifies whether the producer waits for the consumer to process the event before continuing. Setting this to false is useful for troubleshooting serialization issues.</param> /// <param name="pubSubType">Specifies how can grains subscribe to this stream.</param> public static void AddSimpleMessageStreamProvider(this ClientConfiguration config, string providerName, bool fireAndForgetDelivery = false, StreamPubSubType pubSubType = SimpleMessageStreamProvider.DEFAULT_STREAM_PUBSUB_TYPE) { var properties = GetSimpleMessageStreamProviderConfiguration(providerName, fireAndForgetDelivery, pubSubType); config.RegisterStreamProvider <SimpleMessageStreamProvider>(providerName, properties); }
public PersistentStreamProviderConfig(IProviderConfiguration config) { string timePeriod; if (!config.Properties.TryGetValue(GET_QUEUE_MESSAGES_TIMER_PERIOD, out timePeriod)) GetQueueMsgsTimerPeriod = DEFAULT_GET_QUEUE_MESSAGES_TIMER_PERIOD; else GetQueueMsgsTimerPeriod = ConfigUtilities.ParseTimeSpan(timePeriod, "Invalid time value for the " + GET_QUEUE_MESSAGES_TIMER_PERIOD + " property in the provider config values."); string timeout; if (!config.Properties.TryGetValue(INIT_QUEUE_TIMEOUT, out timeout)) InitQueueTimeout = DEFAULT_INIT_QUEUE_TIMEOUT; else InitQueueTimeout = ConfigUtilities.ParseTimeSpan(timeout, "Invalid time value for the " + INIT_QUEUE_TIMEOUT + " property in the provider config values."); string balanceTypeString; BalancerType = !config.Properties.TryGetValue(QUEUE_BALANCER_TYPE, out balanceTypeString) ? DEFAULT_STREAM_QUEUE_BALANCER_TYPE : (StreamQueueBalancerType)Enum.Parse(typeof(StreamQueueBalancerType), balanceTypeString); if (!config.Properties.TryGetValue(MAX_EVENT_DELIVERY_TIME, out timeout)) MaxEventDeliveryTime = DEFAULT_MAX_EVENT_DELIVERY_TIME; else MaxEventDeliveryTime = ConfigUtilities.ParseTimeSpan(timeout, "Invalid time value for the " + MAX_EVENT_DELIVERY_TIME + " property in the provider config values."); if (!config.Properties.TryGetValue(STREAM_INACTIVITY_PERIOD, out timeout)) StreamInactivityPeriod = DEFAULT_STREAM_INACTIVITY_PERIOD; else StreamInactivityPeriod = ConfigUtilities.ParseTimeSpan(timeout, "Invalid time value for the " + STREAM_INACTIVITY_PERIOD + " property in the provider config values."); string pubSubTypeString; PubSubType = !config.Properties.TryGetValue(STREAM_PUBSUB_TYPE, out pubSubTypeString) ? DEFAULT_STREAM_PUBSUB_TYPE : (StreamPubSubType)Enum.Parse(typeof(StreamPubSubType), pubSubTypeString); }
public static TConfigurator ConfigureStreamPubSub <TConfigurator>(this TConfigurator configurator, StreamPubSubType pubsubType = StreamPubSubOptions.DEFAULT_STREAM_PUBSUB_TYPE) where TConfigurator : IClusterClientPersistentStreamConfigurator { configurator.Configure <StreamPubSubOptions>(ob => ob.Configure(options => options.PubSubType = pubsubType)); return(configurator); }
public async Task Init(string name, IProviderRuntime providerUtilitiesManager, IProviderConfiguration config) { if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } if (providerUtilitiesManager == null) { throw new ArgumentNullException("providerUtilitiesManager"); } if (config == null) { throw new ArgumentNullException("config"); } Name = name; providerRuntime = (IStreamProviderRuntime)providerUtilitiesManager; logger = providerRuntime.GetLogger(this.GetType().Name); adapterFactory = new TAdapterFactory(); adapterFactory.Init(config, Name, logger); queueAdapter = await adapterFactory.CreateAdapter(); string timePeriod; if (!config.Properties.TryGetValue(GET_QUEUE_MESSAGES_TIMER_PERIOD, out timePeriod)) { getQueueMsgsTimerPeriod = DEFAULT_GET_QUEUE_MESSAGES_TIMER_PERIOD; } else { getQueueMsgsTimerPeriod = ConfigUtilities.ParseTimeSpan(timePeriod, "Invalid time value for the " + GET_QUEUE_MESSAGES_TIMER_PERIOD + " property in the provider config values."); } string timeout; if (!config.Properties.TryGetValue(INIT_QUEUE_TIMEOUT, out timeout)) { initQueueTimeout = DEFAULT_INIT_QUEUE_TIMEOUT; } else { initQueueTimeout = ConfigUtilities.ParseTimeSpan(timeout, "Invalid time value for the " + INIT_QUEUE_TIMEOUT + " property in the provider config values."); } string balanceTypeString; balancerType = !config.Properties.TryGetValue(QUEUE_BALANCER_TYPE, out balanceTypeString) ? DEFAULT_STREAM_QUEUE_BALANCER_TYPE : (StreamQueueBalancerType)Enum.Parse(typeof(StreamQueueBalancerType), balanceTypeString); if (!config.Properties.TryGetValue(MAX_EVENT_DELIVERY_TIME, out timeout)) { maxEventDeliveryTime = DEFAULT_MAX_EVENT_DELIVERY_TIME; } else { maxEventDeliveryTime = ConfigUtilities.ParseTimeSpan(timeout, "Invalid time value for the " + MAX_EVENT_DELIVERY_TIME + " property in the provider config values."); } string pubSubTypeString; pubSubType = !config.Properties.TryGetValue(STREAM_PUBSUB_TYPE, out pubSubTypeString) ? DEFAULT_STREAM_PUBSUB_TYPE : (StreamPubSubType)Enum.Parse(typeof(StreamPubSubType), pubSubTypeString); string startup; if (config.Properties.TryGetValue(STARTUP_STATE, out startup)) { if (!Enum.TryParse(startup, true, out startupState)) { throw new ArgumentException( String.Format("Unsupported value '{0}' for configuration parameter {1} of stream provider {2}.", startup, STARTUP_STATE, config.Name)); } } else { startupState = StreamProviderStartupState.Started; } logger.Info("Initialized PersistentStreamProvider<{0}> with name {1}, {2} = {3}, {4} = {5}, {6} = {7} and with Adapter {8}.", typeof(TAdapterFactory).Name, Name, GET_QUEUE_MESSAGES_TIMER_PERIOD, getQueueMsgsTimerPeriod, INIT_QUEUE_TIMEOUT, initQueueTimeout, STARTUP_STATE, startupState, queueAdapter.Name); }
/// <summary> /// Configures the Silo PubSub Type for Stream Provider. /// </summary> /// <param name="builder">The Orleans <see cref="ISiloBuilder"/>.</param> /// <param name="streamProviderName">The Stream Provider name.</param> /// <param name="pubSubType">The PubSub Type.</param> /// <returns></returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> public static ISiloBuilder ConfigurePubSubType([NotNull] this ISiloBuilder builder, [NotNull] string streamProviderName, StreamPubSubType pubSubType) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (string.IsNullOrEmpty(streamProviderName)) { throw new ArgumentException($"'{nameof(streamProviderName)}' must not be null, empty or whitespace.", nameof(streamProviderName)); } return(builder.ConfigureServices(x => x.Configure <StreamPubSubOptions>(streamProviderName, o => o.PubSubType = pubSubType))); }