2 * Copyright (c) 2016 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
8 package org.opendaylight.controller.cluster.databroker.actors.dds;
10 import akka.actor.ActorRef;
11 import akka.actor.Props;
12 import akka.util.Timeout;
13 import com.google.common.base.Preconditions;
14 import com.google.common.base.Throwables;
15 import java.util.concurrent.TimeUnit;
16 import javax.annotation.Nonnull;
17 import org.opendaylight.controller.cluster.access.client.AbstractClientActor;
18 import org.opendaylight.controller.cluster.access.client.ClientActorContext;
19 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
20 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
21 import org.opendaylight.controller.cluster.access.concepts.MemberName;
22 import org.opendaylight.controller.cluster.common.actor.ExplicitAsk;
23 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
24 import scala.Function1;
25 import scala.concurrent.Await;
26 import scala.concurrent.duration.Duration;
29 * A {@link AbstractClientActor} which acts as the point of contact for DistributedDataStore.
31 * @author Robert Varga
33 public final class DistributedDataStoreClientActor extends AbstractClientActor {
34 private static final Function1<ActorRef, ?> GET_CLIENT_FACTORY = ExplicitAsk.toScala(t -> new GetClientRequest(t));
36 private final ActorContext actorContext;
38 private DistributedDataStoreClientActor(final FrontendIdentifier frontendId, final ActorContext actorContext) {
40 this.actorContext = Preconditions.checkNotNull(actorContext);
44 protected DistributedDataStoreClientBehavior initialBehavior(final ClientActorContext context) {
45 return new DistributedDataStoreClientBehavior(context, actorContext);
48 public static Props props(final @Nonnull MemberName memberName, @Nonnull final String storeName, final ActorContext ctx) {
49 final String name = "datastore-" + storeName;
50 final FrontendIdentifier frontendId = FrontendIdentifier.create(memberName, FrontendType.forName(name));
51 return Props.create(DistributedDataStoreClientActor.class,
52 () -> new DistributedDataStoreClientActor(frontendId, ctx));
55 public static DistributedDataStoreClient getDistributedDataStoreClient(final @Nonnull ActorRef actor,
56 final long timeout, final TimeUnit unit) {
58 return (DistributedDataStoreClient) Await.result(ExplicitAsk.ask(actor, GET_CLIENT_FACTORY,
59 Timeout.apply(timeout, unit)), Duration.Inf());
60 } catch (Exception e) {
61 throw Throwables.propagate(e);