-
Notifications
You must be signed in to change notification settings - Fork 13.6k
/
Record.java
129 lines (110 loc) · 3.95 KB
/
Record.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.kafka.common.record;
import java.nio.ByteBuffer;
import org.apache.kafka.common.header.Header;
/**
* A log record is a tuple consisting of a unique offset in the log, a sequence number assigned by
* the producer, a timestamp, a key and a value.
*/
public interface Record {
Header[] EMPTY_HEADERS = new Header[0];
/**
* The offset of this record in the log
* @return the offset
*/
long offset();
/**
* Get the sequence number assigned by the producer.
* @return the sequence number
*/
int sequence();
/**
* Get the size in bytes of this record.
* @return the size of the record in bytes
*/
int sizeInBytes();
/**
* Get the record's timestamp.
* @return the record's timestamp
*/
long timestamp();
/**
* Raise a {@link org.apache.kafka.common.errors.CorruptRecordException} if the record does not have a valid checksum.
*/
void ensureValid();
/**
* Get the size in bytes of the key.
* @return the size of the key, or -1 if there is no key
*/
int keySize();
/**
* Check whether this record has a key
* @return true if there is a key, false otherwise
*/
boolean hasKey();
/**
* Get the record's key.
* @return the key or null if there is none
*/
ByteBuffer key();
/**
* Get the size in bytes of the value.
* @return the size of the value, or -1 if the value is null
*/
int valueSize();
/**
* Check whether a value is present (i.e. if the value is not null)
* @return true if so, false otherwise
*/
boolean hasValue();
/**
* Get the record's value
* @return the (nullable) value
*/
ByteBuffer value();
/**
* Check whether the record has a particular magic. For versions prior to 2, the record contains its own magic,
* so this function can be used to check whether it matches a particular value. For version 2 and above, this
* method returns true if the passed magic is greater than or equal to 2.
*
* @param magic the magic value to check
* @return true if the record has a magic field (versions prior to 2) and the value matches
*/
boolean hasMagic(byte magic);
/**
* For versions prior to 2, check whether the record is compressed (and therefore
* has nested record content). For versions 2 and above, this always returns false.
* @return true if the magic is lower than 2 and the record is compressed
*/
boolean isCompressed();
/**
* For versions prior to 2, the record contained a timestamp type attribute. This method can be
* used to check whether the value of that attribute matches a particular timestamp type. For versions
* 2 and above, this will always be false.
*
* @param timestampType the timestamp type to compare
* @return true if the version is lower than 2 and the timestamp type matches
*/
boolean hasTimestampType(TimestampType timestampType);
/**
* Get the headers. For magic versions 1 and below, this always returns an empty array.
*
* @return the array of headers
*/
Header[] headers();
}