Dummy Distributed Data Store for testing replication
[controller.git] / opendaylight / md-sal / sal-dummy-distributed-datastore / src / main / java / org / opendaylight / controller / dummy / datastore / DummyShardManager.java
1 /*
2  * Copyright (c) 2014 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
9 package org.opendaylight.controller.dummy.datastore;
10
11 import akka.actor.ActorContext;
12 import akka.actor.Props;
13 import akka.actor.UntypedActor;
14 import akka.japi.Creator;
15
16 public class DummyShardManager extends UntypedActor {
17     public DummyShardManager(Configuration configuration, String memberName, String[] shardNames, String type) throws Exception {
18         new DummyShardsCreator(configuration, context(), memberName, shardNames, type).create();
19     }
20
21     @Override
22     public void onReceive(Object o) throws Exception {
23
24     }
25
26     public static Props props(Configuration configuration, String memberName, String[] shardNames, String type){
27         return Props.create(new DummyShardManagerCreator(configuration, memberName, shardNames, type));
28     }
29
30     private static class DummyShardManagerCreator implements Creator<DummyShardManager> {
31
32         private final Configuration configuration;
33         private final String memberName;
34         private final String[] shardNames;
35         private final String type;
36
37         public DummyShardManagerCreator(Configuration configuration, String memberName, String[] shardNames, String type) {
38             this.configuration = configuration;
39             this.memberName = memberName;
40             this.shardNames = shardNames;
41             this.type = type;
42         }
43
44         @Override
45         public DummyShardManager create() throws Exception {
46             return new DummyShardManager(configuration, memberName, shardNames, type );
47         }
48     }
49
50     private static class DummyShardsCreator {
51         private final Configuration configuration;
52         private final ActorContext actorSystem;
53         private final String memberName;
54         private final String[] shardNames;
55         private final String type;
56
57         DummyShardsCreator(Configuration configuration, ActorContext actorSystem, String memberName, String[] shardNames, String type){
58             this.configuration = configuration;
59             this.actorSystem = actorSystem;
60             this.memberName = memberName;
61             this.shardNames = shardNames;
62             this.type = type;
63         }
64
65         void create(){
66             for(String shardName : shardNames){
67                 String shardId = memberName + "-shard-" + shardName + "-" + type;
68                 actorSystem.actorOf(DummyShard.props(configuration, shardId), shardId);
69             }
70         }
71     }
72 }