/// <summary> /// Create stream queue balancer by type requested /// </summary> /// <param name="balancerType">queue balancer type to create</param> /// <param name="strProviderName">name of requesting stream provider</param> /// <param name="siloStatusOracle">membership services interface.</param> /// <param name="clusterConfiguration">cluster configuration</param> /// <param name="runtime">stream provider runtime environment to run in</param> /// <param name="queueMapper">queue mapper of requesting stream provider</param> /// <param name="siloMaturityPeriod">Maturity Period of a silo for queue rebalancing purposes</param> /// <returns>Constructed stream queue balancer</returns> public static IStreamQueueBalancer Create( StreamQueueBalancerType balancerType, string strProviderName, ISiloStatusOracle siloStatusOracle, ClusterConfiguration clusterConfiguration, IStreamProviderRuntime runtime, IStreamQueueMapper queueMapper, TimeSpan siloMaturityPeriod) { if (string.IsNullOrWhiteSpace(strProviderName)) { throw new ArgumentNullException("strProviderName"); } if (siloStatusOracle == null) { throw new ArgumentNullException("siloStatusOracle"); } if (clusterConfiguration == null) { throw new ArgumentNullException("clusterConfiguration"); } if (runtime == null) { throw new ArgumentNullException("runtime"); } if (queueMapper == null) { throw new ArgumentNullException("queueMapper"); } bool isFixed; switch (balancerType) { case StreamQueueBalancerType.ConsistentRingBalancer: { // Consider: for now re-use the same ConsistentRingProvider with 1 equally devided range. Remove later. IConsistentRingProviderForGrains ringProvider = runtime.GetConsistentRingProvider(0, 1); return new ConsistentRingQueueBalancer(ringProvider, queueMapper); } case StreamQueueBalancerType.DynamicAzureDeploymentBalancer: case StreamQueueBalancerType.StaticAzureDeploymentBalancer: { Logger logger = LogManager.GetLogger(typeof(StreamQueueBalancerFactory).Name, LoggerType.Runtime); var wrapper = AssemblyLoader.LoadAndCreateInstance<IDeploymentConfiguration>(Constants.ORLEANS_AZURE_UTILS_DLL, logger); isFixed = balancerType == StreamQueueBalancerType.StaticAzureDeploymentBalancer; return new DeploymentBasedQueueBalancer(siloStatusOracle, wrapper, queueMapper, siloMaturityPeriod, isFixed); } case StreamQueueBalancerType.DynamicClusterConfigDeploymentBalancer: case StreamQueueBalancerType.StaticClusterConfigDeploymentBalancer: { IDeploymentConfiguration deploymentConfiguration = new StaticClusterDeploymentConfiguration(clusterConfiguration); isFixed = balancerType == StreamQueueBalancerType.StaticClusterConfigDeploymentBalancer; return new DeploymentBasedQueueBalancer(siloStatusOracle, deploymentConfiguration, queueMapper, siloMaturityPeriod, isFixed); } default: { string error = string.Format("Unsupported balancerType for stream provider. BalancerType: {0}, StreamProvider: {1}", balancerType, strProviderName); throw new ArgumentOutOfRangeException("balancerType", error); } } }
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); IQueueAdapterFactory factory = new TAdapterFactory(); factory.Init(config, Name, logger); queueAdapter = await factory.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); logger.Info("Initialized PersistentStreamProvider<{0}> with name {1}, {2} = {3}, {4} = {5} and with Adapter {6}.", typeof(TAdapterFactory).Name, Name, GET_QUEUE_MESSAGES_TIMER_PERIOD, getQueueMsgsTimerPeriod, INIT_QUEUE_TIMEOUT, this.initQueueTimeout, queueAdapter.Name); }
public Task StartPullingAgents( string streamProviderName, StreamQueueBalancerType balancerType, IQueueAdapter queueAdapter, TimeSpan getQueueMsgsTimerPeriod, TimeSpan initQueueTimeout) { return(TaskDone.Done); }
public async Task StartPullingAgents( string streamProviderName, StreamQueueBalancerType balancerType, IQueueAdapter queueAdapter, TimeSpan getQueueMsgsTimerPeriod, TimeSpan initQueueTimeout) { IStreamQueueBalancer queueBalancer = StreamQueueBalancerFactory.Create( balancerType, streamProviderName, Silo.CurrentSilo.LocalSiloStatusOracle, this, queueAdapter.GetStreamQueueMapper()); var managerId = GrainId.NewSystemTargetGrainIdByTypeCode(Constants.PULLING_AGENTS_MANAGER_SYSTEM_TARGET_TYPE_CODE); var manager = new PersistentStreamPullingManager(managerId, streamProviderName, this, queueBalancer, getQueueMsgsTimerPeriod, initQueueTimeout); this.RegisterSystemTarget(manager); // Init the manager only after it was registered locally. var managerGrainRef = PersistentStreamPullingManagerFactory.Cast(manager.AsReference()); // Need to call it as a grain reference though. await managerGrainRef.Initialize(queueAdapter.AsImmutable()); }
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 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); }