--- /dev/null
+/*
+ * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
+ * Copyright (c) 2024 PANTHEON.tech, s.r.o.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.common.api;
+
+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;
+
+/**
+ * Default {@link CommitInfo} implementation.
+ */
+record CI(UUID uuid, Instant instant) implements CommitInfo, Serializable {
+ @java.io.Serial
+ private static final long serialVersionUID = 0L;
+
+ static final @NonNull CI EMPTY = new CI(null, null);
+ static final @NonNull FluentFuture<@NonNull CommitInfo> EMPTY_FUTURE =
+ FluentFuture.from(Futures.immediateFuture(EMPTY));
+
+ static @NonNull CI of(final UUID uuid, final Instant time) {
+ return time != null || uuid != null ? new CI(uuid, time) : EMPTY;
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects.toStringHelper(CommitInfo.class).omitNullValues()
+ .add("uuid", uuid)
+ .add("instant", instant)
+ .toString();
+ }
+
+ @java.io.Serial
+ private Object readResolve() throws ObjectStreamException {
+ return instant != null || uuid != null ? this : EMPTY;
+ }
+}
* 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.
- *
- * @author Robert Varga
*/
@Beta
@NonNullByDefault
* @return An empty {@link CommitInfo} instance.
*/
static CommitInfo empty() {
- return EmptyCommitInfo.INSTANCE;
+ return CI.EMPTY;
}
/**
* @return An empty {@link CommitInfo} instance enclosed in a completed future.
*/
static FluentFuture<CommitInfo> emptyFluentFuture() {
- return EmptyCommitInfo.FLUENT_INSTANCE;
+ return CI.EMPTY_FUTURE;
}
}
+++ /dev/null
-/*
- * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.mdsal.common.api;
-
-import com.google.common.util.concurrent.FluentFuture;
-import org.eclipse.jdt.annotation.NonNullByDefault;
-import org.opendaylight.yangtools.util.concurrent.FluentFutures;
-
-/**
- * Empty commit info singleton. Useful when {@link AsyncWriteTransaction#commit()} has nothing more to say.
- *
- * @author Robert Varga
- */
-@NonNullByDefault
-final class EmptyCommitInfo implements CommitInfo {
- static final CommitInfo INSTANCE = new EmptyCommitInfo();
- static final FluentFuture<CommitInfo> FLUENT_INSTANCE = FluentFutures.immediateFluentFuture(INSTANCE);
-
- private EmptyCommitInfo() {
- // Hidden
- }
-}
class CommitInfoTest {
@Test
void testEmpty() {
- assertSame(EmptyCommitInfo.INSTANCE, CommitInfo.empty());
+ assertSame(CI.EMPTY, CommitInfo.empty());
}
@Test
void testEmptyFluentFuture() {
- assertSame(EmptyCommitInfo.FLUENT_INSTANCE, CommitInfo.emptyFluentFuture());
+ assertSame(CI.EMPTY_FUTURE, CommitInfo.emptyFluentFuture());
}
}
class EmptyCommitInfoTest {
@Test
void testFuture() throws Exception {
- final var future = EmptyCommitInfo.FLUENT_INSTANCE;
+ final var future = CI.EMPTY_FUTURE;
assertTrue(future.isDone());
- assertSame(EmptyCommitInfo.INSTANCE, Futures.getDone(future));
+ assertSame(CI.EMPTY, Futures.getDone(future));
}
}