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.datastore.actors.client;
10 import akka.actor.ActorRef;
11 import com.google.common.annotations.Beta;
12 import com.google.common.base.Preconditions;
13 import com.google.common.base.Ticker;
14 import javax.annotation.Nonnull;
15 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
16 import org.opendaylight.yangtools.concepts.Identifiable;
19 * An actor context associated with this {@link AbstractClientActor}.
21 * Time-keeping in a client actor is based on monotonic time. The precision of this time can be expected to be the
22 * same as {@link System#nanoTime()}, but it is not tied to that particular clock. Actor clock is exposed as
23 * a {@link Ticker}, which can be obtained via {@link #ticker()}.
25 * @author Robert Varga
28 public class ClientActorContext extends AbstractClientActorContext implements Identifiable<ClientIdentifier> {
29 private final ClientIdentifier identifier;
31 // Hidden to avoid subclassing
32 ClientActorContext(final ActorRef self, final String persistenceId, final ClientIdentifier identifier) {
33 super(self, persistenceId);
34 this.identifier = Preconditions.checkNotNull(identifier);
38 public @Nonnull ClientIdentifier getIdentifier() {
43 * Return the time ticker for this {@link ClientActorContext}. This should be used for in all time-tracking
44 * done within a client actor. Subclasses of {@link ClientActorBehavior} are encouraged to use
45 * {@link com.google.common.base.Stopwatch}.
47 * @return Client actor time source
49 public @Nonnull Ticker ticker() {
50 return Ticker.systemTicker();
54 * Execute a command in the context of the client actor.
56 * @param command Block of code which needs to be execute
58 public void executeInActor(final @Nonnull InternalCommand command) {
59 self().tell(Preconditions.checkNotNull(command), ActorRef.noSender());