Beispiel #1
0
        private bool SeedNode(bool failIfNotConnected)
        {
            // Must copy array reference for copy on write semantics to work.
            Host[]      seedArray  = seeds;
            Exception[] exceptions = null;

            for (int i = 0; i < seedArray.Length; i++)
            {
                Host seed = seedArray[i];

                try
                {
                    NodeValidator nv   = new NodeValidator();
                    Node          node = nv.SeedNode(this, seed);

                    Dictionary <string, Node> nodesToAdd = new Dictionary <string, Node>(1);
                    nodesToAdd[node.Name] = node;
                    AddNodes(nodesToAdd);
                    return(true);
                }
                catch (Exception e)
                {
                    // Store exception and try next seed.
                    if (failIfNotConnected)
                    {
                        if (exceptions == null)
                        {
                            exceptions = new Exception[seedArray.Length];
                        }
                        exceptions[i] = e;
                    }
                    else
                    {
                        if (Log.WarnEnabled())
                        {
                            Log.Warn("Seed " + seed + " failed: " + Util.GetErrorMessage(e));
                        }
                    }
                }
            }

            if (failIfNotConnected)
            {
                StringBuilder sb = new StringBuilder(500);
                sb.AppendLine("Failed to connect to host(s): ");

                for (int i = 0; i < seedArray.Length; i++)
                {
                    sb.Append(seedArray[i]);
                    sb.Append(' ');

                    Exception ex = exceptions[i];

                    if (ex != null)
                    {
                        sb.AppendLine(ex.Message);
                    }
                }
                throw new AerospikeException.Connection(sb.ToString());
            }
            return(false);
        }
Beispiel #2
0
        private bool SeedNode(Peers peers, bool failIfNotConnected)
        {
            // Must copy array reference for copy on write semantics to work.
            Host[]        seedArray  = seeds;
            Exception[]   exceptions = null;
            NodeValidator nv         = new NodeValidator();

            for (int i = 0; i < seedArray.Length; i++)
            {
                Host seed = seedArray[i];

                try
                {
                    Node node = nv.SeedNode(this, seed, peers);

                    if (node != null)
                    {
                        AddNode(node);
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    // Store exception and try next seed.
                    if (failIfNotConnected)
                    {
                        if (exceptions == null)
                        {
                            exceptions = new Exception[seedArray.Length];
                        }
                        exceptions[i] = e;
                    }
                    else
                    {
                        if (Log.WarnEnabled())
                        {
                            Log.Warn("Seed " + seed + " failed: " + Util.GetErrorMessage(e));
                        }
                    }
                }
            }

            // No seeds valid. Use fallback node if it exists.
            if (nv.fallback != null)
            {
                AddNode(nv.fallback);
                return(true);
            }

            if (failIfNotConnected)
            {
                StringBuilder sb = new StringBuilder(500);
                sb.AppendLine("Failed to connect to host(s): ");

                for (int i = 0; i < seedArray.Length; i++)
                {
                    sb.Append(seedArray[i]);
                    sb.Append(' ');

                    Exception ex = exceptions[i];

                    if (ex != null)
                    {
                        sb.AppendLine(ex.Message);
                    }
                }
                throw new AerospikeException.Connection(sb.ToString());
            }
            return(false);
        }