Refactor AbstractClientHandle a bit
[controller.git] / opendaylight / md-sal / sal-distributed-eos / src / main / java / org / opendaylight / controller / cluster / entityownership / selectionstrategy / FirstCandidateSelectionStrategy.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.entityownership.selectionstrategy;
9
10 import com.google.common.base.Preconditions;
11 import java.util.Collection;
12 import java.util.Collections;
13 import java.util.Map;
14
15 /**
16  * The FirstCandidateSelectionStrategy always selects the first viable candidate from the list of candidates.
17  */
18 public class FirstCandidateSelectionStrategy extends AbstractEntityOwnerSelectionStrategy {
19
20     public static final FirstCandidateSelectionStrategy INSTANCE =
21             new FirstCandidateSelectionStrategy(0L, Collections.emptyMap());
22
23     public FirstCandidateSelectionStrategy(final long selectionDelayInMillis,
24             final Map<String, Long> initialStatistics) {
25         super(selectionDelayInMillis, initialStatistics);
26     }
27
28     @Override
29     public String newOwner(final String currentOwner, final Collection<String> viableCandidates) {
30         Preconditions.checkArgument(viableCandidates.size() > 0, "No viable candidates provided");
31         return viableCandidates.iterator().next();
32     }
33 }