示例#1
0
        /// <inheritdoc />
        public void Dispose()
        {
            if (!this.disposed)
            {
                this.disposed = true;

                if (this.factory != null)
                {
                    this.factory.Dispose();
                    this.factory = null;
                }

                if (this.backend != null)
                {
                    this.backend.Dispose();
                    this.backend = null;
                }

                if (this.ringMasterServer != null)
                {
                    this.ringMasterServer.Dispose();
                    this.ringMasterServer = null;
                }
            }
        }
示例#2
0
        private void Run(int port)
        {
            var protocol = new RingMasterCommunicationProtocol();

            this.CreateBackend();

            using (var cancel = new CancellationTokenSource())
            {
                this.ringMasterServer = new RingMasterServer(protocol, null, cancel.Token);

                var transportConfig = new SecureTransport.Configuration
                {
                    UseSecureConnection          = false,
                    IsClientCertificateRequired  = false,
                    CommunicationProtocolVersion = RingMasterCommunicationProtocol.MaximumSupportedVersion,
                };

                using (var serverTransport = new SecureTransport(transportConfig))
                {
                    this.ringMasterServer.RegisterTransport(serverTransport);
                    this.ringMasterServer.OnInitSession = initRequest =>
                    {
                        return(new CoreRequestHandler(this.backend, initRequest));
                    };

                    serverTransport.StartServer(port);

                    Console.WriteLine("Press ENTER to exit...");
                    Console.ReadLine();
                    cancel.Cancel();
                }
            }
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TcpCommunicationListener" /> class.
        /// </summary>
        /// <param name="server">RingMaster server</param>
        /// <param name="port">Port where this listener will listen</param>
        /// <param name="uriPublished">The specific uri to listen on</param>
        /// <param name="executor">RingMaster request executor</param>
        /// <param name="instrumentation">Instrumentation consumer</param>
        /// <param name="protocol">The Marshalling protocol</param>
        /// <param name="maximumSupportedProtocolVersion">Maximum supported version</param>
        public TcpCommunicationListener(
            RingMasterServer server,
            int port,
            string uriPublished,
            IRingMasterRequestExecutor executor,
            IRingMasterServerInstrumentation instrumentation,
            ICommunicationProtocol protocol,
            uint maximumSupportedProtocolVersion)
        {
            this.server          = server;
            this.port            = port;
            this.uriPublished    = uriPublished;
            this.instrumentation = instrumentation;
            this.protocol        = protocol;

            var transportConfig = new SecureTransport.Configuration
            {
                UseSecureConnection          = false,
                IsClientCertificateRequired  = false,
                CommunicationProtocolVersion = maximumSupportedProtocolVersion,
            };

            this.transport = new SecureTransport(transportConfig);
            this.executor  = executor;
        }
示例#4
0
        /// <inheritdoc />
        public void Dispose()
        {
            this.backend.Dispose();
            this.factory.Dispose();
            this.cancellationSource.Dispose();

            if (this.ringMasterServer != null)
            {
                this.ringMasterServer.Dispose();
                this.ringMasterServer = null;
            }
        }
示例#5
0
        private ICommunicationListener CreateListener(StatefulServiceContext context)
        {
            // Partition replica's URL is the node's IP, port, PartitionId, ReplicaId, Guid
            var protocol = EndpointProtocol.Tcp;

            try
            {
                var internalEndpoint = context.CodePackageActivationContext.GetEndpoint("ServiceEndpoint");
                this.port = Convert.ToUInt16(internalEndpoint.Port);

                protocol = internalEndpoint.Protocol;

                RingMasterServiceEventSource.Log.CreateListener("RingMasterProtocol", this.port, 0);
            }
            catch (Exception ex)
            {
                RingMasterServiceEventSource.Log.CreateListener_GetEndpointFailed($"Failed to get ServiceEndpoint for RingMasterProtocol: {ex}");
                throw;
            }

            var communicationProtocol = new RingMasterCommunicationProtocol();

            this.ringMasterServer = new RingMasterServer(
                communicationProtocol,
                this.ringMasterServerInstrumentation,
                CancellationToken.None);

            string nodeIp = context.NodeContext.IPAddressOrFQDN;

            if (nodeIp.Equals("LocalHost", StringComparison.OrdinalIgnoreCase))
            {
                nodeIp = GetHostIp(Dns.GetHostName());
            }

            string uri = $"{protocol}://{nodeIp}:{this.port}/";

            return(new TcpCommunicationListener(
                       this.ringMasterServer,
                       this.port,
                       uri,
                       this.backend,
                       this.ringMasterServerInstrumentation,
                       communicationProtocol,
                       RingMasterCommunicationProtocol.MaximumSupportedVersion));
        }
示例#6
0
        public static void Setup(TestContext context)
        {
            var            path        = System.Reflection.Assembly.GetExecutingAssembly().Location;
            var            builder     = new ConfigurationBuilder().SetBasePath(Path.GetDirectoryName(path)).AddJsonFile("appSettings.json");
            IConfiguration appSettings = builder.Build();

            Helpers.SetupTraceLog(Path.Combine(appSettings["LogFolder"], "VegaInMemoryPerf.LogPath"));
            log = s => Trace.TraceInformation(s);

            // If a parameter is specified as follows:
            //      te.exe VegaInMemoryPerf.dll /p:ServerAddress=127.0.0.1:99
            if (!context.Properties.ContainsKey("ServerAddress"))
            {
                backendCore   = CreateBackend();
                backendServer = new RingMasterServer(protocol, null, CancellationToken.None);

                var transportConfig = new SecureTransport.Configuration
                {
                    UseSecureConnection          = false,
                    IsClientCertificateRequired  = false,
                    CommunicationProtocolVersion = RingMasterCommunicationProtocol.MaximumSupportedVersion,
                };

                serverTransport = new SecureTransport(transportConfig);

                backendServer.RegisterTransport(serverTransport);
                backendServer.OnInitSession = initRequest =>
                {
                    return(new CoreRequestHandler(backendCore, initRequest));
                };

                serverTransport.StartServer(10009);
                serverAddress = "127.0.0.1:10009";
            }
            else
            {
                serverAddress = context.Properties["ServerAddress"] as string;
            }

            // Read the app settings
            minPayloadSize = int.Parse(appSettings["MinPayloadSize"]);
            maxPayloadSize = int.Parse(appSettings["MaxPayloadSize"]);
            threadCount    = int.Parse(appSettings["ThreadCount"]);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RingMasterClientUnitTest"/> class.
        /// </summary>
        public RingMasterClientUnitTest()
        {
            this.serverTransport  = new SimpleTransport();
            this.backend          = this.CreateBackend();
            this.ringMasterServer = new RingMasterServer(this.protocol, null, this.cancellationTokenSource.Token);
            this.ringMasterServer.RegisterTransport(this.serverTransport);
            this.ringMasterServer.OnInitSession = initRequest =>
            {
                return(new CoreRequestHandler(this.backend, initRequest));
            };

            foreach (var source in EventSource.GetSources())
            {
                if (source.Guid == this.ringMasterClientEventSourceGuid)
                {
                    Trace.TraceInformation($"Enabling EventSource {source.Name}");
                    this.listener.EnableEvents(source, EventLevel.Verbose);
                }
            }
        }