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.access.commands;
10 import java.io.DataInput;
11 import java.io.DataOutput;
12 import java.io.IOException;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.concepts.WritableObject;
17 * Enumeration of transaction persistence protocols. These govern which protocol is executed between the frontend
18 * and backend to drive persistence of a particular transaction.
20 public enum PersistenceProtocol implements WritableObject {
22 * Abort protocol. The transaction has been aborted on the frontend and its effects should not be visible
23 * in the global history. This is a simple request/reply protocol.
32 * Simple commit protocol. The transaction should be committed to the global history. The receiving backend
33 * is the only entity which needs to persist its effects, hence a simple request/reply protocol is sufficient.
42 * Three-phase commit protocol (3PC). The transaction should be committed to the global history, but it is a part
43 * of a transaction spanning multiple entities and coordination is needed to drive persistence.
52 * Transaction is ready. This is not a really a persistence protocol, but an indication that frontend has
53 * completed modifications on the transaction and considers it ready, without deciding the actual commit protocol.
63 public final void writeTo(final DataOutput out) throws IOException {
64 out.writeByte(byteValue());
67 public static PersistenceProtocol readFrom(final DataInput in) throws IOException {
68 return valueOf(in.readByte());
71 abstract byte byteValue();
73 static int byteValue(final PersistenceProtocol finish) {
74 return finish == null ? 0 : finish.byteValue();
77 static @Nullable PersistenceProtocol valueOf(final byte value) {
78 return switch (value) {
82 case 3 -> THREE_PHASE;
84 default -> throw new IllegalArgumentException("Unhandled byte value " + value);