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.datastore;
10 import com.google.common.base.Preconditions;
11 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
12 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
13 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
14 import org.opendaylight.controller.cluster.datastore.persisted.FrontendHistoryMetadata;
15 import org.opendaylight.yangtools.concepts.Builder;
16 import org.opendaylight.yangtools.concepts.Identifiable;
18 final class FrontendHistoryMetadataBuilder implements Builder<FrontendHistoryMetadata>, Identifiable<LocalHistoryIdentifier> {
19 private final LocalHistoryIdentifier identifier;
21 private long nextTransaction;
22 private boolean closed;
24 FrontendHistoryMetadataBuilder(final LocalHistoryIdentifier identifier) {
25 this.identifier = Preconditions.checkNotNull(identifier);
28 FrontendHistoryMetadataBuilder(final ClientIdentifier clientId, final FrontendHistoryMetadata meta) {
29 identifier = new LocalHistoryIdentifier(clientId, meta.getHistoryId(), meta.getCookie());
30 nextTransaction = meta.getNextTransaction();
31 closed = meta.isClosed();
35 public LocalHistoryIdentifier getIdentifier() {
40 public FrontendHistoryMetadata build() {
41 return new FrontendHistoryMetadata(identifier.getHistoryId(), identifier.getCookie(), nextTransaction, closed);
44 void onHistoryClosed() {
48 void onTransactionCommitted(final TransactionIdentifier txId) {
49 nextTransaction = txId.getTransactionId() + 1;