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 com.google.common.base.Preconditions;
13 * Local bucket implementation. Unlike a full-blown {@link Bucket}, this class is mutable and tracks when it has been
14 * changed and when it has been sent anywhere.
16 * @author Robert Varga
18 final class LocalBucket<T extends BucketData<T>> {
20 * Decomposed 64bit signed version number. Always non-negative, hence the most significant bit is always zero.
21 * - incarnation number (most-significant 31 bits, forming an unsigned int)
22 * - version number (least-significant 32 bits, treated as unsigned int)
24 * We are keeping a boxed version here, as we stick it into a map anyway.
29 // We bump versions only if we took a snapshot since last data update
30 private boolean bumpVersion;
32 LocalBucket(final int incarnation, final T data) {
33 Preconditions.checkArgument(incarnation >= 0);
34 this.version = ((long)incarnation) << Integer.SIZE;
35 this.data = Preconditions.checkNotNull(data);
46 Bucket<T> snapshot() {
48 return new BucketImpl<>(version, data);
51 boolean setData(final T data) {
52 this.data = Preconditions.checkNotNull(data);
58 return (++version & 0xffff_ffffL) == 0;