Bug 4105: Implement candidate registration close
[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.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;
19
20 /**
21  * Special Shard for EntityOwnership.
22  *
23  * @author Thomas Pantelis
24  */
25 public class EntityOwnershipShard extends Shard {
26
27     private static DatastoreContext noPersistenceDatastoreContext(DatastoreContext datastoreContext) {
28         return DatastoreContext.newBuilderFrom(datastoreContext).persistent(false).build();
29     }
30
31     protected EntityOwnershipShard(ShardIdentifier name, Map<String, String> peerAddresses,
32             DatastoreContext datastoreContext, SchemaContext schemaContext) {
33         super(name, peerAddresses, noPersistenceDatastoreContext(datastoreContext), schemaContext);
34     }
35
36     @Override
37     protected void onDatastoreContext(DatastoreContext context) {
38         super.onDatastoreContext(noPersistenceDatastoreContext(context));
39     }
40
41     @Override
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);
47         } else {
48             super.onReceiveCommand(message);
49         }
50     }
51
52     private void onRegisterCandidateLocal(RegisterCandidateLocal registerCandidate) {
53         // TODO - implement
54         getSender().tell(SuccessReply.INSTANCE, getSelf());
55     }
56
57     private void onUnregisterCandidateLocal(UnregisterCandidateLocal unregisterCandidate) {
58         // TODO - implement
59         getSender().tell(SuccessReply.INSTANCE, getSelf());
60     }
61
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));
65     }
66
67     private static class Creator extends AbstractShardCreator {
68         private static final long serialVersionUID = 1L;
69
70         Creator(final ShardIdentifier name, final Map<String, String> peerAddresses,
71                 final DatastoreContext datastoreContext, final SchemaContext schemaContext) {
72             super(name, peerAddresses, datastoreContext, schemaContext);
73         }
74
75         @Override
76         public Shard create() throws Exception {
77             return new EntityOwnershipShard(name, peerAddresses, datastoreContext, schemaContext);
78         }
79     }
80 }