Implement scatter/gather on module shards
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / DistributedDataStoreClientBehavior.java
1 /*
2  * Copyright (c) 2016 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.databroker.actors.dds;
9
10 import java.util.stream.Stream;
11 import org.opendaylight.controller.cluster.access.client.ClientActorContext;
12 import org.opendaylight.controller.cluster.datastore.utils.ActorUtils;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
14
15 /**
16  * {@link AbstractDataStoreClientBehavior} which performs module-based sharding.
17  *
18  * @author Robert Varga
19  */
20 final class DistributedDataStoreClientBehavior extends AbstractDataStoreClientBehavior {
21     private final ModuleShardBackendResolver resolver;
22
23     private DistributedDataStoreClientBehavior(final ClientActorContext context,
24             final ModuleShardBackendResolver resolver) {
25         super(context, resolver);
26         this.resolver = resolver;
27     }
28
29     DistributedDataStoreClientBehavior(final ClientActorContext context, final ActorUtils actorUtils) {
30         this(context, new ModuleShardBackendResolver(context.getIdentifier(), actorUtils));
31     }
32
33     @Override
34     Long resolveShardForPath(final YangInstanceIdentifier path) {
35         return resolver.resolveShardForPath(path);
36     }
37
38     @Override
39     Stream<Long> resolveAllShards() {
40         return resolver.resolveAllShards();
41     }
42
43     @Override
44     public void close() {
45         super.close();
46         resolver().close();
47     }
48 }