Example #1
0
        public PersistentStreamProvider(string name, PersistentStreamOptions options, IProviderRuntime runtime, SerializationManager serializationManager, ILogger <PersistentStreamProvider> logger)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (runtime == null)
            {
                throw new ArgumentNullException(nameof(runtime));
            }
            if (serializationManager == null)
            {
                throw new ArgumentNullException(nameof(serializationManager));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            this.Name                 = name;
            this.options              = options;
            this.runtime              = runtime.ServiceProvider.GetRequiredService <IStreamProviderRuntime>();
            this.runtimeClient        = runtime.ServiceProvider.GetRequiredService <IRuntimeClient>();
            this.serializationManager = serializationManager;
            this.logger               = logger;
        }
        internal PersistentStreamPullingManager(
            GrainId id,
            string strProviderName,
            IStreamProviderRuntime runtime,
            IStreamPubSub streamPubSub,
            IQueueAdapterFactory adapterFactory,
            IStreamQueueBalancer streamQueueBalancer,
            PersistentStreamOptions options,
            ILoggerFactory loggerFactory)
            : base(id, runtime.ExecutingSiloAddress, loggerFactory)
        {
            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.options           = options;
            nonReentrancyGuarantor = new AsyncSerialExecutor();
            latestRingNotificationSequenceNumber = 0;
            latestCommandNumber = 0;
            queueBalancer       = streamQueueBalancer;
            this.adapterFactory = adapterFactory;

            queueAdapterCache = adapterFactory.GetQueueAdapterCache();
            logger            = loggerFactory.CreateLogger($"{GetType().FullName}-{streamProviderName}");
            Log(ErrorCode.PersistentStreamPullingManager_01, "Created {0} for Stream Provider {1}.", GetType().Name, streamProviderName);
            this.loggerFactory = loggerFactory;
            IntValueStatistic.FindOrCreate(new StatisticName(StatisticNames.STREAMS_PERSISTENT_STREAM_NUM_PULLING_AGENTS, strProviderName), () => queuesToAgentsMap.Count);
        }
Example #3
0
        public async Task <IPersistentStreamPullingManager> InitializePullingAgents(
            string streamProviderName,
            IQueueAdapterFactory adapterFactory,
            IQueueAdapter queueAdapter,
            PersistentStreamOptions options)
        {
            IStreamQueueBalancer queueBalancer = CreateQueueBalancer(options, streamProviderName);
            var managerId = GrainId.NewSystemTargetGrainIdByTypeCode(Constants.PULLING_AGENTS_MANAGER_SYSTEM_TARGET_TYPE_CODE);
            var manager   = new PersistentStreamPullingManager(managerId, streamProviderName, this, this.PubSub(options.PubSubType), adapterFactory, queueBalancer, options, this.loggerFactory);

            this.RegisterSystemTarget(manager);
            // Init the manager only after it was registered locally.
            var pullingAgentManager = manager.AsReference <IPersistentStreamPullingManager>();
            // Need to call it as a grain reference though.
            await pullingAgentManager.Initialize(queueAdapter.AsImmutable());

            return(pullingAgentManager);
        }
Example #4
0
 private IStreamQueueBalancer CreateQueueBalancer(PersistentStreamOptions options, string streamProviderName)
 {
     //default type is ConsistentRingBalancer
     if (options.BalancerType == null)
     {
         options.BalancerType = StreamQueueBalancerType.ConsistentRingBalancer;
     }
     try
     {
         var balancer = this.ServiceProvider.GetRequiredService(options.BalancerType) as IStreamQueueBalancer;
         if (balancer == null)
         {
             throw new ArgumentOutOfRangeException("balancerType", $"Configured BalancerType isn't a type which implements IStreamQueueBalancer. BalancerType: {options.BalancerType}, StreamProvider: {streamProviderName}");
         }
         return(balancer);
     }
     catch (Exception e)
     {
         string error = $"Unsupported balancerType for stream provider. BalancerType: {options.BalancerType}, StreamProvider: {streamProviderName}, Exception: {e}";
         throw new ArgumentOutOfRangeException("balancerType", error);
     }
 }
        internal PersistentStreamPullingAgent(
            GrainId id,
            string strProviderName,
            IStreamProviderRuntime runtime,
            ILoggerFactory loggerFactory,
            IStreamPubSub streamPubSub,
            QueueId queueId,
            PersistentStreamOptions options)
            : base(id, runtime.ExecutingSiloAddress, true, loggerFactory)
        {
            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.options       = options;
            numMessages        = 0;

            logger = runtime.ServiceProvider.GetRequiredService <ILoggerFactory>().CreateLogger($"{this.GetType().Namespace}.{((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);
        }