792b5b31c1cadef2ce9c3c6575e9b9963cf36686
[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.function.Function;
11 import org.opendaylight.controller.cluster.access.client.ClientActorContext;
12 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
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 Function<YangInstanceIdentifier, Long> pathToShard;
22
23     private DistributedDataStoreClientBehavior(final ClientActorContext context,
24             final ModuleShardBackendResolver resolver) {
25         super(context, resolver);
26         pathToShard = resolver::resolveShardForPath;
27     }
28
29     DistributedDataStoreClientBehavior(final ClientActorContext context, final ActorContext actorContext) {
30         this(context, new ModuleShardBackendResolver(context.getIdentifier(), actorContext));
31     }
32
33     @Override
34     Long resolveShardForPath(final YangInstanceIdentifier path) {
35         return pathToShard.apply(path);
36     }
37
38     @Override
39     public void close() {
40         super.close();
41         resolver().close();
42     }
43 }