-
Notifications
You must be signed in to change notification settings - Fork 541
/
Copy pathRollCycles.java
152 lines (135 loc) · 5.21 KB
/
RollCycles.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*
* Copyright 2016-2020 chronicle.software
*
* https://chronicle.software
*
* Licensed 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 net.openhft.chronicle.queue;
import net.openhft.chronicle.queue.rollcycles.*;
import java.util.*;
import java.util.stream.Collectors;
/**
* Roll cycles to use with the queue. Sparse indexing roll cycles are useful for improving write performance but they slightly slow random access
* performance (with no effect for sequential reads)
*/
public enum RollCycles implements RollCycle {
/**
* 0x40000000 entries per 5 minutes, indexing every 256th entry
*/
FIVE_MINUTELY(/*------*/"yyyyMMdd-HHmm'V'", 5 * 60 * 1000, 2 << 10, 256),
/**
* 0x40000000 entries per 10 minutes, indexing every 256th entry
*/
TEN_MINUTELY(/*------*/"yyyyMMdd-HHmm'X'", 10 * 60 * 1000, 2 << 10, 256),
/**
* 0x40000000 entries per 20 minutes, indexing every 256th entry
*/
TWENTY_MINUTELY(/*------*/"yyyyMMdd-HHmm'XX'", 20 * 60 * 1000, 2 << 10, 256),
/**
* 0x40000000 entries per half hour, indexing every 256th entry
*/
HALF_HOURLY(/*------*/"yyyyMMdd-HHmm'H'", 30 * 60 * 1000, 2 << 10, 256),
/**
* 0xffffffff entries per hour, indexing every 256th entry, leave as 4K and 256 for historical reasons.
*/
FAST_HOURLY(/*----------*/"yyyyMMdd-HH'F'", 60 * 60 * 1000, 4 << 10, 256),
/**
* 0xffffffff entries per 2 hours, indexing every 256th entry
*/
TWO_HOURLY(/*----*/"yyyyMMdd-HH'II'", 2 * 60 * 60 * 1000, 4 << 10, 256),
/**
* 0xffffffff entries per four hours, indexing every 256th entry
*/
FOUR_HOURLY(/*----*/"yyyyMMdd-HH'IV'", 4 * 60 * 60 * 1000, 4 << 10, 256),
/**
* 0xffffffff entries per six hours, indexing every 256th entry
*/
SIX_HOURLY(/*----*/"yyyyMMdd-HH'VI'", 6 * 60 * 60 * 1000, 4 << 10, 256),
/**
* 0xffffffff entries per day, indexing every 256th entry, leave as 4K and 256 for historical reasons.
*/
FAST_DAILY(/*-----------*/"yyyyMMdd'F'", 24 * 60 * 60 * 1000, 4 << 10, 256),
/**
* 0xffffffff entries per week, indexing every 256th entry, leave as 4K and 256 for historical reasons. Cycle starts Sunday 00:00
*/
WEEKLY(/*-----------*/"YYYY'W'ww", 7 * 24 * 60 * 60 * 1000, 4 << 10, 256, RollCycleArithmetic.SUNDAY_00_00),
;
public static final RollCycles DEFAULT = FAST_DAILY;
// don't alter this or you will confuse yourself.
private static final Iterable<RollCycle> VALUES;
static {
List<RollCycle> allCycles = new ArrayList<>();
// We can add #values() again once the deprecated ones are gone
allCycles.addAll(Arrays.stream(RollCycles.values()).collect(Collectors.toList()));
allCycles.addAll(Arrays.asList(LegacyRollCycles.values()));
allCycles.addAll(Arrays.asList(LargeRollCycles.values()));
allCycles.addAll(Arrays.asList(SparseRollCycles.values()));
allCycles.addAll(Arrays.asList(TestRollCycles.values()));
VALUES = Collections.unmodifiableList(allCycles);
}
private final String format;
private final int lengthInMillis;
private final int defaultEpoch;
private final RollCycleArithmetic arithmetic;
RollCycles(String format, int lengthInMillis, int indexCount, int indexSpacing) {
this(format, lengthInMillis, indexCount, indexSpacing, 0);
}
RollCycles(String format, int lengthInMillis, int indexCount, int indexSpacing, int defaultEpoch) {
this.format = format;
this.lengthInMillis = lengthInMillis;
this.defaultEpoch = defaultEpoch;
this.arithmetic = RollCycleArithmetic.of(indexCount, indexSpacing);
}
public static Iterable<RollCycle> all() {
return VALUES;
}
public long maxMessagesPerCycle() {
return arithmetic.maxMessagesPerCycle();
}
@Override
public String format() {
return this.format;
}
@Override
public int lengthInMillis() {
return this.lengthInMillis;
}
@Override
public int defaultEpoch() {
return this.defaultEpoch;
}
/**
* @return this is the size of each index array, note: indexCount^2 is the maximum number of index queue entries.
*/
@Override
public int defaultIndexCount() {
return arithmetic.indexCount();
}
@Override
public int defaultIndexSpacing() {
return arithmetic.indexSpacing();
}
@Override
public long toIndex(int cycle, long sequenceNumber) {
return arithmetic.toIndex(cycle, sequenceNumber);
}
@Override
public long toSequenceNumber(long index) {
return arithmetic.toSequenceNumber(index);
}
@Override
public int toCycle(long index) {
return arithmetic.toCycle(index);
}
}