Cleanup warnings
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / main / java / org / opendaylight / controller / cluster / databroker / actors / dds / AbstractDataStoreClientActor.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.ActorRef;
11 import akka.util.Timeout;
12 import com.google.common.base.Preconditions;
13 import com.google.common.base.Verify;
14 import java.util.concurrent.TimeUnit;
15 import javax.annotation.Nonnull;
16 import org.opendaylight.controller.cluster.access.client.AbstractClientActor;
17 import org.opendaylight.controller.cluster.access.client.ClientActorConfig;
18 import org.opendaylight.controller.cluster.access.client.ClientActorContext;
19 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
20 import org.opendaylight.controller.cluster.common.actor.ExplicitAsk;
21 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
22 import scala.Function1;
23 import scala.concurrent.Await;
24 import scala.concurrent.duration.Duration;
25
26 public abstract class AbstractDataStoreClientActor extends AbstractClientActor {
27     private static final Function1<ActorRef, ?> GET_CLIENT_FACTORY = ExplicitAsk.toScala(GetClientRequest::new);
28
29     private final ActorContext actorContext;
30
31     AbstractDataStoreClientActor(final FrontendIdentifier frontendId, final ActorContext actorContext) {
32         super(frontendId);
33         this.actorContext = Preconditions.checkNotNull(actorContext);
34     }
35
36     @Override
37     protected ClientActorConfig getClientActorConfig() {
38         return actorContext.getDatastoreContext();
39     }
40
41     @Override
42     protected final AbstractDataStoreClientBehavior initialBehavior(final ClientActorContext context) {
43         return Verify.verifyNotNull(initialBehavior(context, actorContext));
44     }
45
46     abstract AbstractDataStoreClientBehavior initialBehavior(ClientActorContext context, ActorContext actorContext);
47
48     @SuppressWarnings("checkstyle:IllegalCatch")
49     public static DataStoreClient getDistributedDataStoreClient(@Nonnull final ActorRef actor,
50             final long timeout, final TimeUnit unit) {
51         try {
52             return (DataStoreClient) Await.result(ExplicitAsk.ask(actor, GET_CLIENT_FACTORY,
53                 Timeout.apply(timeout, unit)), Duration.Inf());
54         } catch (RuntimeException e) {
55             throw e;
56         } catch (Exception e) {
57             throw new RuntimeException(e);
58         }
59     }
60 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.