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>,
19 Identifiable<LocalHistoryIdentifier> {
20 private final LocalHistoryIdentifier identifier;
22 private long nextTransaction;
23 private boolean closed;
25 FrontendHistoryMetadataBuilder(final LocalHistoryIdentifier identifier) {
26 this.identifier = Preconditions.checkNotNull(identifier);
29 FrontendHistoryMetadataBuilder(final ClientIdentifier clientId, final FrontendHistoryMetadata meta) {
30 identifier = new LocalHistoryIdentifier(clientId, meta.getHistoryId(), meta.getCookie());
31 nextTransaction = meta.getNextTransaction();
32 closed = meta.isClosed();
36 public LocalHistoryIdentifier getIdentifier() {
41 public FrontendHistoryMetadata build() {
42 return new FrontendHistoryMetadata(identifier.getHistoryId(), identifier.getCookie(), nextTransaction, closed);
45 void onHistoryClosed() {
49 void onTransactionCommitted(final TransactionIdentifier txId) {
50 nextTransaction = txId.getTransactionId() + 1;