private static IDisposable SetTarget(IProvidedMethodReference obj, InvocationStartRequest req) { var proto = ConvertToProtoStrict(obj); req.ProvidedMethod = proto; return(proto); }
private static ProvidedMethodReference ConvertToProtoStrict(IProvidedMethodReference obj) { var proto = ProvidedMethodReference.Rent(); proto.ProvidedService = ConvertToProtoStrict(obj.ProvidedService); proto.MethodId = obj.MethodId.ConvertToProtoStrict(); return(proto); }
private IInvocationStartRequested CreateInvocationTarget(IProvidedMethodReference reference, IClientConnection sourceConnection) { return(_protocolMessageFactory.CreateInvocationStartRequested( reference.ProvidedService.ServiceId, reference.MethodId, reference.ProvidedService.ServiceAlias, sourceConnection.Info.ApplicationId, sourceConnection.Id)); }
private async ValueTask <IAppConnection> ResolveTargetConnectionAsync( IProvidedMethodReference methodReference, IAppConnection source, IContextLinkageOptions contextLinkageOptions) { var method = _registryService.GetProvidedMethod(methodReference); var launchMode = GetLaunchMode(method); var appId = methodReference.ProvidedService.ApplicationId; if (methodReference.ProvidedService.ConnectionId.HasValue) { var connectionId = methodReference.ProvidedService.ConnectionId.Value; if (!_appLifecycleManager.TryGetOnlineConnection(connectionId, out var connection)) { throw new InvalidOperationException($"The requested app {appId} connection {connectionId} is not online"); } return(connection); } Task <ResolvedConnection> resolveTask; lock (_resolveConnectionSync) { if (launchMode != LaunchMode.MultiInstance) { var onlineConnections = _appLifecycleManager .GetOnlineConnections() .Where(x => x.Info.ApplicationId.Equals(appId) && !x.Id.Equals(source.Id)).ToArray(); if (_contextLinkageManager.IsContextShouldBeConsidered(contextLinkageOptions, source)) { onlineConnections = _contextLinkageManager .GetAppsInContexts(contextLinkageOptions, source, true) .Join(onlineConnections, x => x.ConnectionId.Value, y => y.Id, (x, y) => y) .ToArray(); } if (onlineConnections.Any()) { return(onlineConnections.First()); } } if (launchMode == LaunchMode.None || !_appLifecycleManager.CanBeLaunched(appId)) { throw new InvalidOperationException( $"The requested app {appId} is not online and cannot be launched"); } var resolveMode = ConvertToResolveMode(launchMode); resolveTask = _appLifecycleManager.LaunchAndConnectAsync(appId, resolveMode, source.Info); } var resolvedConnection = await resolveTask.ConfigureAwait(false); return(resolvedConnection.AppConnection); }
public IProvidedMethod GetProvidedMethod(IProvidedMethodReference reference) { _registryLock.EnterReadLock(); try { return(GetProvidedService(reference.ProvidedService).Methods[reference.MethodId]); } finally { _registryLock.ExitReadLock(); } }
private ValueTask <IClientConnection> ResolveTargetConnectionAsync( IProvidedMethodReference method, IClientConnection source) { if (method.ProvidedService.ConnectionId.HasValue) { var connectionId = method.ProvidedService.ConnectionId.Value; if (!_clientConnectionTracker.TryGetOnlineConnection(connectionId, out var connection)) { throw new InvalidOperationException($"The requested connection {connectionId} is not online"); } return(new ValueTask <IClientConnection>(connection)); } return(_clientConnectionTracker.GetOrSpawnConnectionAsync(new[] { method.ProvidedService.ApplicationId })); }
public IDiscoveredMethod CreateDiscoveredMethod( IProvidedMethodReference providedMethod, Maybe <string> methodTitle, string inputMessageId, string outputMessageId, MethodType methodType) { var obj = DiscoveredMethod.Rent(); obj.ProvidedMethod = providedMethod; obj.MethodTitle = methodTitle; obj.InputMessageId = inputMessageId; obj.OutputMessageId = outputMessageId; obj.MethodType = methodType; return(obj); }
public IDiscoveredMethod CreateDiscoveredMethod( IProvidedMethodReference providedMethod, Maybe <string> methodTitle, string inputMessageId, string outputMessageId, MethodType methodType, IReadOnlyCollection <IOption> options) { var obj = DiscoveredMethod.Rent(); obj.ProvidedMethod = providedMethod; obj.MethodTitle = methodTitle; obj.InputMessageId = inputMessageId; obj.OutputMessageId = outputMessageId; obj.MethodType = methodType; obj.Options = options; return(obj); }
public T Handle(IProvidedMethodReference target, TArgs args) { return(_providedMethodHandler(target, args)); }
private async ValueTask <IAppConnection> ResolveTargetConnectionAsync( IProvidedMethodReference methodReference, IAppConnection source, ITransportChannel sourceChannel, IContextLinkageOptions contextLinkageOptions) { if (methodReference.ProvidedService.ConnectionId.HasValue) { var connectionId = methodReference.ProvidedService.ConnectionId.Value; if (!_appLifecycleManager.TryGetOnlineConnection(connectionId, out var connection)) { throw new InvalidOperationException($"The requested connection {connectionId} is not online"); } return(connection); } var appId = methodReference.ProvidedService.ApplicationId; if (methodReference.ProvidedService.ApplicationInstanceId.HasValue) { var appInstanceId = methodReference.ProvidedService.ApplicationInstanceId.Value; if (appId.HasValue && _appLifecycleManager.TryGetConnectionInProgress(appInstanceId, appId.Value, out var connectionInProgress)) { return(await connectionInProgress); } var connections = _appLifecycleManager.GetAppInstanceConnections(appInstanceId).ToList(); if (connections.Count == 0) { throw new InvalidOperationException($"App instance {appInstanceId} is doesn't have online connections"); } if (appId.HasValue) { var connection = connections.FirstOrDefault(c => c.Info.ApplicationId.Equals(appId.Value)); if (connection == null) { throw new InvalidOperationException($"App instance {appInstanceId} is doesn't have connection with {appId.Value} application id"); } return(connection); } if (connections.Count == 1) { return(connections.Single()); } throw new InvalidOperationException($"App instance {appInstanceId} has several connections, you need to specify ApplicationId to make call to specific connection"); } if (!appId.HasValue) { throw new InvalidOperationException($"AppId is required to resolve target connection for {methodReference} provided method reference"); } var appIdValue = appId.Value; var method = _registryService.GetProvidedMethod(methodReference); var launchMode = GetLaunchMode(method); Task <ResolvedConnection> resolveTask; lock (_resolveConnectionSync) { if (launchMode != LaunchMode.MultiInstance) { var onlineConnections = _appLifecycleManager .GetOnlineConnections() .Where(x => x.Info.ApplicationId.Equals(appIdValue) && !x.Id.Equals(source.Id)).ToArray(); if (_contextLinkageManager.IsContextShouldBeConsidered(contextLinkageOptions, source)) { onlineConnections = _contextLinkageManager .GetAppsInContexts(contextLinkageOptions, source, true) .Join(onlineConnections, x => x.ConnectionId.Value, y => y.Id, (x, y) => y) .ToArray(); } if (onlineConnections.Any()) { return(onlineConnections.First()); } } if (launchMode == LaunchMode.None || !_appLifecycleManager.CanBeLaunched(appIdValue)) { throw new InvalidOperationException( $"The requested app {appIdValue} is not online and cannot be launched"); } var resolveMode = ConvertToResolveMode(launchMode); resolveTask = _appLifecycleManager.LaunchAndConnectAsync(appIdValue, resolveMode, source.Info); } var resolvedConnection = await resolveTask.ConfigureAwait(false); return(resolvedConnection.AppConnection); }