BUG-5280: fix InversibleLock race
[controller.git] / opendaylight / md-sal / cds-access-client / src / main / java / org / opendaylight / controller / cluster / access / client / InitialClientActorContext.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.access.client;
9
10 import akka.actor.ActorSystem;
11 import akka.persistence.SnapshotSelectionCriteria;
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
14
15 /**
16  * The initial context for an actor.
17  *
18  * @author Robert Varga
19  */
20 final class InitialClientActorContext extends AbstractClientActorContext {
21     private final AbstractClientActor actor;
22
23     InitialClientActorContext(final AbstractClientActor actor, final String persistenceId) {
24         super(actor.self(), persistenceId);
25         this.actor = Preconditions.checkNotNull(actor);
26     }
27
28     void saveSnapshot(final ClientIdentifier snapshot) {
29         actor.saveSnapshot(snapshot);
30     }
31
32     void deleteSnapshots(final SnapshotSelectionCriteria criteria) {
33         actor.deleteSnapshots(criteria);
34     }
35
36     ClientActorBehavior<?> createBehavior(final ClientIdentifier clientId) {
37         final ActorSystem system = actor.getContext().system();
38         final ClientActorContext context = new ClientActorContext(self(), system.scheduler(), system.dispatcher(),
39             persistenceId(), clientId);
40
41         return actor.initialBehavior(context);
42     }
43
44     void stash() {
45         actor.stash();
46     }
47
48     void unstash() {
49         actor.unstashAll();
50     }
51 }