X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-clustering-commons%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fmessaging%2FMessageAssembler.java;h=2b41bc595fad01f98f0969425fa11830316714f6;hb=HEAD;hp=87f0e9890ecbc71fdad7e4549899e04e28e2fd12;hpb=2d60632f7cf63712e8357a3cf3fc40d83366e5e6;p=controller.git diff --git a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/messaging/MessageAssembler.java b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/messaging/MessageAssembler.java index 87f0e9890e..2b41bc595f 100644 --- a/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/messaging/MessageAssembler.java +++ b/opendaylight/md-sal/sal-clustering-commons/src/main/java/org/opendaylight/controller/cluster/messaging/MessageAssembler.java @@ -7,12 +7,13 @@ */ package org.opendaylight.controller.cluster.messaging; +import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Objects.requireNonNull; + import akka.actor.ActorRef; import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import com.google.common.cache.RemovalListener; import com.google.common.cache.RemovalNotification; import com.google.common.io.ByteSource; import java.io.IOException; @@ -20,7 +21,7 @@ import java.io.ObjectInputStream; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.function.BiConsumer; -import javax.annotation.Nonnull; +import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.controller.cluster.io.FileBackedOutputStreamFactory; import org.opendaylight.yangtools.concepts.Identifier; import org.slf4j.Logger; @@ -41,16 +42,15 @@ public final class MessageAssembler implements AutoCloseable { private final String logContext; MessageAssembler(final Builder builder) { - this.fileBackedStreamFactory = Preconditions.checkNotNull(builder.fileBackedStreamFactory, + fileBackedStreamFactory = requireNonNull(builder.fileBackedStreamFactory, "FiledBackedStreamFactory cannot be null"); - this.assembledMessageCallback = Preconditions.checkNotNull(builder.assembledMessageCallback, + assembledMessageCallback = requireNonNull(builder.assembledMessageCallback, "assembledMessageCallback cannot be null"); - this.logContext = builder.logContext; + logContext = builder.logContext; stateCache = CacheBuilder.newBuilder() .expireAfterAccess(builder.expireStateAfterInactivityDuration, builder.expireStateAfterInactivityUnit) - .removalListener((RemovalListener) notification -> - stateRemoved(notification)).build(); + .removalListener(this::stateRemoved).build(); } /** @@ -96,14 +96,14 @@ public final class MessageAssembler implements AutoCloseable { * @param sendTo the reference of the actor to which subsequent message slices should be sent * @return true if the message was handled, false otherwise */ - public boolean handleMessage(final Object message, final @Nonnull ActorRef sendTo) { - if (message instanceof MessageSlice) { - LOG.debug("{}: handleMessage: {}", logContext, message); - onMessageSlice((MessageSlice) message, sendTo); + public boolean handleMessage(final Object message, final @NonNull ActorRef sendTo) { + if (message instanceof MessageSlice messageSlice) { + LOG.debug("{}: handleMessage: {}", logContext, messageSlice); + onMessageSlice(messageSlice, sendTo); return true; - } else if (message instanceof AbortSlicing) { - LOG.debug("{}: handleMessage: {}", logContext, message); - onAbortSlicing((AbortSlicing) message); + } else if (message instanceof AbortSlicing abortSlicing) { + LOG.debug("{}: handleMessage: {}", logContext, abortSlicing); + onAbortSlicing(abortSlicing); return true; } @@ -116,14 +116,9 @@ public final class MessageAssembler implements AutoCloseable { final AssembledMessageState state = stateCache.get(identifier, () -> createState(messageSlice)); processMessageSliceForState(messageSlice, state, sendTo); } catch (ExecutionException e) { - final MessageSliceException messageSliceEx; final Throwable cause = e.getCause(); - if (cause instanceof MessageSliceException) { - messageSliceEx = (MessageSliceException) cause; - } else { - messageSliceEx = new MessageSliceException(String.format( - "Error creating state for identifier %s", identifier), cause); - } + final MessageSliceException messageSliceEx = cause instanceof MessageSliceException sliceEx ? sliceEx + : new MessageSliceException(String.format("Error creating state for identifier %s", identifier), cause); messageSlice.getReplyTo().tell(MessageSliceReply.failed(identifier, messageSliceEx, sendTo), ActorRef.noSender()); @@ -231,7 +226,7 @@ public final class MessageAssembler implements AutoCloseable { * @return this Builder */ public Builder fileBackedStreamFactory(final FileBackedOutputStreamFactory newFileBackedStreamFactory) { - this.fileBackedStreamFactory = Preconditions.checkNotNull(newFileBackedStreamFactory); + fileBackedStreamFactory = requireNonNull(newFileBackedStreamFactory); return this; } @@ -243,7 +238,7 @@ public final class MessageAssembler implements AutoCloseable { * @return this Builder */ public Builder assembledMessageCallback(final BiConsumer newAssembledMessageCallback) { - this.assembledMessageCallback = newAssembledMessageCallback; + assembledMessageCallback = newAssembledMessageCallback; return this; } @@ -257,9 +252,9 @@ public final class MessageAssembler implements AutoCloseable { * @return this Builder */ public Builder expireStateAfterInactivity(final long duration, final TimeUnit unit) { - Preconditions.checkArgument(duration > 0, "duration must be > 0"); - this.expireStateAfterInactivityDuration = duration; - this.expireStateAfterInactivityUnit = unit; + checkArgument(duration > 0, "duration must be > 0"); + expireStateAfterInactivityDuration = duration; + expireStateAfterInactivityUnit = unit; return this; } @@ -270,7 +265,7 @@ public final class MessageAssembler implements AutoCloseable { * @return this Builder */ public Builder logContext(final String newLogContext) { - this.logContext = newLogContext; + logContext = newLogContext; return this; }