/// <summary>
        /// Constructs a DefaultRemoteManager listening on the specified address and
        /// a specific port.
        /// </summary>
        /// <param name="localAddress">The address to listen on</param>
        /// <param name="tcpPortProvider">Tcp port provider</param>
        /// <param name="streamingCodec">Streaming codec</param>
        /// <param name="tcpClientFactory">provides TcpClient for given endpoint</param>
        internal StreamingRemoteManager(IPAddress localAddress,
                                        ITcpPortProvider tcpPortProvider,
                                        IStreamingCodec <T> streamingCodec,
                                        ITcpClientConnectionFactory tcpClientFactory)
        {
            if (localAddress == null)
            {
                throw new ArgumentNullException("localAddress");
            }

            _tcpClientFactory  = tcpClientFactory;
            _observerContainer = new ObserverContainer <T>();
            _cachedClients     = new Dictionary <IPEndPoint, ProxyObserver>();
            _remoteEventCodec  = new RemoteEventStreamingCodec <T>(streamingCodec);

            // Begin to listen for incoming messages
            _server = new StreamingTransportServer <IRemoteEvent <T> >(localAddress,
                                                                       _observerContainer,
                                                                       tcpPortProvider,
                                                                       _remoteEventCodec);
            _server.Run();

            LocalEndpoint = _server.LocalEndpoint;
            Identifier    = new SocketRemoteIdentifier(LocalEndpoint);
        }
 private StreamingRemoteManagerFactory(ITcpPortProvider tcpPortProvider,
                                       ITcpClientConnectionFactory tcpClientFactory,
                                       IInjector injector)
 {
     _tcpPortProvider  = tcpPortProvider;
     _tcpClientFactory = tcpClientFactory;
     _injector         = injector;
 }
Esempio n. 3
0
 /// <summary>
 /// Construct a TransportClient.
 /// Used to send messages to the specified remote endpoint.
 /// </summary>
 /// <param name="remoteEndpoint">The endpoint of the remote server to connect to</param>
 /// <param name="observer">Callback used when receiving responses from remote host</param>
 /// <param name="streamingCodec">Streaming codec</param>
 /// <param name="clientFactory">TcpClient factory</param>
 internal StreamingTransportClient(IPEndPoint remoteEndpoint,
                                   IObserver <TransportEvent <T> > observer,
                                   IStreamingCodec <T> streamingCodec,
                                   ITcpClientConnectionFactory clientFactory)
     : this(remoteEndpoint, streamingCodec, clientFactory)
 {
     _observer = observer;
     Task.Run(() => ResponseLoop());
 }
Esempio n. 4
0
 private DefaultRemoteManagerFactory(
     ITcpPortProvider tcpPortProvider,
     ITcpClientConnectionFactory tcpClientFactory,
     ILocalAddressProvider localAddressProvider)
 {
     _tcpPortProvider      = tcpPortProvider;
     _localAddressProvider = localAddressProvider;
     _tcpClientFactory     = tcpClientFactory;
 }
Esempio n. 5
0
 /// <summary>
 /// Construct a TransportClient.
 /// Used to send messages to the specified remote endpoint.
 /// </summary>
 /// <param name="remoteEndpoint">The endpoint of the remote server to connect to</param>
 /// <param name="codec">Codec to decode/encodec</param>
 /// <param name="observer">Callback used when receiving responses from remote host</param>
 /// <param name="clientFactory">TcpClient factory</param>
 public TransportClient(IPEndPoint remoteEndpoint,
                        ICodec <T> codec,
                        IObserver <TransportEvent <T> > observer,
                        ITcpClientConnectionFactory clientFactory)
     : this(remoteEndpoint, codec, clientFactory)
 {
     _observer = observer;
     Task.Run(() => ResponseLoop());
 }
Esempio n. 6
0
 /// <summary>
 /// Construct a TransportClient.
 /// Used to send messages to the specified remote endpoint.
 /// </summary>
 /// <param name="remoteEndpoint">The endpoint of the remote server to connect to</param>
 /// <param name="observer">Callback used when receiving responses from remote host</param>
 /// <param name="streamingCodec">Streaming codec</param>
 /// <param name="clientFactory">TcpClient factory</param>
 internal StreamingTransportClient(IPEndPoint remoteEndpoint,
                                   IObserver <TransportEvent <T> > observer,
                                   IStreamingCodec <T> streamingCodec,
                                   ITcpClientConnectionFactory clientFactory)
     : this(remoteEndpoint, streamingCodec, clientFactory)
 {
     _observer = observer;
     Task.Factory.StartNew(() => ResponseLoop(), TaskCreationOptions.LongRunning);
 }
Esempio n. 7
0
        private NameClient(
            [Parameter(typeof(NamingConfigurationOptions.NameServerAddress))] string remoteAddress,
            [Parameter(typeof(NamingConfigurationOptions.NameServerPort))] int remotePort,
            ITcpClientConnectionFactory tcpClientFactory)
        {
            IPEndPoint remoteEndpoint = new IPEndPoint(IPAddress.Parse(remoteAddress), remotePort);

            _tcpClientFactory = tcpClientFactory;
            Initialize(remoteEndpoint);
            _disposed = false;
            _cache    = TangFactory.GetTang().NewInjector().GetInstance <NameCache>();
        }
Esempio n. 8
0
        private NameClient(
            [Parameter(typeof(NamingConfigurationOptions.NameServerAddress))] string remoteAddress,
            [Parameter(typeof(NamingConfigurationOptions.NameServerPort))] int remotePort,
            ITcpClientConnectionFactory tcpClientFactory,
            NameCache cache)
        {
            IPEndPoint remoteEndpoint = new IPEndPoint(IPAddress.Parse(remoteAddress), remotePort);

            _tcpClientFactory = tcpClientFactory;
            Initialize(remoteEndpoint);
            _disposed = false;
            _cache    = cache;
        }
 /// <summary>
 /// Construct a TransportClient.
 /// Used to send messages to the specified remote endpoint.
 /// </summary>
 /// <param name="remoteEndpoint">The endpoint of the remote server to connect to</param>
 /// <param name="observer">Callback used when receiving responses from remote host</param>
 /// <param name="streamingCodec">Streaming codec</param>
 /// <param name="clientFactory">TcpClient factory</param>
 internal StreamingTransportClient(IPEndPoint remoteEndpoint,
                                   IObserver <TransportEvent <T> > observer,
                                   IStreamingCodec <T> streamingCodec,
                                   ITcpClientConnectionFactory clientFactory)
     : this(remoteEndpoint, streamingCodec, clientFactory)
 {
     _observer = observer;
     try
     {
         Task.Factory.StartNew(() => ResponseLoop(), TaskCreationOptions.LongRunning);
     }
     catch (Exception e)
     {
         Logger.Log(Level.Warning, "StreamingTransportClient get exception from ResponseLoop: {0}.", e.GetType());
         throw e;
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Constructs a Link object.
        /// Connects to the specified remote endpoint.
        /// </summary>
        /// <param name="remoteEndpoint">The remote endpoint to connect to</param>
        /// <param name="codec">The codec for serializing messages</param>
        /// <param name="tcpClientFactory">TcpClient factory</param>
        public Link(IPEndPoint remoteEndpoint, ICodec <T> codec, ITcpClientConnectionFactory tcpClientFactory)
        {
            if (remoteEndpoint == null)
            {
                throw new ArgumentNullException("remoteEndpoint");
            }
            if (codec == null)
            {
                throw new ArgumentNullException("codec");
            }

            Client = tcpClientFactory.Connect(remoteEndpoint);

            _codec         = codec;
            _channel       = new Channel(Client.GetStream());
            _localEndpoint = (IPEndPoint)Client.Client.LocalEndPoint;
            _disposed      = false;
        }
Esempio n. 11
0
        /// <summary>
        /// Construct a TransportClient.
        /// Used to send messages to the specified remote endpoint.
        /// </summary>
        /// <param name="remoteEndpoint">The endpoint of the remote server to connect to</param>
        /// <param name="codec">Codec to decode/encode</param>
        /// <param name="clientFactory">TcpClient factory</param>
        public TransportClient(IPEndPoint remoteEndpoint, ICodec <T> codec, ITcpClientConnectionFactory clientFactory)
        {
            if (remoteEndpoint == null)
            {
                throw new ArgumentNullException("remoteEndpoint");
            }
            if (codec == null)
            {
                throw new ArgumentNullException("codec");
            }
            if (clientFactory == null)
            {
                throw new ArgumentNullException("clientFactory");
            }

            _link = new Link <T>(remoteEndpoint, codec, clientFactory);
            _cancellationSource = new CancellationTokenSource();
            _disposed           = false;
        }
        /// <summary>
        /// Constructs a DefaultRemoteManager. Does not listen for incoming messages.
        /// </summary>
        /// <param name="localAddressProvider">The local address provider</param>
        /// <param name="codec">The codec used for serializing messages</param>
        /// <param name="tcpClientFactory">provides TcpClient for given endpoint</param>
        internal DefaultRemoteManager(
            ILocalAddressProvider localAddressProvider,
            ICodec <T> codec,
            ITcpClientConnectionFactory tcpClientFactory)
        {
            using (LOGGER.LogFunction("DefaultRemoteManager::DefaultRemoteManager"))
            {
                if (codec == null)
                {
                    throw new ArgumentNullException("codec");
                }

                _tcpClientFactory  = tcpClientFactory;
                _observerContainer = new ObserverContainer <T>();
                _codec             = new RemoteEventCodec <T>(codec);
                _cachedClients     = new Dictionary <IPEndPoint, ProxyObserver>();

                LocalEndpoint = new IPEndPoint(localAddressProvider.LocalAddress, 0);
                Identifier    = new SocketRemoteIdentifier(LocalEndpoint);
            }
        }
        /// <summary>
        /// Constructs a DefaultRemoteManager listening on the specified address and any
        /// available port.
        /// </summary>
        /// <param name="localAddress">The address to listen on</param>
        /// <param name="port">The port to listen on</param>
        /// <param name="codec">The codec used for serializing messages</param>
        /// <param name="tcpPortProvider">provides port numbers to listen</param>
        /// <param name="tcpClientFactory">provides TcpClient for given endpoint</param>
        internal DefaultRemoteManager(IPAddress localAddress,
                                      int port,
                                      ICodec <T> codec,
                                      ITcpPortProvider tcpPortProvider,
                                      ITcpClientConnectionFactory tcpClientFactory)
        {
            if (localAddress == null)
            {
                throw new ArgumentNullException("localAddress");
            }
            if (port < 0)
            {
                throw new ArgumentException("Listening port must be greater than or equal to zero");
            }
            if (codec == null)
            {
                throw new ArgumentNullException("codec");
            }

            _tcpClientFactory  = tcpClientFactory;
            _observerContainer = new ObserverContainer <T>();
            _codec             = new RemoteEventCodec <T>(codec);
            _cachedClients     = new Dictionary <IPEndPoint, ProxyObserver>();

            IPEndPoint localEndpoint = new IPEndPoint(localAddress, port);

            // Begin to listen for incoming messages
            _server = new TransportServer <IRemoteEvent <T> >(localEndpoint,
                                                              _observerContainer,
                                                              _codec,
                                                              tcpPortProvider);
            _server.Run();

            LocalEndpoint = _server.LocalEndpoint;
            Identifier    = new SocketRemoteIdentifier(LocalEndpoint);
        }
        /// <summary>
        /// Construct a TransportClient.
        /// Used to send messages to the specified remote endpoint.
        /// </summary>
        /// <param name="remoteEndpoint">The endpoint of the remote server to connect to</param>
        /// <param name="streamingCodec">Streaming codec</param>
        /// <param name="clientFactory">TcpClient factory</param>
        internal StreamingTransportClient(IPEndPoint remoteEndpoint, IStreamingCodec <T> streamingCodec, ITcpClientConnectionFactory clientFactory)
        {
            if (remoteEndpoint == null)
            {
                Exceptions.Throw(new ArgumentNullException("remoteEndpoint"), Logger);
            }

            _link = new StreamingLink <T>(remoteEndpoint, streamingCodec, clientFactory);
            _cancellationSource = new CancellationTokenSource();
            _disposed           = false;
        }
Esempio n. 15
0
        /// <summary>
        /// Constructs a Link object.
        /// Connects to the specified remote endpoint.
        /// </summary>
        /// <param name="remoteEndpoint">The remote endpoint to connect to</param>
        /// <param name="streamingCodec">Streaming codec</param>
        /// <param name="tcpClientFactory">TcpClient factory</param>
        internal StreamingLink(IPEndPoint remoteEndpoint, IStreamingCodec <T> streamingCodec, ITcpClientConnectionFactory tcpClientFactory)
        {
            if (remoteEndpoint == null)
            {
                throw new ArgumentNullException("remoteEndpoint");
            }

            _client = tcpClientFactory.Connect(remoteEndpoint);
            var stream = _client.GetStream();

            _localEndpoint  = GetLocalEndpoint();
            _disposed       = false;
            _reader         = new StreamDataReader(stream);
            _writer         = new StreamDataWriter(stream);
            _streamingCodec = streamingCodec;
        }