public void WhenReferencingAType_AndTypeIsInAppDomain_ReturnThatType() { var requiredTypeString = typeof(SomePlainType).FullName; var result = new EventTypeResolver().Resolve(requiredTypeString); result.Should().Be <SomePlainType>(); }
public EPModuleVariableInitServicesImpl( VariableCollector variableCollector, EventTypeResolver eventTypeResolver) { VariableCollector = variableCollector; EventTypeResolver = eventTypeResolver; }
public FragmentEventType GetFragmentType(string property) { lock (this) { var pair = propertyFragmentTypes.Get(property); if (pair == null) { if (propertyFragmentTypes.ContainsKey(property)) { return null; } return DoResolveFragmentType(property); } // if a type is assigned, use that if (pair.Second != null) { return pair.Second; } // resolve event type var existingType = EventTypeResolver.GetTypeByName(pair.First.OptionalFragmentTypeName); if (!(existingType is BaseConfigurableEventType)) { Log.Warn( "Type configured for fragment event property '" + property + "' by name '" + pair.First + "' could not be found"); return null; } var fragmentType = new FragmentEventType(existingType, pair.First.IsFragmentArray, false); pair.Second = fragmentType; return fragmentType; } }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { var eventTypeResolver = new EventTypeResolver(); var viewRepo = new CosmosDBViewRepository(_viewsEndpointUri, _viewsAuthKey, _viewsDatabase, _viewsContainer); var projectionEngine = new CosmosDBProjectionEngine( eventTypeResolver, viewRepo, _processorName, _eventsEndpointUri, _eventsAuthKey, _eventsDatabase, _leasesEndpointUri, _leasesAuthKey, _leasesDatabase, _eventsContainer, _leasesContainer, _startDateTimeUtcEpochSeconds ); projectionEngine.RegisterProjection(new OrderProjection()); projectionEngine.RegisterProjection(new PendingOrdersProjection()); projectionEngine.RegisterProjection(new CustomerProjection()); projectionEngine.RegisterProjection(new AllCustomersProjection()); var serviceName = "ProjectionWorkerService"; await projectionEngine.StartAsync(serviceName); _logger.LogInformation($"{serviceName} running at: {DateTimeOffset.Now}"); await Task.Delay(-1, stoppingToken); } }
public EPModuleNamedWindowInitServicesImpl( NamedWindowCollector namedWindowCollector, EventTypeResolver eventTypeResolver) { NamedWindowCollector = namedWindowCollector; EventTypeResolver = eventTypeResolver; }
public EPModuleTableInitServicesImpl( TableCollector namedWindowCollector, EventTypeResolver eventTypeResolver) { TableCollector = namedWindowCollector; EventTypeResolver = eventTypeResolver; }
public EPStatementInitServicesImpl( String statementName, IDictionary<StatementProperty, Object> statementProperties, Attribute[] annotations, String deploymentId, EventTypeResolver eventTypeResolver, FilterSpecActivatableRegistry filterSpecActivatableRegistry, FilterSharedBoolExprRegistery filterSharedBoolExprRegistery, FilterSharedLookupableRegistery filterSharedLookupableRegistery, ModuleIncidentals moduleIncidentals, bool recovery, StatementResourceService statementResourceService, StatementResultService statementResultService, EPServicesContext servicesContext) { StatementName = statementName; StatementProperties = statementProperties; Annotations = annotations; DeploymentId = deploymentId; EventTypeResolver = eventTypeResolver; FilterSpecActivatableRegistry = filterSpecActivatableRegistry; FilterSharedBoolExprRegistery = filterSharedBoolExprRegistery; FilterSharedLookupableRegistery = filterSharedLookupableRegistery; ModuleIncidentals = moduleIncidentals; IsRecovery = recovery; StatementResourceService = statementResourceService; StatementResultService = statementResultService; ServicesContext = servicesContext; }
public EPModuleContextInitServicesImpl( ContextCollector contextCollector, EventTypeResolver eventTypeResolver) { ContextCollector = contextCollector; EventTypeResolver = eventTypeResolver; }
public EPModuleEventTypeInitServicesImpl( EventTypeCollector eventTypeCollector, EventTypeResolver eventTypeByMetaResolver) { EventTypeCollector = eventTypeCollector; EventTypeResolver = eventTypeByMetaResolver; }
public void WhenReferencingAType_AndMappedTypeExistsWithMultipleMappings_ReturnTheMappedType() { var result1 = new EventTypeResolver().Resolve("Some multi bound type 1"); var result2 = new EventTypeResolver().Resolve("Some multi bound type 2"); var result3 = new EventTypeResolver().Resolve("Some multi bound type 3"); result1.Should().Be <SomeMultiBoundType>(); result2.Should().Be <SomeMultiBoundType>(); result3.Should().Be <SomeMultiBoundType>(); }
public OutboxProcessorConfigurator UseEventsInAssemblies(params Assembly[] assemblies) { var eventTypeResolver = new EventTypeResolver(); if (assemblies.Length > 0) { foreach (var assembly in assemblies) { eventTypeResolver.AddTypesFromAssembly(assembly); } } services.AddSingleton <IEventTypeResolver>(eventTypeResolver); return(this); }
private static void ConfigurePersistence(HostBuilderContext hostContext, IServiceCollection services) { services.AddSingleton(sp => { var connectionString = hostContext.Configuration.GetConnectionString("DefaultConnection"); var connection = EventStoreConnection.Create(new Uri(connectionString)); connection.ConnectAsync().Wait(); return(connection); }); services.AddSingleton <IEventTypeResolver>(s => { var resolver = new EventTypeResolver(); resolver.AddTypesFromAssembly(typeof(OrderPlaced).Assembly); return(resolver); }); services.AddSingleton(typeof(IRepository <,>), typeof(EventStoreRepository <,>)); services.AddSingleton <IOrderRepository, OrderRepository>(); }
public async Task RegisterProjectionsAsync() { var eventTypeResolver = new EventTypeResolver(); var orderViewRepo = new CosmosDBViewRepository( _testConfig.OrderViewsEndpointUri, _testConfig.OrderViewsAuthKey, _testConfig.OrderViewsDatabase, _testConfig.OrderViewsContainer); var orderProcessorName = "OrderUnitTestsProcessor"; var orderProjectionEngine = new CosmosDBProjectionEngine(eventTypeResolver, orderViewRepo, orderProcessorName, _testConfig.EventsEndpointUri, _testConfig.EventsAuthKey, _testConfig.EventsDatabase, _testConfig.LeasesEndpointUri, _testConfig.LeasesAuthKey, _testConfig.LeasesDatabase, _testConfig.EventContainer, _testConfig.LeasesContainer, _testConfig.StartTimeEpoch); orderProjectionEngine.RegisterProjection(new OrderProjection()); orderProjectionEngine.RegisterProjection(new PendingOrdersProjection()); await orderProjectionEngine.StartAsync("UnitTests"); // --- var customerViewRepo = new CosmosDBViewRepository( _testConfig.CustomerViewsEndpointUri, _testConfig.CustomerViewsAuthKey, _testConfig.CustomerViewsDatabase, _testConfig.CustomerViewsContainer); var customerProcessorName = "CustomerUnitTestsProcessor"; var customerProjectionEngine = new CosmosDBProjectionEngine(eventTypeResolver, customerViewRepo, customerProcessorName, _testConfig.EventsEndpointUri, _testConfig.EventsAuthKey, _testConfig.EventsDatabase, _testConfig.LeasesEndpointUri, _testConfig.LeasesAuthKey, _testConfig.LeasesDatabase, _testConfig.EventContainer, _testConfig.LeasesContainer, _testConfig.StartTimeEpoch); customerProjectionEngine.RegisterProjection(new CustomerProjection()); customerProjectionEngine.RegisterProjection(new AllCustomersProjection()); await customerProjectionEngine.StartAsync("UnitTests"); await Task.Delay(-1); }
public static void Main(string[] args) { var quitEvent = new ManualResetEvent(false); Console.CancelKeyPress += (sender, eArgs) => { quitEvent.Set(); eArgs.Cancel = true; Console.WriteLine("Application is shutting down..."); }; var builder = new ConfigurationBuilder().AddEnvironmentVariables(); var configuration = builder.Build(); var options = EventStoreOptions.Create(configuration); var typeResolver = new EventTypeResolver(ReflectionHelper.MessagesAssembly); var eventBus = EventStoreConnectionFactory.Create(options.ConnectionString); eventBus.Subscribe( typeResolver, options.Subscription, msg => { if (msg is QuestionRightAnsweredEvent rightEvent) { Console.WriteLine($"Type:{rightEvent.GetType().Name}, OptionId:{rightEvent.OptionId}, QuestionId: {rightEvent.QuestionId}"); } if (msg is QuestionWrongAnsweredEvent wrongEvent) { Console.WriteLine($"Type:{wrongEvent.GetType().Name}, OptionId:{wrongEvent.OptionId}, QuestionId: {wrongEvent.QuestionId}"); } }) .Wait(); Console.Write("Application started. Press Ctrl+C to shut down."); quitEvent.WaitOne(); }
private OrderSystemRepository GetOrderSystemRepository() { var eventTypeResolver = new EventTypeResolver(); if (_testConfig.UseInMemoryEventStore) { var eventStore = new InMemoryEventStore( eventTypeResolver, new Dictionary <string, List <string> >()); return(new OrderSystemRepository(eventStore, null)); } else { var eventStore = new CosmosDBEventStore( eventTypeResolver, _testConfig.EventsEndpointUri, _testConfig.EventsAuthKey, _testConfig.EventsDatabase, _testConfig.EventContainer); var snapshotStore = new CosmosSnapshotStore(_testConfig.SnapshotsEndpointUri, _testConfig.SnapshotsAuthKey, _testConfig.SnapshotsDatabase, _testConfig.SnapshotsContainer); return(new OrderSystemRepository(eventStore, snapshotStore)); } }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider, ILoggerFactory loggerFactory, IEventStoreConnection eventBus, EventTypeResolver typeResolver, WebSocketHandler handler) { app.UseCors("CorsPolicy"); app.UseWebSockets(); app.MapWebSocketManager("/ws", handler); var logger = loggerFactory.CreateLogger <Startup>(); Policy.Handle <Exception>() .WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))) .ExecuteAsync(async() => await eventBus.StartSubscription(EventStoreOptions, typeResolver, async(message) => { logger.LogInformation(message.ToString()); await handler.SendMessageToAllAsync(message); })) .Wait(); }
public void WhenReferencingAType_AndTypeIsNotInAppDomainButAMappedTypeExist_ReturnTheMappedType() { var result = new EventTypeResolver().Resolve("Some arbitrarily bound type"); result.Should().Be <SomeBoundType>(); }
private static StatementLightweight InitStatement( bool recovery, string moduleName, StatementProvider statementProvider, string deploymentId, int statementId, EventTypeResolver eventTypeResolver, ModuleIncidentals moduleIncidentals, StatementNameRuntimeOption statementNameResolverRuntime, StatementUserObjectRuntimeOption userObjectResolverRuntime, ClassLoader moduleClassLoader, EPServicesContext services) { var informationals = statementProvider.Informationals; // set instrumentation unless already provided if (informationals.InstrumentationProvider == null) { informationals.InstrumentationProvider = InstrumentationDefault.INSTANCE; } var statementResultService = new StatementResultServiceImpl(informationals, services); FilterSharedLookupableRegistery filterSharedLookupableRegistery = new ProxyFilterSharedLookupableRegistery() { ProcRegisterLookupable = ( eventTypeX, lookupable) => { services.FilterSharedLookupableRepository.RegisterLookupable(statementId, eventTypeX, lookupable); }, }; FilterSharedBoolExprRegistery filterSharedBoolExprRegistery = new ProxyFilterSharedBoolExprRegistery() { ProcRegisterBoolExpr = (node) => { services.FilterSharedBoolExprRepository.RegisterBoolExpr(statementId, node); }, }; IDictionary <int, FilterSpecActivatable> filterSpecActivatables = new Dictionary <int, FilterSpecActivatable>(); FilterSpecActivatableRegistry filterSpecActivatableRegistry = new ProxyFilterSpecActivatableRegistry() { ProcRegister = (filterSpecActivatable) => { filterSpecActivatables.Put(filterSpecActivatable.FilterCallbackId, filterSpecActivatable); }, }; var contextPartitioned = informationals.OptionalContextName != null; var statementResourceService = new StatementResourceService(contextPartitioned); // determine statement name var statementName = informationals.StatementNameCompileTime; if (statementNameResolverRuntime != null) { string statementNameAssigned = statementNameResolverRuntime.Invoke( new StatementNameRuntimeContext( deploymentId, statementName, statementId, (string)informationals.Properties.Get(StatementProperty.EPL), informationals.Annotations)); if (statementNameAssigned != null) { statementName = statementNameAssigned; } } statementName = statementName.Trim(); var epInitServices = new EPStatementInitServicesImpl( statementName, informationals.Properties, informationals.Annotations, deploymentId, eventTypeResolver, filterSpecActivatableRegistry, filterSharedBoolExprRegistery, filterSharedLookupableRegistery, moduleIncidentals, recovery, statementResourceService, statementResultService, services); if (!services.EpServicesHA.RuntimeExtensionServices.IsHAEnabled) { statementProvider.Initialize(epInitServices); } else { // for HA we set the context classloader as state may be loaded considering the module provider's classloader // - NEsper doesn't support HA like this, and we wouldn't want to deliver this information in // - this manner. An alternative delivery mechanism must be established to carry the information // - without relying on the "current" thread to carry that detail. // ClassLoader originalClassLoader = Thread.CurrentThread().ContextClassLoader; // try { // Thread.CurrentThread().ContextClassLoader = moduleClassLoader; // statementProvider.Initialize(epInitServices); // } // finally { // Thread.CurrentThread().ContextClassLoader = originalClassLoader; // } } var multiMatchHandler = services.MultiMatchHandlerFactory.Make(informationals.HasSubquery, informationals.IsNeedDedup); var stmtMetric = services.MetricReportingService.GetStatementHandle(statementId, deploymentId, statementName); var optionalEPL = (string)informationals.Properties.Get(StatementProperty.EPL); InsertIntoLatchFactory insertIntoFrontLatchFactory = null; InsertIntoLatchFactory insertIntoBackLatchFactory = null; if (informationals.InsertIntoLatchName != null) { var latchFactoryNameBack = "insert_stream_B_" + informationals.InsertIntoLatchName + "_" + statementName; var latchFactoryNameFront = "insert_stream_F_" + informationals.InsertIntoLatchName + "_" + statementName; var msecTimeout = services.RuntimeSettingsService.ConfigurationRuntime.Threading.InsertIntoDispatchTimeout; var locking = services.RuntimeSettingsService.ConfigurationRuntime.Threading.InsertIntoDispatchLocking; var latchFactoryFront = new InsertIntoLatchFactory( latchFactoryNameFront, informationals.IsStateless, msecTimeout, locking, services.TimeSourceService); var latchFactoryBack = new InsertIntoLatchFactory( latchFactoryNameBack, informationals.IsStateless, msecTimeout, locking, services.TimeSourceService); insertIntoFrontLatchFactory = latchFactoryFront; insertIntoBackLatchFactory = latchFactoryBack; } var statementHandle = new EPStatementHandle( statementName, deploymentId, statementId, optionalEPL, informationals.Priority, informationals.IsPreemptive, informationals.IsCanSelfJoin, multiMatchHandler, informationals.HasVariables, informationals.HasTableAccess, stmtMetric, insertIntoFrontLatchFactory, insertIntoBackLatchFactory); // determine context StatementAIResourceRegistry statementAgentInstanceRegistry = null; ContextRuntimeDescriptor contextRuntimeDescriptor = null; var optionalContextName = informationals.OptionalContextName; if (optionalContextName != null) { var contextDeploymentId = ContextDeployTimeResolver.ResolveContextDeploymentId( informationals.OptionalContextModuleName, informationals.OptionalContextVisibility, optionalContextName, deploymentId, services.ContextPathRegistry); var contextManager = services.ContextManagementService.GetContextManager(contextDeploymentId, optionalContextName); contextRuntimeDescriptor = contextManager.ContextRuntimeDescriptor; var registryRequirements = statementProvider.StatementAIFactoryProvider.Factory.RegistryRequirements; statementAgentInstanceRegistry = contextManager.AllocateAgentInstanceResourceRegistry(registryRequirements); } var statementCPCacheService = new StatementCPCacheService( contextPartitioned, statementResourceService, statementAgentInstanceRegistry); var eventType = statementProvider.StatementAIFactoryProvider.Factory.StatementEventType; var configurationThreading = services.RuntimeSettingsService.ConfigurationRuntime.Threading; var preserveDispatchOrder = configurationThreading.IsListenerDispatchPreserveOrder && !informationals.IsStateless; var isSpinLocks = configurationThreading.ListenerDispatchLocking == Locking.SPIN; var msecBlockingTimeout = configurationThreading.ListenerDispatchTimeout; UpdateDispatchViewBase dispatchChildView; if (preserveDispatchOrder) { if (isSpinLocks) { dispatchChildView = new UpdateDispatchViewBlockingSpin( eventType, statementResultService, services.DispatchService, msecBlockingTimeout, services.TimeSourceService); } else { dispatchChildView = new UpdateDispatchViewBlockingWait(eventType, statementResultService, services.DispatchService, msecBlockingTimeout); } } else { dispatchChildView = new UpdateDispatchViewNonBlocking(eventType, statementResultService, services.DispatchService); } var countSubexpressions = services.ConfigSnapshot.Runtime.Patterns.MaxSubexpressions != null; PatternSubexpressionPoolStmtSvc patternSubexpressionPoolStmtSvc = null; if (countSubexpressions) { var stmtCounter = new PatternSubexpressionPoolStmtHandler(); patternSubexpressionPoolStmtSvc = new PatternSubexpressionPoolStmtSvc(services.PatternSubexpressionPoolRuntimeSvc, stmtCounter); services.PatternSubexpressionPoolRuntimeSvc.AddPatternContext(statementId, statementName, stmtCounter); } var countMatchRecogStates = services.ConfigSnapshot.Runtime.MatchRecognize.MaxStates != null; RowRecogStatePoolStmtSvc rowRecogStatePoolStmtSvc = null; if (countMatchRecogStates && informationals.HasMatchRecognize) { var stmtCounter = new RowRecogStatePoolStmtHandler(); rowRecogStatePoolStmtSvc = new RowRecogStatePoolStmtSvc(services.RowRecogStatePoolEngineSvc, stmtCounter); services.RowRecogStatePoolEngineSvc.AddPatternContext(new DeploymentIdNamePair(deploymentId, statementName), stmtCounter); } // get user object for runtime object userObjectRuntime = null; if (userObjectResolverRuntime != null) { userObjectRuntime = userObjectResolverRuntime.GetUserObject( new StatementUserObjectRuntimeContext( deploymentId, statementName, statementId, (string)informationals.Properties.Get(StatementProperty.EPL), informationals.Annotations)); } var statementContext = new StatementContext( services.Container, contextRuntimeDescriptor, deploymentId, statementId, statementName, moduleName, informationals, userObjectRuntime, services.StatementContextRuntimeServices, statementHandle, filterSpecActivatables, patternSubexpressionPoolStmtSvc, rowRecogStatePoolStmtSvc, new ScheduleBucket(statementId), statementAgentInstanceRegistry, statementCPCacheService, statementProvider.StatementAIFactoryProvider, statementResultService, dispatchChildView, services.FilterService, services.SchedulingService, services.InternalEventRouteDest ); foreach (var readyCallback in epInitServices.ReadyCallbacks) { readyCallback.Ready(statementContext, moduleIncidentals, recovery); } return(new StatementLightweight(statementProvider, informationals, statementResultService, statementContext)); }
public static async Task StartSubscription(this IEventStoreConnection eventBus, EventStoreOptions options, EventTypeResolver typeResolver, Func <object, Task> messageSender) { await CreateSubscription(eventBus, options); await eventBus.Subscribe(typeResolver, options.Subscription, async msg => await messageSender(msg)); }
public Repository(IEventStoreConnection eventStoreConnection, EventTypeResolver eventTypeResolver) { _eventStoreConnection = eventStoreConnection; _eventTypeResolver = eventTypeResolver; }
public void WhenReferencingAType_AndTypeIsNotInAppDomainButADefaultEventMappedTypeExists_ReturnTheMappedType() { var result = new EventTypeResolver().Resolve("Some Default Event Type"); result.Should().Be <SomeDefaultEventBoundType>(); }