public void populateNodeList() throws SocketTimeoutException {

        /* This flag decides whether the node list is obtained from primary or secondary IP. */
        boolean ip = true;
        /* Once this flag reaches MAX_RETRIES, a SocketTimeoutException will be thrown. */
        int count = 0;

        ClusterTableRecord[] tempRecords;

        /* Get the cluster member record table from the primary node or
         * secondary node.
         */
        while (true) {

            InetAddress ipAddr = null;

            /* Switch to primary or secondary IP at every retry. */
            if (ip) {
                ipAddr = this.primaryIp;
            } else {

                logger.log(Level.FINE, "Selecting secondary node IP");
                ipAddr = this.secondaryIp;
            }

            try {

                logger.log(Level.INFO, "ipAddr = " + ipAddr);

                ControlMessage getNodeList = new ControlMessage('e', ipAddr);
                tempRecords = getNodeList(ipAddr, getNodeList);

                if (tempRecords != null) {

                    /* Once the node list is obtained, select 'K' nodes */
                    logger.log(Level.FINE, "Got the node list. Now selecting nodes..");
                    selectKNodes(tempRecords);

                } else {

                    /* If we didnt get the cluster table record from the cluster node, throw this */
                    logger.log(Level.INFO, "Did not get cluster table record from cluster node.");
                    throw new NullPointerException();

                }

                break;

            } catch (SocketTimeoutException e) {

                /* Could not connect to the selected node. Try again with the alternate node. */
                ip = !ip;
                if (++count == MAX_RETRIES) throw e;

            } catch (IOException e) {

                logger.log(Level.SEVERE, "[ERROR]: Error while getting node list from cluster");
                e.printStackTrace();

                /* Could not connect to the selected node. Try again with the alternate node. */
                ip = !ip;
                if (++count == MAX_RETRIES) System.exit(1);

            }
        }

    }