/// <inheritdoc/> public override async Task Open(OpenTunnel request, IServerStreamWriter <CommittedEventStreamWithContext> responseStream, ServerCallContext context) { try { using (var tunnel = new QuantumTunnel(_serializer, responseStream, _logger, context.CancellationToken)) { var application = request.Application.To <Dolittle.Applications.Application>(); var boundedContext = request.BoundedContext.To <BoundedContext>(); var events = request .Events .Select(@event => @event.ToArtifact()) .ToArray(); var tenantOffsets = request.Offsets.ToTenantOffsets(); var subscription = new EventParticleSubscription(events); _logger.Information($"Opening up a quantum tunnel for bounded context '{boundedContext}' in application '{application}'"); var singularity = new Singularity(application, boundedContext, tunnel, subscription); _eventHorizon.GravitateTowards(singularity, tenantOffsets); tunnel.Collapsed += _ => _eventHorizon.Collapse(singularity); await tunnel.Open(request.Offsets.ToTenantOffsets()).ConfigureAwait(false); _logger.Information($"Quantum tunnel collapsed for bounded context '{boundedContext}' in application '{application}'"); } } catch (Exception ex) { _logger.Error(ex, "Problems opening tunnel"); } await Task.CompletedTask.ConfigureAwait(false); }
/// <summary> /// Initializes a new instance of <see cref="Singularity"/> /// </summary> /// <param name="application"><see cref="Application">Application</see> representing the singularity</param> /// <param name="boundedContext"><see cref="BoundedContext"/> representing the bounded context of the singularity</param> /// <param name="tunnel"><see cref="IQuantumTunnel"/> used to pass through to <see cref="Singularity"/></param> /// <param name="subscription"><see cref="EventParticleSubscription"/></param> public Singularity( Application application, BoundedContext boundedContext, IQuantumTunnel tunnel, EventParticleSubscription subscription) { _subscription = subscription; _tunnel = tunnel; Application = application; BoundedContext = boundedContext; }