All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.despegar.jdbc.galera.policies.MasterSortingNodesPolicy Maven / Gradle / Ivy

Go to download

A simple Java client for MariaDB Galera Cluster and Percona XtraDB Cluster. It is designed to be an alternative to connect JVM app to MariaDB/Percona galera nodes without HAProxy

There is a newer version: 1.0.20
Show newest version
package com.despegar.jdbc.galera.policies;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.List;

/**
 * We choose master choosing always the first active node sorted alphabetically
 */
public class MasterSortingNodesPolicy implements ElectionNodePolicy {
    private static final Logger LOG = LoggerFactory.getLogger(MasterSortingNodesPolicy.class);

    public String chooseNode(List activeNodes) {

        String[] nodes = activeNodes.toArray(new String[activeNodes.size()]);
        Arrays.sort(nodes);
        String master = nodes[0];

        LOG.info("Master node selected {}", master);

        return master;
    }

    @Override
    public String getName() {
        return "MasterSortingNodes";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy