public async Task Init(string name, IProviderRuntime providerUtilitiesManager, IProviderConfiguration config)
        {
            if (!stateManager.PresetState(ProviderState.Initialized))
            {
                return;
            }
            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();
            // Temporary change, but we need GrainFactory inside ServiceProvider for now,
            // so will change it back as soon as we have an action item to add GrainFactory to ServiceProvider.
            adapterFactory.Init(config, Name, logger, new GrainFactoryServiceProvider(providerRuntime));
            queueAdapter = await adapterFactory.CreateAdapter();

            myConfig                  = new PersistentStreamProviderConfig(config);
            this.providerConfig       = config;
            this.serializationManager = this.providerRuntime.ServiceProvider.GetRequiredService <SerializationManager>();
            this.runtimeClient        = this.providerRuntime.ServiceProvider.GetRequiredService <IRuntimeClient>();
            if (this.myConfig.PubSubType == StreamPubSubType.ExplicitGrainBasedAndImplicit ||
                this.myConfig.PubSubType == StreamPubSubType.ExplicitGrainBasedOnly)
            {
                this.streamSubscriptionManager = this.providerRuntime.ServiceProvider
                                                 .GetService <IStreamSubscriptionManagerAdmin>().GetStreamSubscriptionManager(StreamSubscriptionManagerType.ExplicitSubscribeOnly);
            }
            string startup;

            if (config.Properties.TryGetValue(StartupStatePropertyName, 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, StartupStatePropertyName, config.Name));
                }
            }
            else
            {
                startupState = StartupStateDefaultValue;
            }
            logger.Info("Initialized PersistentStreamProvider<{0}> with name {1}, Adapter {2} and config {3}, {4} = {5}.",
                        typeof(TAdapterFactory).Name,
                        Name,
                        queueAdapter.Name,
                        myConfig,
                        StartupStatePropertyName, startupState);
            stateManager.CommitState();
        }
예제 #2
0
        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);

            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);
        }
예제 #3
0
        public async Task Init(string name, IProviderRuntime providerUtilitiesManager, IProviderConfiguration config)
        {
            if (!stateManager.PresetState(ProviderState.Initialized))
            {
                return;
            }
            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, providerRuntime.ServiceProvider);
            queueAdapter = await adapterFactory.CreateAdapter();

            myConfig = new PersistentStreamProviderConfig(config);
            string startup;

            if (config.Properties.TryGetValue(StartupStatePropertyName, 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, StartupStatePropertyName, config.Name));
                }
            }
            else
            {
                startupState = StartupStateDefaultValue;
            }

            logger.Info("Initialized PersistentStreamProvider<{0}> with name {1}, Adapter {2} and config {3}, {4} = {5}.",
                        typeof(TAdapterFactory).Name,
                        Name,
                        queueAdapter.Name,
                        myConfig,
                        StartupStatePropertyName, startupState);
            stateManager.CommitState();
        }
예제 #4
0
        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);
        }