Bug 6714 - Use singleton service in clustered netconf topology
[netconf.git] / netconf / abstract-topology / src / main / java / org / opendaylight / netconf / topology / example / ExampleSingleStateAggregator.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
9 package org.opendaylight.netconf.topology.example;
10
11 import com.google.common.base.Preconditions;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import java.util.List;
14 import org.opendaylight.netconf.topology.StateAggregator;
15 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
16
17 /**
18  * Aggregator implementation expecting just a single state
19  */
20 public final class ExampleSingleStateAggregator implements StateAggregator {
21
22     @Override public ListenableFuture<Node> combineCreateAttempts(final List<ListenableFuture<Node>> stateFutures) {
23         return getSingleFuture(stateFutures);
24     }
25
26     private <T> ListenableFuture<T> getSingleFuture(final List<ListenableFuture<T>> stateFutures) {
27         Preconditions.checkArgument(stateFutures.size() == 1, "Recieved multiple results, Single result is enforced here");
28         return stateFutures.get(0);
29     }
30
31     @Override public ListenableFuture<Node> combineUpdateAttempts(final List<ListenableFuture<Node>> stateFutures) {
32         return getSingleFuture(stateFutures);
33     }
34
35     @Override public ListenableFuture<Void> combineDeleteAttempts(final List<ListenableFuture<Void>> stateFutures) {
36         return getSingleFuture(stateFutures);
37     }
38 }