Exemplo n.º 1
0
        private void DiscoverNodesSync()
        {
            using (var discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint()))
            {
                FindResponse fileToMachineEndPoints =
                    discoveryClient.Find(new FindCriteria(typeof(IFileToMachineServiceContract)));
                foreach (EndpointDiscoveryMetadata endpoint in fileToMachineEndPoints.Endpoints)
                {
                    try
                    {
                        var client = new FileToMachineClient(new BasicHttpBinding(), endpoint.Address);
                        FileToMachineHandler.AddToRoutingTable(client.Ping().NodeIdentifier);
                    }
                    catch (CommunicationException e)
                    {
                    }
                }

                FindResponse reverseIndexEndPoints =
                    discoveryClient.Find(new FindCriteria(typeof(IReverseIndexServiceContract)));
                foreach (EndpointDiscoveryMetadata endPoint in reverseIndexEndPoints.Endpoints)
                {
                    try
                    {
                        var client = new ReverseIndexServiceClient(new BasicHttpBinding(), endPoint.Address);
                        ReverseIndexHandler.AddToRoutingTable(client.Ping().NodeIdentifier);
                    }
                    catch (CommunicationException e)
                    {
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void InitDiscovery()
        {
            Logger.Info("Starting the (Initial) Discovery proccess...");
            int discoveredReverseIndex = 0, discoveredFileToMachine = 0;
            var finder = new KadNodeFinder();

            finder.FileToMachineEndpointDiscovered += (_, e) =>
            {
                discoveredReverseIndex++;
                FileToMachineHandler.AddToRoutingTable(e.NodeIdentifier);
                Logger.Info("New Reverse Index service node found: " + e.NodeIdentifier);
            };
            finder.ReverseIndexServiceEndpointDiscovered += (_, e) =>
            {
                discoveredFileToMachine++;
                ReverseIndexHandler.AddToRoutingTable(e.NodeIdentifier);
                Logger.Info("New File2Machine service node found: " + e.NodeIdentifier);
            };
            finder.DiscoveryFinished += (_, __) => NodeDiscoveryCompleted();

            // when minNodes are discovered, ActivateAndJoin()
            const int minKnownNodesBeforeJoiningAsClient = 1;

            finder.FileToMachineEndpointDiscovered +=
                (_, __) =>
            {
                if (discoveredReverseIndex >= minKnownNodesBeforeJoiningAsClient &&
                    discoveredFileToMachine >= minKnownNodesBeforeJoiningAsClient &&
                    !IsActive)
                {
                    ActivateAndJoin();
                }
            };
            finder.InitDiscovery();
        }