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.entityownership.messages.UnregisterCandidateLocal;
16 import org.opendaylight.controller.cluster.datastore.identifiers.ShardIdentifier;
17 import org.opendaylight.controller.cluster.datastore.messages.SuccessReply;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 * Special Shard for EntityOwnership.
23 * @author Thomas Pantelis
25 public class EntityOwnershipShard extends Shard {
27 private static DatastoreContext noPersistenceDatastoreContext(DatastoreContext datastoreContext) {
28 return DatastoreContext.newBuilderFrom(datastoreContext).persistent(false).build();
31 protected EntityOwnershipShard(ShardIdentifier name, Map<String, String> peerAddresses,
32 DatastoreContext datastoreContext, SchemaContext schemaContext) {
33 super(name, peerAddresses, noPersistenceDatastoreContext(datastoreContext), schemaContext);
37 protected void onDatastoreContext(DatastoreContext context) {
38 super.onDatastoreContext(noPersistenceDatastoreContext(context));
42 public void onReceiveCommand(final Object message) throws Exception {
43 if(message instanceof RegisterCandidateLocal) {
44 onRegisterCandidateLocal((RegisterCandidateLocal)message);
45 } else if(message instanceof UnregisterCandidateLocal) {
46 onUnregisterCandidateLocal((UnregisterCandidateLocal)message);
48 super.onReceiveCommand(message);
52 private void onRegisterCandidateLocal(RegisterCandidateLocal registerCandidate) {
54 getSender().tell(SuccessReply.INSTANCE, getSelf());
57 private void onUnregisterCandidateLocal(UnregisterCandidateLocal unregisterCandidate) {
59 getSender().tell(SuccessReply.INSTANCE, getSelf());
62 public static Props props(final ShardIdentifier name, final Map<String, String> peerAddresses,
63 final DatastoreContext datastoreContext, final SchemaContext schemaContext) {
64 return Props.create(new Creator(name, peerAddresses, datastoreContext, schemaContext));
67 private static class Creator extends AbstractShardCreator {
68 private static final long serialVersionUID = 1L;
70 Creator(final ShardIdentifier name, final Map<String, String> peerAddresses,
71 final DatastoreContext datastoreContext, final SchemaContext schemaContext) {
72 super(name, peerAddresses, datastoreContext, schemaContext);
76 public Shard create() throws Exception {
77 return new EntityOwnershipShard(name, peerAddresses, datastoreContext, schemaContext);