internal PersistentStreamPullingAgent(
            GrainId id, 
            string strProviderName,
            IStreamProviderRuntime runtime,
            IStreamPubSub streamPubSub,
            QueueId queueId,
            PersistentStreamProviderConfig config)
            : base(id, runtime.ExecutingSiloAddress, true)
        {
            if (runtime == null) throw new ArgumentNullException("runtime", "PersistentStreamPullingAgent: runtime reference should not be null");
            if (strProviderName == null) throw new ArgumentNullException("runtime", "PersistentStreamPullingAgent: strProviderName should not be null");

            QueueId = queueId;
            streamProviderName = strProviderName;
            providerRuntime = runtime;
            pubSub = streamPubSub;
            pubSubCache = new Dictionary<StreamId, StreamConsumerCollection>();
            safeRandom = new SafeRandom();
            this.config = config;
            numMessages = 0;

            logger = providerRuntime.GetLogger(GrainId + "-" + streamProviderName);
            logger.Info((int)ErrorCode.PersistentStreamPullingAgent_01, 
                "Created {0} {1} for Stream Provider {2} on silo {3} for Queue {4}.",
                GetType().Name, GrainId.ToDetailedString(), streamProviderName, Silo, QueueId.ToStringWithHashCode());

            string statUniquePostfix = strProviderName + "." + QueueId;
            numReadMessagesCounter = CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_READ_MESSAGES, statUniquePostfix));
            numSentMessagesCounter = CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_SENT_MESSAGES, statUniquePostfix));
            IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_PUBSUB_CACHE_SIZE, statUniquePostfix), () => pubSubCache.Count);
            IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_QUEUE_CACHE_SIZE, statUniquePostfix), () => queueCache !=null ? queueCache.Size : 0);
        }
        internal PersistentStreamPullingAgent(
            GrainId id,
            string strProviderName,
            IStreamProviderRuntime runtime,
            IStreamPubSub streamPubSub,
            QueueId queueId,
            PersistentStreamProviderConfig config)
            : base(id, runtime.ExecutingSiloAddress, true)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime", "PersistentStreamPullingAgent: runtime reference should not be null");
            }
            if (strProviderName == null)
            {
                throw new ArgumentNullException("runtime", "PersistentStreamPullingAgent: strProviderName should not be null");
            }

            QueueId            = queueId;
            streamProviderName = strProviderName;
            pubSub             = streamPubSub;
            pubSubCache        = new Dictionary <StreamId, StreamConsumerCollection>();
            safeRandom         = new SafeRandom();
            this.config        = config;
            numMessages        = 0;

            logger = runtime.GetLogger(((ISystemTargetBase)this).GrainId + "-" + streamProviderName);
            logger.Info(ErrorCode.PersistentStreamPullingAgent_01,
                        "Created {0} {1} for Stream Provider {2} on silo {3} for Queue {4}.",
                        GetType().Name, ((ISystemTargetBase)this).GrainId.ToDetailedString(), streamProviderName, Silo, QueueId.ToStringWithHashCode());
            numReadMessagesCounter = CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_READ_MESSAGES, StatisticUniquePostfix));
            numSentMessagesCounter = CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_SENT_MESSAGES, StatisticUniquePostfix));
            // TODO: move queue cache size statistics tracking into queue cache implementation once Telemetry APIs and LogStatistics have been reconciled.
            //IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_QUEUE_CACHE_SIZE, statUniquePostfix), () => queueCache != null ? queueCache.Size : 0);
        }
 internal SimpleMessageStreamProducerExtension(IStreamProviderRuntime providerRt, bool fireAndForget)
 {
     providerRuntime = providerRt;
     fireAndForgetDelivery = fireAndForget;
     remoteConsumers = new Dictionary<StreamId, StreamConsumerExtensionCollection>();
     logger = providerRuntime.GetLogger(GetType().Name);
 }
Beispiel #4
0
 internal SimpleMessageStreamProducerExtension(IStreamProviderRuntime providerRt, bool fireAndForget)
 {
     providerRuntime       = providerRt;
     fireAndForgetDelivery = fireAndForget;
     remoteConsumers       = new Dictionary <StreamId, StreamConsumerExtensionCollection>();
     logger = providerRuntime.GetLogger(GetType().Name);
 }
        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();
        }
 internal StreamConsumerExtension(IStreamProviderRuntime providerRt, StreamSubscriptionChangeHandler streamSubscriptionChangeHandler = null)
 {
     this.subscriptionChangeHandler = streamSubscriptionChangeHandler;
     providerRuntime    = providerRt;
     allStreamObservers = new ConcurrentDictionary <GuidId, IStreamSubscriptionHandle>();
     logger             = providerRuntime.GetLogger(GetType().Name);
 }
Beispiel #7
0
 internal StreamConsumerExtension(IStreamProviderRuntime providerRt, bool isRewindable)
 {
     providerRuntime    = providerRt;
     allStreamObservers = new ConcurrentDictionary <GuidId, IStreamSubscriptionHandle>();
     this.isRewindable  = isRewindable;
     logger             = providerRuntime.GetLogger(GetType().Name);
 }
        internal PersistentStreamPullingAgent(
            GrainId id, 
            string strProviderName,
            IStreamProviderRuntime runtime,
            QueueId queueId, 
            TimeSpan queueGetPeriod,
            TimeSpan initQueueTimeout,
            TimeSpan maxDeliveryTime)
            : base(id, runtime.ExecutingSiloAddress, true)
        {
            if (runtime == null) throw new ArgumentNullException("runtime", "PersistentStreamPullingAgent: runtime reference should not be null");
            if (strProviderName == null) throw new ArgumentNullException("runtime", "PersistentStreamPullingAgent: strProviderName should not be null");

            QueueId = queueId;
            streamProviderName = strProviderName;
            providerRuntime = runtime;
            pubSub = runtime.PubSub(StreamPubSubType.GrainBased);
            pubSubCache = new Dictionary<StreamId, StreamConsumerCollection>();
            safeRandom = new SafeRandom();
            this.queueGetPeriod = queueGetPeriod;
            this.initQueueTimeout = initQueueTimeout;
            this.maxDeliveryTime = maxDeliveryTime;
            numMessages = 0;

            logger = providerRuntime.GetLogger(GrainId + "-" + streamProviderName);
            logger.Info((int)ErrorCode.PersistentStreamPullingAgent_01, 
                "Created {0} {1} for Stream Provider {2} on silo {3} for Queue {4}.",
                GetType().Name, GrainId.ToDetailedString(), streamProviderName, Silo, QueueId.ToStringWithHashCode());

            numReadMessagesCounter = CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_READ_MESSAGES, strProviderName));
            numSentMessagesCounter = CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_SENT_MESSAGES, strProviderName));
        }
Beispiel #9
0
        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);
        }
        internal PersistentStreamPullingAgent(
            GrainId id,
            string strProviderName,
            IStreamProviderRuntime runtime,
            QueueId queueId,
            TimeSpan queueGetPeriod,
            TimeSpan initQueueTimeout)
            : base(id, runtime.ExecutingSiloAddress, true)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime", "PersistentStreamPullingAgent: runtime reference should not be null");
            }

            QueueId               = queueId;
            streamProviderName    = strProviderName;
            providerRuntime       = runtime;
            pubSub                = runtime.PubSub(StreamPubSubType.GrainBased);
            pubSubCache           = new Dictionary <StreamId, StreamConsumerCollection>();
            safeRandom            = new SafeRandom();
            this.queueGetPeriod   = queueGetPeriod;
            this.initQueueTimeout = initQueueTimeout;
            numMessages           = 0;

            logger = providerRuntime.GetLogger(this.GrainId.ToString() + "-" + streamProviderName);
            logger.Info((int)ErrorCode.PersistentStreamPullingAgent_01,
                        "Created {0} {1} for Stream Provider {2} on silo {3} for Queue {4}.",
                        this.GetType().Name, this.GrainId.ToDetailedString(), streamProviderName, base.Silo, QueueId.ToStringWithHashCode());

            numReadMessagesCounter = CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_READ_MESSAGES, strProviderName));
            numSentMessagesCounter = CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_SENT_MESSAGES, strProviderName));
        }
        internal PersistentStreamPullingAgent(
            GrainId id, 
            string strProviderName,
            IStreamProviderRuntime runtime,
            IStreamPubSub streamPubSub,
            QueueId queueId,
            PersistentStreamProviderConfig config)
            : base(id, runtime.ExecutingSiloAddress, true)
        {
            if (runtime == null) throw new ArgumentNullException("runtime", "PersistentStreamPullingAgent: runtime reference should not be null");
            if (strProviderName == null) throw new ArgumentNullException("runtime", "PersistentStreamPullingAgent: strProviderName should not be null");

            QueueId = queueId;
            streamProviderName = strProviderName;
            providerRuntime = runtime;
            pubSub = streamPubSub;
            pubSubCache = new Dictionary<StreamId, StreamConsumerCollection>();
            safeRandom = new SafeRandom();
            this.config = config;
            numMessages = 0;

            logger = providerRuntime.GetLogger(GrainId + "-" + streamProviderName);
            logger.Info((int)ErrorCode.PersistentStreamPullingAgent_01, 
                "Created {0} {1} for Stream Provider {2} on silo {3} for Queue {4}.",
                GetType().Name, GrainId.ToDetailedString(), streamProviderName, Silo, QueueId.ToStringWithHashCode());

            string statUniquePostfix = strProviderName + "." + QueueId;
            numReadMessagesCounter = CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_READ_MESSAGES, statUniquePostfix));
            numSentMessagesCounter = CounterStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_SENT_MESSAGES, statUniquePostfix));
            IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_PUBSUB_CACHE_SIZE, statUniquePostfix), () => pubSubCache.Count);
            // TODO: move queue cache size statistics tracking into queue cache implementation once Telemetry APIs and LogStatistics have been reconciled.
            //IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_QUEUE_CACHE_SIZE, statUniquePostfix), () => queueCache != null ? queueCache.Size : 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);
            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);
        }
 internal SimpleMessageStreamProducerExtension(IStreamProviderRuntime providerRt, IStreamPubSub pubsub, bool fireAndForget, bool optimizeForImmutable)
 {
     providerRuntime          = providerRt;
     streamPubSub             = pubsub;
     fireAndForgetDelivery    = fireAndForget;
     optimizeForImmutableData = optimizeForImmutable;
     remoteConsumers          = new Dictionary <StreamId, StreamConsumerExtensionCollection>();
     logger = providerRuntime.GetLogger(GetType().Name);
 }
 internal SimpleMessageStreamProducerExtension(IStreamProviderRuntime providerRt, IStreamPubSub pubsub, bool fireAndForget, bool optimizeForImmutable)
 {
     providerRuntime = providerRt;
     streamPubSub = pubsub;
     fireAndForgetDelivery = fireAndForget;
     optimizeForImmutableData = optimizeForImmutable;
     remoteConsumers = new Dictionary<StreamId, StreamConsumerExtensionCollection>();
     logger = providerRuntime.GetLogger(GetType().Name);
 }
Beispiel #15
0
        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);

            logger = providerRuntime.GetLogger(this.GetType().Name);
            logger.Info("Initialized SimpleMessageStreamProvider with name {0} and with property FireAndForgetDelivery: {1}.", Name, fireAndForgetDelivery);
            return(TaskDone.Done);
        }
        internal PersistentStreamProducer(StreamImpl <T> stream, IStreamProviderRuntime providerUtilities, IQueueAdapter queueAdapter, bool isRewindable)
        {
            this.stream       = stream;
            this.queueAdapter = queueAdapter;
            IsRewindable      = isRewindable;
            var logger = providerUtilities.GetLogger(this.GetType().Name);

            if (logger.IsVerbose)
            {
                logger.Verbose("Created PersistentStreamProducer for stream {0}, of type {1}, and with Adapter: {2}.",
                               stream.ToString(), typeof(T), this.queueAdapter.Name);
            }
        }
Beispiel #17
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();
        }
Beispiel #18
0
        internal SimpleMessageStreamProducer(StreamImpl <T> stream, string streamProviderName, IStreamProviderRuntime providerUtilities, bool fireAndForgetDelivery, bool isRewindable)
        {
            this.stream             = stream;
            this.streamProviderName = streamProviderName;
            providerRuntime         = providerUtilities;
            pubSub = providerRuntime.PubSub(StreamPubSubType.GrainBased);
            connectedToRendezvous      = false;
            this.fireAndForgetDelivery = fireAndForgetDelivery;
            IsRewindable = isRewindable;
            isDisposed   = false;
            logger       = providerRuntime.GetLogger(GetType().Name);
            initLock     = new AsyncLock();

            ConnectToRendezvous().Ignore();
        }
        internal PersistentStreamPullingManager(
            GrainId id,
            string strProviderName,
            IStreamProviderRuntime runtime,
            IStreamPubSub streamPubSub,
            IQueueAdapterFactory adapterFactory,
            IStreamQueueBalancer streamQueueBalancer,
            TimeSpan queueGetPeriod,
            TimeSpan initQueueTimeout,
            TimeSpan maxEvenDeliveryTime)
            : base(id, runtime.ExecutingSiloAddress)
        {
            if (string.IsNullOrWhiteSpace(strProviderName))
            {
                throw new ArgumentNullException("strProviderName");
            }
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime", "IStreamProviderRuntime runtime reference should not be null");
            }
            if (streamPubSub == null)
            {
                throw new ArgumentNullException("streamPubSub", "StreamPubSub reference should not be null");
            }
            if (streamQueueBalancer == null)
            {
                throw new ArgumentNullException("streamQueueBalancer", "IStreamQueueBalancer streamQueueBalancer reference should not be null");
            }

            queuesToAgentsMap                    = new Dictionary <QueueId, PersistentStreamPullingAgent>();
            streamProviderName                   = strProviderName;
            providerRuntime                      = runtime;
            pubSub                               = streamPubSub;
            this.queueGetPeriod                  = queueGetPeriod;
            this.initQueueTimeout                = initQueueTimeout;
            this.maxEvenDeliveryTime             = maxEvenDeliveryTime;
            nonReentrancyGuarantor               = new AsyncSerialExecutor();
            latestRingNotificationSequenceNumber = 0;
            latestCommandNumber                  = 0;
            queueBalancer                        = streamQueueBalancer;
            this.adapterFactory                  = adapterFactory;

            queueAdapterCache = adapterFactory.GetQueueAdapterCache();
            logger            = providerRuntime.GetLogger(GetType().Name + "-" + streamProviderName);
            logger.Info((int)ErrorCode.PersistentStreamPullingManager_01, "Created {0} for Stream Provider {1}.", GetType().Name, streamProviderName);

            IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_PULLING_AGENTS, strProviderName), () => queuesToAgentsMap.Count);
        }
        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);
        }
Beispiel #21
0
        internal SimpleMessageStreamProducer(StreamImpl <T> stream, string streamProviderName,
                                             IStreamProviderRuntime providerUtilities, bool fireAndForgetDelivery, bool optimizeForImmutableData,
                                             IStreamPubSub pubSub, bool isRewindable, SerializationManager serializationManager)
        {
            this.stream                   = stream;
            this.streamProviderName       = streamProviderName;
            providerRuntime               = providerUtilities;
            this.pubSub                   = pubSub;
            this.serializationManager     = serializationManager;
            connectedToRendezvous         = false;
            this.fireAndForgetDelivery    = fireAndForgetDelivery;
            this.optimizeForImmutableData = optimizeForImmutableData;
            IsRewindable                  = isRewindable;
            isDisposed = false;
            logger     = providerRuntime.GetLogger(GetType().Name);
            initLock   = new AsyncLock();

            ConnectToRendezvous().Ignore();
        }
        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);
        }
        internal PersistentStreamPullingManager(
            GrainId id, 
            string strProviderName, 
            IStreamProviderRuntime runtime,
            IQueueAdapterFactory adapterFactory,
            IStreamQueueBalancer streamQueueBalancer,
            TimeSpan queueGetPeriod, 
            TimeSpan initQueueTimeout)
            : base(id, runtime.ExecutingSiloAddress)
        {
            if (string.IsNullOrWhiteSpace(strProviderName))
            {
                throw new ArgumentNullException("strProviderName");
            }
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime", "IStreamProviderRuntime runtime reference should not be null");
            }
            if (streamQueueBalancer == null)
            {
                throw new ArgumentNullException("streamQueueBalancer", "IStreamQueueBalancer streamQueueBalancer reference should not be null");
            }

            queuesToAgentsMap = new Dictionary<QueueId, PersistentStreamPullingAgent>();
            streamProviderName = strProviderName;
            providerRuntime = runtime;
            this.queueGetPeriod = queueGetPeriod;
            this.initQueueTimeout = initQueueTimeout;
            nonReentrancyGuarantor = new AsyncSerialExecutor();
            latestRingNotificationSequenceNumber = 0;
            queueBalancer = streamQueueBalancer;

            queueAdapterCache = adapterFactory.GetQueueAdapterCache();
            logger = providerRuntime.GetLogger(GetType().Name + "-" + streamProviderName);
            logger.Info((int)ErrorCode.PersistentStreamPullingManager_01, "Created {0} for Stream Provider {1}.", GetType().Name, streamProviderName);

            IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_PULLING_AGENTS, strProviderName), () => queuesToAgentsMap.Count);
        }
        internal PersistentStreamPullingManager(
            GrainId id, 
            string strProviderName, 
            IStreamProviderRuntime runtime,
            IStreamPubSub streamPubSub,
            IQueueAdapterFactory adapterFactory,
            IStreamQueueBalancer streamQueueBalancer,
            PersistentStreamProviderConfig config)
            : base(id, runtime.ExecutingSiloAddress)
        {
            if (string.IsNullOrWhiteSpace(strProviderName))
            {
                throw new ArgumentNullException("strProviderName");
            }
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime", "IStreamProviderRuntime runtime reference should not be null");
            }
            if (streamPubSub == null)
            {
                throw new ArgumentNullException("streamPubSub", "StreamPubSub reference should not be null");
            }
            if (streamQueueBalancer == null)
            {
                throw new ArgumentNullException("streamQueueBalancer", "IStreamQueueBalancer streamQueueBalancer reference should not be null");
            }

            queuesToAgentsMap = new Dictionary<QueueId, PersistentStreamPullingAgent>();
            streamProviderName = strProviderName;
            providerRuntime = runtime;
            pubSub = streamPubSub;
            this.config = config;
            nonReentrancyGuarantor = new AsyncSerialExecutor();
            latestRingNotificationSequenceNumber = 0;
            latestCommandNumber = 0;
            queueBalancer = streamQueueBalancer;
            this.adapterFactory = adapterFactory;

            queueAdapterCache = adapterFactory.GetQueueAdapterCache();
            logger = providerRuntime.GetLogger(GetType().Name + "-" + streamProviderName);
            logger.Info((int)ErrorCode.PersistentStreamPullingManager_01, "Created {0} for Stream Provider {1}.", GetType().Name, streamProviderName);

            IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_PULLING_AGENTS, strProviderName), () => queuesToAgentsMap.Count);
            queuePrintTimer = providerRuntime.RegisterTimer(AsyncTimerCallback, null, QUEUES_PRINT_PERIOD, QUEUES_PRINT_PERIOD);
        }
        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);
        }
Beispiel #26
0
 internal StreamConsumerExtension(IStreamProviderRuntime providerRt)
 {
     providerRuntime    = providerRt;
     allStreamObservers = new ConcurrentDictionary <StreamId, IStreamObservers>();
     logger             = providerRuntime.GetLogger(this.GetType().Name);
 }