Beispiel #1
0
 /// <inheritdoc />
 public ICollection <Host> AllHosts()
 {
     //Do not connect at first
     return(_metadata.AllHosts());
 }
Beispiel #2
0
        private static void waitFor(string node, Cluster cluster, int maxTry, bool waitForDead, bool waitForOut)
        {
            // In the case where the we've killed the last node in the cluster, if we haven't
            // tried doing an actual query, the driver won't realize that last node is dead until'
            // keep alive kicks in, but that's a fairly long time. So we cheat and trigger a force'
            // the detection by forcing a request.
            bool disconnected = false;

            if (waitForDead || waitForOut)
            {
                disconnected = !cluster.RefreshSchema(null, null);
            }

            if (disconnected)
            {
                return;
            }

            IPAddress address;

            try
            {
                address = IPAddress.Parse(node);
            }
            catch (Exception e)
            {
                // That's a problem but that's not *our* problem
                return;
            }

            Metadata metadata = cluster.Metadata;

            for (int i = 0; i < maxTry; ++i)
            {
                bool found = false;
                foreach (Host host in metadata.AllHosts())
                {
                    if (host.Address.Equals(address))
                    {
                        found = true;
                        if (testHost(host, waitForDead))
                        {
                            return;
                        }
                    }
                }
                if (waitForDead && !found)
                {
                    return;
                }
                try { Thread.Sleep(1000); }
                catch (Exception e) { }
            }

            foreach (Host host in metadata.AllHosts())
            {
                if (host.Address.Equals(address))
                {
                    if (testHost(host, waitForDead))
                    {
                        return;
                    }
                    else
                    {
                        // logging it because this give use the timestamp of when this happens
                        logger.Info(node + " is not " + (waitForDead ? "DOWN" : "UP") + " after " + maxTry + "s");
                        throw new InvalidOperationException(node + " is not " + (waitForDead ? "DOWN" : "UP") + " after " + maxTry + "s");
                    }
                }
            }

            if (waitForOut)
            {
                return;
            }
            else
            {
                logger.Info(node + " is not part of the cluster after " + maxTry + "s");
                throw new InvalidOperationException(node + " is not part of the cluster after " + maxTry + "s");
            }
        }