public IStoreBuilder <ITimestampedKeyValueStore <K, V> > Materialize()
        {
            IKeyValueBytesStoreSupplier supplier = (IKeyValueBytesStoreSupplier)materialized.StoreSupplier;

            if (supplier == null)
            {
                // TODO : RocksDB
                //supplier = Stores.persistentTimestampedKeyValueStore(name);
                supplier = new InMemoryKeyValueBytesStoreSupplier(materialized.StoreName);
            }

            IStoreBuilder <ITimestampedKeyValueStore <K, V> > builder = Stores.TimestampedKeyValueStoreBuilder(
                supplier,
                materialized.KeySerdes,
                materialized.ValueSerdes);

            if (materialized.LoggingEnabled)
            {
                builder.WithLoggingEnabled(materialized.TopicConfig);
            }
            else
            {
                builder.WithLoggingDisabled();
            }

            if (materialized.CachingEnabled)
            {
                builder.WithCachingEnabled();
            }

            return(builder);
        }
        internal IKTable <KR, VR> BuildWindow <KR, VR>(
            string functionName,
            IStoreBuilder <ITimestampedWindowStore <K, VR> > storeBuilder,
            IKStreamAggProcessorSupplier <K, KR, V, VR> aggregateSupplier,
            ISerDes <KR> keySerdes,
            ISerDes <VR> valueSerdes)
        {
            // if repartition required TODO
            // ELSE
            StatefulProcessorNode <K, V, ITimestampedWindowStore <K, VR> > statefulProcessorNode =
                new StatefulProcessorNode <K, V, ITimestampedWindowStore <K, VR> >(
                    functionName,
                    new ProcessorParameters <K, V>(aggregateSupplier, functionName),
                    storeBuilder);

            builder.AddGraphNode(node, statefulProcessorNode);

            return(new KTableGrouped <K, KR, V, VR>(functionName,
                                                    keySerdes,
                                                    valueSerdes,
                                                    sourceNodes,
                                                    aggregateSupplier,
                                                    statefulProcessorNode,
                                                    builder));
        }
Example #3
0
        public void Configure(IComponentsApplicationBuilder app, IStoreBuilder <AppState> RealmStoreBuilder)
        {
            RealmStoreBuilder.UseRealmAsync <AppState>();

            RealmStoreBuilder.UseRealmReduxDevTools <AppState>(new System.Type[]
            {
                typeof(Redux.Actions.Counter.Dispose)
            });

            //app.Map("/services", builder => builder.Run(async context =>
            //{
            //var sb = new StringBuilder();
            //sb.Append("<h1>All Services</h1>");
            //sb.Append("<table><thead>");
            //sb.Append("<tr><th>Type</th><th>Lifetime</th><th>Instance</th></tr>");
            //sb.Append("</thead><tbody>");
            Console.WriteLine("Test");
            foreach (var svc in _services)
            {
                Console.WriteLine($"{svc.ServiceType.FullName} = {svc.ImplementationType?.FullName}");
            }
            //sb.Append("</tbody></table>");
            //await context.Response.WriteAsync(sb.ToString());
            //}));

            app.AddComponent <App>("app");
        }
        public void ReplicateQueuedAssociations()
        {
            QueuedInProcessAssociationReplicator.Tracer.TraceDebug((long)this.GetHashCode(), "MailboxTaskProcessor.ReplicateQueuedAssociations: Processing associations.");
            ADUser mailboxAdUser = this.mailbox.FindAdUser();
            IDiagnosticsFrameFactory <IExtensibleLogger, IMailboxAssociationPerformanceTracker> diagnosticsFrameFactory = this.diagnosticsFrameFactoryCreator();
            IMailboxAssociationPerformanceTracker performanceTracker = diagnosticsFrameFactory.CreatePerformanceTracker(null);
            IExtensibleLogger      logger     = diagnosticsFrameFactory.CreateLogger(mailboxAdUser.ExchangeGuid, mailboxAdUser.OrganizationId);
            IAssociationReplicator replicator = this.immediateReplicatorCreator(logger, performanceTracker);

            using (MailboxAssociationDiagnosticsFrameFactory.Default.CreateDiagnosticsFrame("QueuedInProcessAssociationReplicator", "ReplicateAssociations", logger, performanceTracker))
            {
                bool inProcessReplicationSucceeded = true;
                GroupMailboxAccessLayerHelper.ExecuteOperationWithRetry(logger, "QueuedInProcessAssociationReplicator.ReplicateAssociations", delegate
                {
                    IStoreBuilder storeBuilder = this.storeBuilderCreator(logger, this.clientInfoString);
                    using (IAssociationStore associationStore = storeBuilder.Create(this.mailbox, performanceTracker))
                    {
                        QueuedInProcessAssociationReplicator.Tracer.TraceDebug <string>((long)this.GetHashCode(), "QueuedInProcessAssociationReplicator.ReplicateAssociationsImplementation: Created store provider. Mailbox={0}.", mailboxAdUser.ExternalDirectoryObjectId);
                        UserAssociationAdaptor masterAdaptor = new UserAssociationAdaptor(associationStore, this.adSession, this.mailbox);
                        while (this.pendingAssociations.Count > 0)
                        {
                            MailboxAssociation association = this.pendingAssociations.Dequeue();
                            inProcessReplicationSucceeded &= this.ReplicateSingleAssociation(replicator, masterAdaptor, association);
                        }
                        if (!inProcessReplicationSucceeded)
                        {
                            IReplicationAssistantInvoker replicationAssistantInvoker = this.replicationAssistantInvokerCreator(logger, this.replicationServerFqdn);
                            replicationAssistantInvoker.Invoke("QueuedInProcessAssociationReplicatorRpcReplication", masterAdaptor, new MailboxAssociation[0]);
                        }
                    }
                }, new Predicate <Exception>(GrayException.IsGrayException));
            }
            QueuedInProcessAssociationReplicator.Tracer.TraceDebug((long)this.GetHashCode(), "MailboxTaskProcessor.SendNotificationImplementation: Task completed.");
        }
Example #5
0
        internal void AddGlobalStore <K, V, S>(string topicName,
                                               IStoreBuilder <S> storeBuilder,
                                               string sourceName,
                                               ConsumedInternal <K, V> consumed,
                                               ProcessorParameters <K, V> processorParameters) where S : IStateStore
        {
            string processorName = processorParameters.ProcessorName;

            ValidateGlobalStoreArguments(sourceName, processorName, storeBuilder.Name, storeBuilder.LoggingEnabled);
            ValidateTopicNotAlreadyRegistered(topicName);

            var predecessors = new[] { sourceName };

            var nodeFactory = new ProcessorNodeFactory <K, V>(processorName, predecessors, processorParameters.Processor);

            globalTopics.Add(topicName);
            nodeFactories.Add(sourceName, new SourceNodeFactory <K, V>(sourceName, topicName, consumed.TimestampExtractor, consumed.KeySerdes, consumed.ValueSerdes));

            // TODO: ?
            // nodeToSourceTopics.put(sourceName, Arrays.asList(topics));
            nodeGrouper.Add(sourceName);
            nodeFactory.AddStateStore(storeBuilder.Name);
            nodeFactories.Add(processorName, nodeFactory);
            nodeGrouper.Add(processorName);
            nodeGrouper.Unite(processorName, predecessors);
            globalStateBuilders.Add(storeBuilder.Name, storeBuilder);
            ConnectSourceStoreAndTopic(storeBuilder.Name, topicName);
            nodeGroups = null;
        }
 public static IStoreBuilder <TState> Use <TState>(this IStoreBuilder <TState> builder, Func <Store <TState>, Dispatcher <TState>, Dispatcher <TState> > middleware)
 {
     return(builder.Use((Dispatcher <TState> next) =>
     {
         Store <TState> store = builder.ServiceProvider.GetService(typeof(Store <TState>)) as Store <TState>;
         return middleware(store, next);
     }));
 }
 internal GroupMailboxAccessLayer(IRecipientSession adSession, IStoreBuilder storeProviderBuilder, IMailboxAssociationPerformanceTracker performanceTracker, IExtensibleLogger logger, string clientString)
 {
     ArgumentValidator.ThrowIfNull("adSession", adSession);
     ArgumentValidator.ThrowIfNull("storeProviderBuilder", storeProviderBuilder);
     ArgumentValidator.ThrowIfNull("performanceTracker", performanceTracker);
     ArgumentValidator.ThrowIfNull("logger", logger);
     this.adSession            = adSession;
     this.storeProviderBuilder = storeProviderBuilder;
     this.PerformanceTracker   = performanceTracker;
     this.Logger = logger;
     this.mailboxCollectionBuilder = new MailboxCollectionBuilder(adSession);
     this.clientString             = clientString;
 }
 public StreamStreamJoinNode(
     string name,
     IValueJoiner <V1, V2, VR> valueJoiner,
     ProcessorParameters <K, V1> joinLeftParams,
     ProcessorParameters <K, V2> joinRightParams,
     ProcessorParameters <K, VR> joinMergeParams,
     ProcessorParameters <K, V1> windowedLeftParams,
     ProcessorParameters <K, V2> windowedRightParams,
     IStoreBuilder <IWindowStore <K, V1> > windowedLeftStoreBuilder,
     IStoreBuilder <IWindowStore <K, V2> > windowedRightStoreBuilder)
     : base(name, valueJoiner, joinLeftParams, joinRightParams, joinMergeParams, null, null)
 {
     this.windowedLeftParams        = windowedLeftParams;
     this.windowedRightParams       = windowedRightParams;
     this.windowedLeftStoreBuilder  = windowedLeftStoreBuilder;
     this.windowedRightStoreBuilder = windowedRightStoreBuilder;
 }
Example #9
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IStoreBuilder <AppState> RealmStoreBuilder, IServiceProvider serviceProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            RealmStoreBuilder.UseRealmAsync <AppState>();

            app.Map("/services", builder => builder.Run(async context =>
            {
                var sb = new StringBuilder();
                sb.Append("<h1>All Services</h1>");
                sb.Append("<table><thead>");
                sb.Append("<tr><th>Type</th><th>Lifetime</th><th>Instance</th></tr>");
                sb.Append("</thead><tbody>");
                foreach (var svc in _services)
                {
                    sb.Append("<tr>");
                    sb.Append($"<td>{svc.ServiceType.FullName}</td>");
                    sb.Append($"<td>{svc.Lifetime}</td>");
                    sb.Append($"<td>{svc.ImplementationType?.FullName}</td>");
                    sb.Append("</tr>");
                }
                sb.Append("</tbody></table>");
                await context.Response.WriteAsync(sb.ToString());
            }));

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapBlazorHub();
                endpoints.MapFallbackToPage("/_Host");
            });
        }
Example #10
0
        internal void AddStateStore <S>(IStoreBuilder <S> storeBuilder, bool allowOverride, params string[] processorNames)
            where S : IStateStore
        {
            if (!allowOverride && stateFactories.ContainsKey(storeBuilder.Name))
            {
                throw new TopologyException("StateStore " + storeBuilder.Name + " is already added.");
            }

            stateFactories.Add(storeBuilder.Name, new StateStoreFactory(storeBuilder));

            if (processorNames != null)
            {
                foreach (var processorName in processorNames)
                {
                    ConnectProcessorAndStateStore(processorName, storeBuilder.Name);
                }
            }
        }
        public static IStoreBuilder <TState> UseMiddleware <TState>(this IStoreBuilder <TState> builder, Type middleware, params object[] args)
        {
            IServiceProvider serviceProvider = builder.ServiceProvider;
            Store <TState>   store           = builder.ServiceProvider.GetService(typeof(Store <TState>)) as Store <TState>;

            return(builder.Use((Dispatcher <TState> next) =>
            {
                MethodInfo[] methods = middleware.GetMethods(BindingFlags.Instance | BindingFlags.Public);
                MethodInfo[] invokeMethods = methods.Where(m =>
                                                           string.Equals(m.Name, InvokeMethodName, StringComparison.Ordinal)
                                                           ).ToArray();

                if (invokeMethods.Length != 1)
                {
                    throw new InvalidOperationException("Middleware should have only one Invoke method.");
                }

                MethodInfo methodinfo = invokeMethods[0];
                if (!typeof(TState).IsAssignableFrom(methodinfo.ReturnType))
                {
                    throw new InvalidOperationException($"Middleware should return type {typeof(TState)}");
                }

                ParameterInfo[] parameters = methodinfo.GetParameters();
                if (parameters.Length != 1 || parameters[0].ParameterType != typeof(IRealmAction))
                {
                    throw new InvalidOperationException("Middleware Invoke should accept one argument of type IRealmAction");
                }

                object[] ctorArgs = new object[args.Length + 2];
                ctorArgs[0] = store;
                ctorArgs[1] = next;
                Array.Copy(args, 0, ctorArgs, 2, args.Length);
                var instance = ActivatorUtilities.CreateInstance(serviceProvider, middleware, ctorArgs);
                //if (parameters.Length == 1)
                //{
                return (Dispatcher <TState>)methodinfo.CreateDelegate(typeof(Dispatcher <TState>), instance);
                //}
            }));
        }
 public static IStoreBuilder <TState> Use <TState>(this IStoreBuilder <TState> builder, Func <Dispatcher <TState>, Dispatcher <TState> > middleware)
 {
     builder.Middleware?.Add(middleware);
     return(builder.Build());
 }
Example #13
0
 IStoreBuilder IMergeStoreBuilder.MergeWith(IStoreBuilder builder)
 {
     return(this);
 }
        public static Dispatcher <TState> GetInitialStoreDispatch <TState>(this IStoreBuilder <TState> builder)
        {
            Store <TState> store = builder.ServiceProvider.GetService(typeof(Store <TState>)) as Store <TState>;

            return(store.InitialDispatch);
        }
 public static IStoreBuilder <TState> UseRealmAsync <TState>(this IStoreBuilder <TState> builder)
 {
     return(builder.UseMiddleware <TState, HandleAsyncActions <TState> >());
 }
 public static IStoreBuilder <TState> UseMiddleware <TState, TMiddleware>(this IStoreBuilder <TState> builder, params object[] args)
 {
     return(builder.UseMiddleware(typeof(TMiddleware), args));
 }
 public static void UseRealmReduxDevTools <TState>(this IStoreBuilder <TState> builder)
 {
     builder.UseMiddleware <TState, HandleReduxDevTools <TState> >(builder.ServiceProvider);
 }
 public static void UseRealmReduxDevTools <TState>(this IStoreBuilder <TState> builder, IServiceProvider serviceProvider, Type[] actionsToIgnore)
 {
     builder.UseMiddleware <TState, HandleReduxDevTools <TState> >(serviceProvider, actionsToIgnore);
 }
        public static void SetStoreDispatch <TState>(this IStoreBuilder <TState> builder, Dispatcher <TState> dispatcher)
        {
            Store <TState> store = builder.ServiceProvider.GetService(typeof(Store <TState>)) as Store <TState>;

            store._dispatch = dispatcher;
        }
Example #20
0
 public static IStoreBuilder <TState> UseDummy <TState>(this IStoreBuilder <TState> store)
 {
     return(store.UseMiddleware <DummyMiddleware <TState> >());
 }
Example #21
0
 internal void AddStateStore <S>(IStoreBuilder <S> storeBuilder, params string[] processorNames)
     where S : IStateStore
 {
     AddStateStore <S>(storeBuilder, false, processorNames);
 }
Example #22
0
 public static IStoreBuilder <TState> UseLogger <TState>(this IStoreBuilder <TState> store, LoggerOptions options)
 {
     return(store.UseMiddleware <LoggerMiddleware <TState> >(options));
 }
 /// <summary>
 /// Create a node representing a stateful processor,
 /// where the store needs to be built and registered as part of building this node.
 /// </summary>
 /// <param name="nameNode"></param>
 /// <param name="parameters"></param>
 /// <param name="storeBuilder"></param>
 public StatefulProcessorNode(string nameNode, ProcessorParameters <K, V> parameters, IStoreBuilder <S> storeBuilder)
     : base(nameNode, parameters)
 {
     storeNames        = null;
     this.storeBuilder = storeBuilder;
 }