2 * Copyright (c) 2014 Cisco 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
9 package org.opendaylight.controller.cluster.datastore;
11 import akka.actor.ActorRef;
12 import akka.actor.ActorSystem;
13 import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListener;
14 import org.opendaylight.controller.cluster.datastore.messages.RegisterChangeListenerReply;
15 import org.opendaylight.controller.cluster.datastore.messages.UpdateSchemaContext;
16 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
17 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
18 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
19 import org.opendaylight.controller.sal.core.spi.data.DOMStore;
20 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
21 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadWriteTransaction;
22 import org.opendaylight.controller.sal.core.spi.data.DOMStoreTransactionChain;
23 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
24 import org.opendaylight.yangtools.concepts.ListenerRegistration;
25 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
26 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
35 public class DistributedDataStore implements DOMStore, SchemaContextListener {
37 private static final Logger
38 LOG = LoggerFactory.getLogger(DistributedDataStore.class);
41 private final String type;
42 private final ActorContext actorContext;
44 public DistributedDataStore(ActorSystem actorSystem, String type) {
45 this(new ActorContext(actorSystem, actorSystem.actorOf(ShardManager.props(type))), type);
48 public DistributedDataStore(ActorContext actorContext, String type) {
50 this.actorContext = actorContext;
55 public <L extends AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>>> ListenerRegistration<L> registerChangeListener(
56 InstanceIdentifier path, L listener,
57 AsyncDataBroker.DataChangeScope scope) {
59 ActorRef dataChangeListenerActor = actorContext.getActorSystem().actorOf(DataChangeListener.props());
61 Object result = actorContext.executeShardOperation(Shard.DEFAULT_NAME,
62 new RegisterChangeListener(path, dataChangeListenerActor.path(),
63 AsyncDataBroker.DataChangeScope.BASE),
64 ActorContext.ASK_DURATION);
66 RegisterChangeListenerReply reply = (RegisterChangeListenerReply) result;
67 return new ListenerRegistrationProxy(reply.getListenerRegistrationPath());
73 public DOMStoreTransactionChain createTransactionChain() {
74 return new TransactionChainProxy(actorContext);
78 public DOMStoreReadTransaction newReadOnlyTransaction() {
79 return new TransactionProxy(actorContext, TransactionProxy.TransactionType.READ_ONLY);
83 public DOMStoreWriteTransaction newWriteOnlyTransaction() {
84 return new TransactionProxy(actorContext, TransactionProxy.TransactionType.WRITE_ONLY);
88 public DOMStoreReadWriteTransaction newReadWriteTransaction() {
89 return new TransactionProxy(actorContext, TransactionProxy.TransactionType.READ_WRITE);
92 @Override public void onGlobalContextUpdated(SchemaContext schemaContext) {
93 actorContext.getShardManager().tell(new UpdateSchemaContext(schemaContext), null);