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

org.wildfly.clustering.singleton.election.RandomSingletonElectionPolicy Maven / Gradle / Ivy

There is a newer version: 34.0.1.Final
Show newest version
/*
 * Copyright The WildFly Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package org.wildfly.clustering.singleton.election;

import java.util.List;
import java.util.Random;

import org.wildfly.clustering.group.Node;
import org.wildfly.clustering.singleton.SingletonElectionPolicy;

/**
 * {@link SingletonElectionPolicy} that elects a random member.
 * @author Paul Ferraro
 */
public class RandomSingletonElectionPolicy implements SingletonElectionPolicy {

    private final Random random = new Random(System.currentTimeMillis());

    /**
     * {@inheritDoc}
     */
    @Override
    public Node elect(List nodes) {
        int size = nodes.size();
        return (size > 0) ? nodes.get(this.random.nextInt(size)) : null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy