2 * Copyright (c) 2015 Brocade Communications Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.datastore.entityownership;
10 import akka.actor.Props;
12 import org.opendaylight.controller.cluster.datastore.DatastoreContext;
13 import org.opendaylight.controller.cluster.datastore.Shard;
14 import org.opendaylight.controller.cluster.datastore.entityownership.messages.RegisterCandidateLocal;
15 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
16 import org.opendaylight.controller.cluster.datastore.messages.SuccessReply;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 * Special Shard for EntityOwnership.
22 * @author Thomas Pantelis
24 public class EntityOwnershipShard extends Shard {
26 private static DatastoreContext noPersistenceDatastoreContext(DatastoreContext datastoreContext) {
27 return DatastoreContext.newBuilderFrom(datastoreContext).persistent(false).build();
30 protected EntityOwnershipShard(ShardIdentifier name, Map<String, String> peerAddresses,
31 DatastoreContext datastoreContext, SchemaContext schemaContext) {
32 super(name, peerAddresses, noPersistenceDatastoreContext(datastoreContext), schemaContext);
36 protected void onDatastoreContext(DatastoreContext context) {
37 super.onDatastoreContext(noPersistenceDatastoreContext(context));
41 public void onReceiveCommand(final Object message) throws Exception {
42 if(message instanceof RegisterCandidateLocal) {
43 onRegisterCandidateLocal((RegisterCandidateLocal)message);
45 super.onReceiveCommand(message);
49 private void onRegisterCandidateLocal(RegisterCandidateLocal registerCandidate) {
50 getSender().tell(SuccessReply.INSTANCE, getSelf());
53 public static Props props(final ShardIdentifier name, final Map<String, String> peerAddresses,
54 final DatastoreContext datastoreContext, final SchemaContext schemaContext) {
55 return Props.create(new Creator(name, peerAddresses, datastoreContext, schemaContext));
58 private static class Creator extends AbstractShardCreator {
59 private static final long serialVersionUID = 1L;
61 Creator(final ShardIdentifier name, final Map<String, String> peerAddresses,
62 final DatastoreContext datastoreContext, final SchemaContext schemaContext) {
63 super(name, peerAddresses, datastoreContext, schemaContext);
67 public Shard create() throws Exception {
68 return new EntityOwnershipShard(name, peerAddresses, datastoreContext, schemaContext);