X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fcds-access-client%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Faccess%2Fclient%2FClientActorContext.java;h=0864da10b06272c892f67d50aac9e8831e45b0d9;hp=3ed207ef6f393c5b84b8c4641b39099758d7df57;hb=62cddd88e42e8f3c6a92bbf42c97b0d6806f44ae;hpb=b5db7d0971de9d84289bc4e46ed7aad1f014a41a diff --git a/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/ClientActorContext.java b/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/ClientActorContext.java index 3ed207ef6f..0864da10b0 100644 --- a/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/ClientActorContext.java +++ b/opendaylight/md-sal/cds-access-client/src/main/java/org/opendaylight/controller/cluster/access/client/ClientActorContext.java @@ -7,17 +7,20 @@ */ package org.opendaylight.controller.cluster.access.client; +import static java.util.Objects.requireNonNull; + import akka.actor.ActorRef; import akka.actor.ActorSystem; import akka.actor.Cancellable; import akka.actor.Scheduler; import com.google.common.annotations.Beta; -import com.google.common.base.Preconditions; import com.google.common.base.Ticker; -import javax.annotation.Nonnull; -import javax.annotation.concurrent.ThreadSafe; +import java.util.concurrent.TimeUnit; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier; import org.opendaylight.controller.cluster.common.actor.Dispatchers; +import org.opendaylight.controller.cluster.io.FileBackedOutputStreamFactory; +import org.opendaylight.controller.cluster.messaging.MessageSlicer; import org.opendaylight.yangtools.concepts.Identifiable; import scala.concurrent.ExecutionContext; import scala.concurrent.duration.FiniteDuration; @@ -28,46 +31,52 @@ import scala.concurrent.duration.FiniteDuration; *

* Time-keeping in a client actor is based on monotonic time. The precision of this time can be expected to be the * same as {@link System#nanoTime()}, but it is not tied to that particular clock. Actor clock is exposed as - * a {@link Ticker}, which can be obtained via {@link #ticker()}. + * a {@link Ticker}, which can be obtained via {@link #ticker()}. This class is thread-safe. * * @author Robert Varga */ @Beta -@ThreadSafe public class ClientActorContext extends AbstractClientActorContext implements Identifiable { private final ExecutionContext executionContext; private final ClientIdentifier identifier; private final Scheduler scheduler; private final Dispatchers dispatchers; private final ClientActorConfig config; + private final MessageSlicer messageSlicer; // Hidden to avoid subclassing ClientActorContext(final ActorRef self, final String persistenceId, final ActorSystem system, final ClientIdentifier identifier, final ClientActorConfig config) { super(self, persistenceId); - this.identifier = Preconditions.checkNotNull(identifier); - this.scheduler = Preconditions.checkNotNull(system).scheduler(); + this.identifier = requireNonNull(identifier); + this.scheduler = requireNonNull(system).scheduler(); this.executionContext = system.dispatcher(); this.dispatchers = new Dispatchers(system.dispatchers()); - this.config = Preconditions.checkNotNull(config); + this.config = requireNonNull(config); + + messageSlicer = MessageSlicer.builder().messageSliceSize(config.getMaximumMessageSliceSize()) + .logContext(persistenceId).expireStateAfterInactivity(config.getRequestTimeout(), TimeUnit.NANOSECONDS) + .fileBackedStreamFactory(new FileBackedOutputStreamFactory(config.getFileBackedStreamingThreshold(), + config.getTempFileDirectory())).build(); } @Override - @Nonnull public ClientIdentifier getIdentifier() { return identifier; } - @Nonnull - public ClientActorConfig config() { + public @NonNull ClientActorConfig config() { return config; } - @Nonnull - public Dispatchers dispatchers() { + public @NonNull Dispatchers dispatchers() { return dispatchers; } + public @NonNull MessageSlicer messageSlicer() { + return messageSlicer; + } + /** * Return the time ticker for this {@link ClientActorContext}. This should be used for in all time-tracking * done within a client actor. Subclasses of {@link ClientActorBehavior} are encouraged to use @@ -75,8 +84,7 @@ public class ClientActorContext extends AbstractClientActorContext implements Id * * @return Client actor time source */ - @Nonnull - public Ticker ticker() { + public @NonNull Ticker ticker() { return Ticker.systemTicker(); } @@ -86,13 +94,13 @@ public class ClientActorContext extends AbstractClientActorContext implements Id * @param command Block of code which needs to be execute * @param BackendInfo type */ - public void executeInActor(@Nonnull final InternalCommand command) { - self().tell(Preconditions.checkNotNull(command), ActorRef.noSender()); + public void executeInActor(final @NonNull InternalCommand command) { + self().tell(requireNonNull(command), ActorRef.noSender()); } - public Cancellable executeInActor(@Nonnull final InternalCommand command, + public Cancellable executeInActor(final @NonNull InternalCommand command, final FiniteDuration delay) { - return scheduler.scheduleOnce(Preconditions.checkNotNull(delay), self(), Preconditions.checkNotNull(command), + return scheduler.scheduleOnce(requireNonNull(delay), self(), requireNonNull(command), executionContext, ActorRef.noSender()); } }