2 * Copyright (c) 2017 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.remote.rpc.registry.gossip;
10 import static com.google.common.base.Preconditions.checkArgument;
11 import static java.util.Objects.requireNonNull;
14 * Local bucket implementation. Unlike a full-blown {@link Bucket}, this class is mutable and tracks when it has been
15 * changed and when it has been sent anywhere.
17 * @author Robert Varga
19 final class LocalBucket<T extends BucketData<T>> {
21 * Decomposed 64bit signed version number. Always non-negative, hence the most significant bit is always zero.
22 * - incarnation number (most-significant 31 bits, forming an unsigned int)
23 * - version number (least-significant 32 bits, treated as unsigned int)
25 * We are keeping a boxed version here, as we stick it into a map anyway.
30 // We bump versions only if we took a snapshot since last data update
31 private boolean bumpVersion;
33 LocalBucket(final int incarnation, final T data) {
34 checkArgument(incarnation >= 0);
35 this.version = (long)incarnation << Integer.SIZE;
36 this.data = requireNonNull(data);
47 Bucket<T> snapshot() {
49 return new BucketImpl<>(version, data);
52 boolean setData(final T newData) {
53 this.data = requireNonNull(newData);
59 return (++version & 0xffff_ffffL) == 0;