public IncomingInvocationDescriptor(
     InvocationMethodDescriptor method,
     AppConnectionDescriptor source)
 {
     Method = method;
     Source = source;
 }
Пример #2
0
        public void AppConnected(AppConnectionDescriptor appConnection)
        {
            _bindingSubject.OnNext(new AppContextBindingEvent(this, appConnection.ApplicationInstanceId));
            var appConnectionsSet = GetOrCreateAppConnectionsSet(appConnection.ApplicationInstanceId);

            appConnectionsSet.AppConnected(appConnection);
        }
Пример #3
0
 public AppConnection(ITransportConnection connection, AppConnectionDescriptor appInfo)
 {
     Id          = connection.Id;
     _log        = LogManager.GetLogger <AppConnection>(Id.ToString());
     Info        = appInfo;
     _connection = connection;
     Completion  = ProcessAsync();
 }
Пример #4
0
 public static Generated.AppConnectionDescriptor ToProto(this AppConnectionDescriptor info)
 {
     return(new Generated.AppConnectionDescriptor
     {
         AppId = info.ApplicationId,
         AppInstanceId = info.ApplicationInstanceId.ToProto(),
         ConnectionId = info.ConnectionId.ToProto()
     });
 }
Пример #5
0
 public void AppDisconnected(AppConnectionDescriptor appConnection)
 {
     lock (_lock)
     {
         if (_appInstanceIdsToConnections.TryGetValue(appConnection.ApplicationInstanceId, out var appConnectionsSet))
         {
             appConnectionsSet.AppDisconnected(appConnection);
         }
     }
 }
 public InvocationDescriptor(
     AppConnectionDescriptor sourceConnection,
     AppConnectionDescriptor targetConnection,
     string serviceId,
     string serviceAlias,
     string methodId)
 {
     SourceConnection = sourceConnection;
     TargetConnection = targetConnection;
     ServiceId        = serviceId;
     ServiceAlias     = serviceAlias;
     MethodId         = methodId;
 }
Пример #7
0
        public void AppDisconnected(AppConnectionDescriptor appConnection)
        {
            var updated = false;

            lock (_lock)
            {
                var appId = appConnection.ApplicationId;
                updated |= _appConnectionMap.Remove(appId);
                updated |= _loadingApps.Remove(appId);
            }

            if (updated)
            {
                _updatedSubject.OnNext(Unit.Default);
            }
        }
Пример #8
0
        public async Task <IAppConnection> HandleAsync(ITransportConnection connection)
        {
            Log.Trace("Accepting new connection {0}", connection.Id);
            var channel = await connection.IncomingChannels.ReadAsync().ConfigureAwait(false);

            var frame = await channel.In.ReadAsync().ConfigureAwait(false);

            using (var payload = frame.Payload)
                using (var connectRequest = _serializer.DeserializeConnectRequest(payload))
                {
                    if (!_registryService.IsApplicationDefined(connectRequest.ApplicationId))
                    {
                        throw new BrokerException($"Connection rejected because application id is unknown to broker: {connectRequest.ApplicationId}");
                    }
                    using (var connectResponse = _messageFactory.CreateConnectResponse(connection.Id))
                    {
                        var serializedResponse = _serializer.Serialize(connectResponse);
                        try
                        {
                            Log.Trace("Sending connect response ({0} bytes): {1}", connectResponse, serializedResponse.Count);
                            await channel.Out.WriteAsync(new TransportMessageFrame(serializedResponse)).ConfigureAwait(false);
                        }
                        catch
                        {
                            serializedResponse.Dispose();
                            throw;
                        }
                        channel.Out.TryComplete();
                        await channel.Completion.ConfigureAwait(false);

                        var info =
                            new AppConnectionDescriptor(
                                connectResponse.ConnectionId,
                                connectRequest.ApplicationId,
                                connectRequest.ApplicationInstanceId);
                        var clientConnection = _connectionTracker.AcceptConnection(connection, info);
                        Log.Info("New connection accepted: {0}", clientConnection);
                        return(clientConnection);
                    }
                }
        }
Пример #9
0
        public void AppConnected(AppConnectionDescriptor appConnection)
        {
            var updated = false;

            lock (_lock)
            {
                var appId = appConnection.ApplicationId;
                if (!_appConnectionMap.TryGetValue(appId, out var existingAppConnection) ||
                    !Equals(appConnection, existingAppConnection))
                {
                    _appConnectionMap[appId] = appConnection;
                    updated = true;
                }
                updated |= _loadingApps.Remove(appId);
            }

            if (updated)
            {
                _updatedSubject.OnNext(Unit.Default);
            }
        }
Пример #10
0
 public AppConnectionEvent(AppConnectionDescriptor connection, ConnectionEventType type)
 {
     Connection = connection;
     Type       = type;
 }