Bug 4105: Add EntityOwnershipShard
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / datastore / entityownership / EntityOwnershipShard.java
1 /*
2  * Copyright (c) 2015 Brocade Communications 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.datastore.entityownership;
9
10 import akka.actor.Props;
11 import java.util.Map;
12 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
13 import org.opendaylight.controller.cluster.datastore.Shard;
14 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
15 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
16
17 /**
18  * Special Shard for EntityOwnership.
19  *
20  * @author Thomas Pantelis
21  */
22 public class EntityOwnershipShard extends Shard {
23
24     private static DatastoreContext noPersistenceDatastoreContext(DatastoreContext datastoreContext) {
25         return DatastoreContext.newBuilderFrom(datastoreContext).persistent(false).build();
26     }
27
28     protected EntityOwnershipShard(ShardIdentifier name, Map<String, String> peerAddresses,
29             DatastoreContext datastoreContext, SchemaContext schemaContext) {
30         super(name, peerAddresses, noPersistenceDatastoreContext(datastoreContext), schemaContext);
31     }
32
33     @Override
34     protected void onDatastoreContext(DatastoreContext context) {
35         super.onDatastoreContext(noPersistenceDatastoreContext(context));
36     }
37
38     public static Props props(final ShardIdentifier name, final Map<String, String> peerAddresses,
39             final DatastoreContext datastoreContext, final SchemaContext schemaContext) {
40         return Props.create(new Creator(name, peerAddresses, datastoreContext, schemaContext));
41     }
42
43     private static class Creator extends AbstractShardCreator {
44         private static final long serialVersionUID = 1L;
45
46         Creator(final ShardIdentifier name, final Map<String, String> peerAddresses,
47                 final DatastoreContext datastoreContext, final SchemaContext schemaContext) {
48             super(name, peerAddresses, datastoreContext, schemaContext);
49         }
50
51         @Override
52         public Shard create() throws Exception {
53             return new EntityOwnershipShard(name, peerAddresses, datastoreContext, schemaContext);
54         }
55     }
56 }