5a10036373de463a6a3425a1a666ef3df9be9cea
[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  *
17  * @author Robert Varga
18  */
19 final class InitialClientActorContext extends AbstractClientActorContext {
20     private final AbstractClientActor actor;
21
22     InitialClientActorContext(final AbstractClientActor actor, final String persistenceId) {
23         super(actor.self(), persistenceId);
24         this.actor = Preconditions.checkNotNull(actor);
25     }
26
27     void saveSnapshot(final ClientIdentifier snapshot) {
28         actor.saveSnapshot(snapshot);
29     }
30
31     void deleteSnapshots(SnapshotSelectionCriteria criteria) {
32         actor.deleteSnapshots(criteria);
33     }
34
35     ClientActorBehavior createBehavior(final ClientIdentifier clientId) {
36         final ActorSystem system = actor.getContext().system();
37         final ClientActorContext context = new ClientActorContext(self(), system.scheduler(), system.dispatcher(),
38             persistenceId(), clientId);
39
40         return actor.initialBehavior(context);
41     }
42
43     void stash() {
44         actor.stash();
45     }
46
47     void unstash() {
48         actor.unstashAll();
49     }
50 }