Exemplo n.º 1
0
        internal ConnectionPair(SimpleInMemConnection client, SimpleInMemConnection server)
        {
            if (server == null)
            {
                throw new ArgumentNullException(nameof(server));
            }
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (server.ConnectionType != ConnectionType.Server)
            {
                throw new ArgumentException($"{server.ToString()} - Invalid Server connection type: {server.ConnectionType}");
            }
            if (client.ConnectionType != ConnectionType.Client)
            {
                throw new ArgumentException($"{client.ToString()} - Invalid Client connection type: {client.ConnectionType}");
            }

            if (server.IsPaired)
            {
                throw new ArgumentException($"{server.ToString()} - already paired connection.");
            }

            if (client.IsPaired)
            {
                throw new ArgumentException($"{client.ToString()} - already paired connection.");
            }

            this.server = server;
            this.client = client;
        }
        public SimpleInMemConnection GetConnection(Guid pairId, ConnectionType connectionType)
        {
            ConnectionPair        pair;
            SimpleInMemConnection connection = null;
            bool foundPair = false;

            lock (connectionsLock)
            {
                foundPair = connectionPairs.TryGetValue(pairId, out pair);
            }

            if (foundPair)
            {
                if (connectionType == ConnectionType.Client)
                {
                    connection = pair.Client;
                }
                else if (connectionType == ConnectionType.Server)
                {
                    connection = pair.Server;
                }
            }

            return(connection);
        }
        internal ConnectionPair CreateConnectionPair()
        {
            var clientConnection = new SimpleInMemConnection(this, ConnectionType.Client, new ServiceHost(logger),
                                                             transport, logger, metrics);
            var serverConnection = new SimpleInMemConnection(this, ConnectionType.Server, serviceHost, transport, logger, metrics);
            var connectionPair   = SimpleInMemConnection.Pair(clientConnection, serverConnection);

            Add(connectionPair);
            return(connectionPair);
        }
Exemplo n.º 4
0
        internal static ConnectionPair Pair(SimpleInMemConnection client, SimpleInMemConnection server)
        {
            ConnectionPair pair = new ConnectionPair(client, server);

            server.pairedReadQueue = client.writeQueue;
            client.pairedReadQueue = server.writeQueue;

            server.Start();
            client.Start();
            return(pair);
        }