ade614b8d765ed23205d0565bbf0b428db484897
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / main / java / org / opendaylight / controller / remote / rpc / registry / gossip / BucketImpl.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.remote.rpc.registry.gossip;
9
10 import com.google.common.base.Preconditions;
11 import com.google.common.base.Verify;
12 import java.io.Serializable;
13
14 final class BucketImpl<T extends BucketData<T>> implements Bucket<T>, Serializable {
15     private static final long serialVersionUID = 294779770032719196L;
16
17     // Guaranteed to be non-null.
18     // This is kept a Long for binary compatibility of serialization format.
19     private final Long version;
20
21     // Guaranteed to be non-null
22     private final T data;
23
24     BucketImpl(final Long version, final T data) {
25         this.version = Preconditions.checkNotNull(version);
26         this.data = Preconditions.checkNotNull(data);
27     }
28
29     @Override
30     public long getVersion() {
31         return version.longValue();
32     }
33
34     @Override
35     public T getData() {
36         return data;
37     }
38
39     @Override
40     public String toString() {
41         return "BucketImpl{" + "version=" + version + ", data=" + data + '}';
42     }
43
44     private Object readResolve() {
45         Verify.verifyNotNull(version);
46         Verify.verifyNotNull(data);
47         return this;
48     }
49 }