BUG-5280: handle TransactionPurgeRequest replay
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / SimpleDataStoreClientActor.java
1 /*
2  * Copyright (c) 2016 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 package org.opendaylight.controller.cluster.databroker.actors.dds;
9
10 import akka.actor.Props;
11 import com.google.common.base.Preconditions;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.controller.cluster.access.client.AbstractClientActor;
14 import org.opendaylight.controller.cluster.access.client.ClientActorContext;
15 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
16 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
17 import org.opendaylight.controller.cluster.access.concepts.MemberName;
18 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
19
20 /**
21  * A {@link AbstractClientActor} which acts as the point of contact for DistributedDataStore.
22  *
23  * @author Robert Varga
24  */
25 public final class SimpleDataStoreClientActor extends AbstractDataStoreClientActor {
26     private final String shardName;
27
28     private SimpleDataStoreClientActor(final FrontendIdentifier frontendId, final ActorContext actorContext,
29             final String shardName) {
30         super(frontendId, actorContext);
31         this.shardName = Preconditions.checkNotNull(shardName);
32     }
33
34     @Override
35     AbstractDataStoreClientBehavior initialBehavior(final ClientActorContext context, final ActorContext actorContext) {
36         return new SimpleDataStoreClientBehavior(context, actorContext, shardName);
37     }
38
39     public static Props props(@Nonnull final MemberName memberName, @Nonnull final String storeName,
40             final ActorContext ctx, final String shardName) {
41         final String name = "datastore-" + storeName;
42         final FrontendIdentifier frontendId = FrontendIdentifier.create(memberName, FrontendType.forName(name));
43         return Props.create(SimpleDataStoreClientActor.class,
44             () -> new SimpleDataStoreClientActor(frontendId, ctx, shardName));
45     }
46 }