org.wildfly.clustering.singleton.election.RandomSingletonElectionPolicy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of wildfly-clustering-singleton-api Show documentation
Show all versions of wildfly-clustering-singleton-api Show documentation
Public API for installing singleton MSC services.
/*
* 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;
}
}