From 4b3f30c8debb4a9065af47935405c4822ef9f6ae Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 13 Jan 2024 19:35:55 +0100 Subject: [PATCH] Expose uuid/instant from CommitInfo A particular commit can have an UUID or an Instant when it occurred, or both. Also this information is something we would like to include in Serializable contexts -- and therefore we promote CommitInfo to a non-Beta Serializable. JIRA: YANGTOOLS-1559 Change-Id: I1a2eb7f41484c4088e6ce310b3ab78a26022ad40 Signed-off-by: Robert Varga --- .../org/opendaylight/mdsal/common/api/CI.java | 3 +- .../mdsal/common/api/CommitInfo.java | 69 ++++++++++++++++++- 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/CI.java b/common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/CI.java index 7736b9e356..801235d60a 100644 --- a/common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/CI.java +++ b/common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/CI.java @@ -12,7 +12,6 @@ import com.google.common.base.MoreObjects; import com.google.common.util.concurrent.FluentFuture; import com.google.common.util.concurrent.Futures; import java.io.ObjectStreamException; -import java.io.Serializable; import java.time.Instant; import java.util.UUID; import org.eclipse.jdt.annotation.NonNull; @@ -20,7 +19,7 @@ import org.eclipse.jdt.annotation.NonNull; /** * Default {@link CommitInfo} implementation. */ -record CI(UUID uuid, Instant instant) implements CommitInfo, Serializable { +record CI(UUID uuid, Instant instant) implements CommitInfo { @java.io.Serial private static final long serialVersionUID = 0L; diff --git a/common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/CommitInfo.java b/common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/CommitInfo.java index 08a409c406..06c45f2b8e 100644 --- a/common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/CommitInfo.java +++ b/common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/CommitInfo.java @@ -7,18 +7,36 @@ */ package org.opendaylight.mdsal.common.api; -import com.google.common.annotations.Beta; +import static java.util.Objects.requireNonNull; + import com.google.common.util.concurrent.FluentFuture; +import java.io.Serializable; +import java.time.Instant; +import java.util.UUID; import org.eclipse.jdt.annotation.NonNullByDefault; +import org.eclipse.jdt.annotation.Nullable; /** * Base interface for tagging information about a successful commit. This can include various ways of identifying * the resulting changeset, timing information or any other piece of data about the commit itself the implementation * deems interesting to the client. */ -@Beta @NonNullByDefault -public interface CommitInfo { +public interface CommitInfo extends Serializable { + /** + * The {@link UUID} of the commit. + * + * @return the {@link UUID} of this commit + */ + @Nullable UUID uuid(); + + /** + * The {@link Instant} when the commit occurred. + * + * @return the {@link Instant} when the commit occurred + */ + @Nullable Instant instant(); + /** * Return an empty {@link CommitInfo}. * @@ -36,4 +54,49 @@ public interface CommitInfo { static FluentFuture emptyFluentFuture() { return CI.EMPTY_FUTURE; } + + /** + * Return a {@link CommitInfo} reporting specified {@link UUID}. + * + * @param uuid UUID to report + * @return a {@link CommitInfo} reporting specified {@link UUID} + * @throws NullPointerException if {@code uuid} is {@code null} + */ + static CommitInfo of(final UUID uuid) { + return new CI(requireNonNull(uuid), null); + } + + /** + * Return a {@link CommitInfo} reporting specified {@link Instant}. + * + * @param instant Instant to report + * @return a {@link CommitInfo} reporting specified {@link Instant} + * @throws NullPointerException if {@code instant} is {@code null} + */ + static CommitInfo of(final Instant instant) { + return new CI(null, requireNonNull(instant)); + } + + /** + * Return a {@link CommitInfo} reporting specified {@link UUID} and {@link Instant}. + * + * @param uuid UUID to report + * @param instant Instant to report + * @return a {@link CommitInfo} reporting specified {@link UUID} and {@link Instant} + * @throws NullPointerException if any argument is {@code null} + */ + static CommitInfo of(final UUID uuid, final Instant instant) { + return new CI(requireNonNull(uuid), requireNonNull(instant)); + } + + /** + * Return a {@link CommitInfo} reporting optional {@link UUID} and {@link Instant}. + * + * @param uuid UUID to report + * @param instant Instant to report + * @return a {@link CommitInfo} reporting optional {@link UUID} and {@link Instant} + */ + static CommitInfo ofNullable(final @Nullable UUID uuid, final @Nullable Instant instant) { + return CI.of(uuid, instant); + } } -- 2.36.6