Skip to content

Commit bf89e7f

Browse files
authored
Remove Joda time dependency and migrate to Java 8 time. (#94)
1 parent 3238d92 commit bf89e7f

File tree

63 files changed

+559
-511
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+559
-511
lines changed

pom.xml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<akka.http.version>10.0.11</akka.http.version>
7676
<apache.httpclient.version>4.5.1</apache.httpclient.version>
7777
<apache.httpcore.version>4.4.3</apache.httpcore.version>
78-
<arpnetworking.commons.version>1.15.3</arpnetworking.commons.version>
78+
<arpnetworking.commons.version>1.16.0</arpnetworking.commons.version>
7979
<aspectjrt.version>1.8.9</aspectjrt.version>
8080
<cglib.version>3.2.5</cglib.version>
8181
<client.protocol.version>0.10.0</client.protocol.version>
@@ -86,7 +86,6 @@
8686
<jackson.version>2.9.2</jackson.version>
8787
<javassist.version>3.22.0-GA</javassist.version>
8888
<javassist.maven.core.version>0.2.1</javassist.maven.core.version>
89-
<joda.time.version>2.9.9</joda.time.version>
9089
<jsr305.version>3.0.2</jsr305.version>
9190
<logback.version>1.2.3</logback.version>
9291
<logback.steno.version>1.18.0</logback.steno.version>
@@ -102,7 +101,6 @@
102101
<scala.version>2.11</scala.version>
103102
<scala.library.version>2.11.7</scala.library.version>
104103
<slf4j.version>1.7.25</slf4j.version>
105-
<statsd.client.timgroup>3.0.1</statsd.client.timgroup>
106104
<typesafe.config.version>1.3.1</typesafe.config.version>
107105
<vertx.core.version>2.1.6</vertx.core.version>
108106

@@ -111,9 +109,10 @@
111109
<hamcrest.version>2.0.0.0</hamcrest.version>
112110
<junit.benchmarks.version>0.7.2</junit.benchmarks.version>
113111
<junit.version>4.12</junit.version>
114-
<metrics.generator.version>1.2.0</metrics.generator.version>
112+
<metrics.generator.version>1.2.1</metrics.generator.version>
115113
<mockito.version>2.12.0</mockito.version>
116114
<performance.test.version>1.1.0</performance.test.version>
115+
<statsd.client.timgroup>3.0.1</statsd.client.timgroup>
117116
<wiremock.version>1.57</wiremock.version>
118117

119118
<!-- Additional Plugins -->
@@ -504,7 +503,7 @@
504503
</dependency>
505504
<dependency>
506505
<groupId>com.fasterxml.jackson.datatype</groupId>
507-
<artifactId>jackson-datatype-joda</artifactId>
506+
<artifactId>jackson-datatype-jsr310</artifactId>
508507
<version>${jackson.version}</version>
509508
<scope>runtime</scope>
510509
</dependency>
@@ -540,11 +539,6 @@
540539
<artifactId>commons</artifactId>
541540
<version>${arpnetworking.commons.version}</version>
542541
</dependency>
543-
<dependency>
544-
<groupId>joda-time</groupId>
545-
<artifactId>joda-time</artifactId>
546-
<version>${joda.time.version}</version>
547-
</dependency>
548542
<dependency>
549543
<groupId>net.sf.oval</groupId>
550544
<artifactId>oval</artifactId>

src/main/java/com/arpnetworking/configuration/jackson/DynamicConfiguration.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
import com.google.common.collect.ImmutableList;
2626
import com.google.common.collect.Lists;
2727
import net.sf.oval.constraint.NotNull;
28-
import org.joda.time.DateTime;
29-
import org.joda.time.Duration;
3028

29+
import java.time.Duration;
30+
import java.time.ZonedDateTime;
3131
import java.util.List;
3232
import java.util.concurrent.ExecutorService;
3333
import java.util.concurrent.Executors;
@@ -174,7 +174,7 @@ private DynamicConfiguration(final Builder builder) {
174174

175175
private ExecutorService _triggerEvaluatorExecutor;
176176

177-
private static final Duration TRIGGER_EVALUATION_INTERVAL = Duration.standardSeconds(60);
177+
private static final Duration TRIGGER_EVALUATION_INTERVAL = Duration.ofSeconds(60);
178178
private static final Logger LOGGER = LoggerFactory.getLogger(DynamicConfiguration.class);
179179

180180
private final class TriggerEvaluator implements Runnable {
@@ -230,8 +230,8 @@ public void run() {
230230

231231
// Wait for the next evaluation period
232232
try {
233-
final DateTime sleepTimeout = DateTime.now().plus(TRIGGER_EVALUATION_INTERVAL);
234-
while (DateTime.now().isBefore(sleepTimeout) && _isRunning) {
233+
final ZonedDateTime sleepTimeout = ZonedDateTime.now().plus(TRIGGER_EVALUATION_INTERVAL);
234+
while (ZonedDateTime.now().isBefore(sleepTimeout) && _isRunning) {
235235
Thread.sleep(100);
236236
}
237237
} catch (final InterruptedException e) {

src/main/java/com/arpnetworking/metrics/common/sources/FileSource.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,11 @@
3030
import com.arpnetworking.steno.LoggerFactory;
3131
import net.sf.oval.constraint.NotEmpty;
3232
import net.sf.oval.constraint.NotNull;
33-
import org.joda.time.DateTime;
34-
import org.joda.time.Duration;
35-
import org.joda.time.Period;
3633

3734
import java.io.IOException;
3835
import java.nio.file.Path;
36+
import java.time.Duration;
37+
import java.time.ZonedDateTime;
3938
import java.util.Optional;
4039
import java.util.concurrent.ExecutorService;
4140
import java.util.concurrent.Executors;
@@ -127,7 +126,7 @@ private FileSource(final Builder<T> builder) {
127126
private final Logger _logger;
128127

129128
private static final Logger LOGGER = LoggerFactory.getLogger(FileSource.class);
130-
private static final Period FILE_NOT_FOUND_WARNING_INTERVAL = Period.minutes(1);
129+
private static final Duration FILE_NOT_FOUND_WARNING_INTERVAL = Duration.ofMinutes(1);
131130
private static final NoPositionStore NO_POSITION_STORE = new NoPositionStore();
132131

133132
private class LogTailerListener implements TailerListener {
@@ -142,7 +141,7 @@ public void initialize(final Tailer tailer) {
142141

143142
@Override
144143
public void fileNotFound() {
145-
final DateTime now = DateTime.now();
144+
final ZonedDateTime now = ZonedDateTime.now();
146145
if (!_lastFileNotFoundWarning.isPresent()
147146
|| _lastFileNotFoundWarning.get().isBefore(now.minus(FILE_NOT_FOUND_WARNING_INTERVAL))) {
148147
_logger.warn()
@@ -221,7 +220,7 @@ public void handle(final Throwable t) {
221220
}
222221
}
223222

224-
private Optional<DateTime> _lastFileNotFoundWarning = Optional.empty();
223+
private Optional<ZonedDateTime> _lastFileNotFoundWarning = Optional.empty();
225224
}
226225

227226
/**
@@ -306,7 +305,7 @@ protected Builder<T> self() {
306305
@NotEmpty
307306
private Path _sourceFile;
308307
@NotNull
309-
private Duration _interval = Duration.millis(500);
308+
private Duration _interval = Duration.ofMillis(500);
310309
@NotNull
311310
private Parser<T, byte[]> _parser;
312311
private Path _stateFile;

src/main/java/com/arpnetworking/metrics/common/tailer/FilePositionStore.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@
2727
import com.google.common.collect.Maps;
2828
import net.sf.oval.constraint.Min;
2929
import net.sf.oval.constraint.NotNull;
30-
import org.joda.time.DateTime;
31-
import org.joda.time.Duration;
3230

3331
import java.io.IOException;
3432
import java.nio.file.Files;
3533
import java.nio.file.Path;
3634
import java.nio.file.Paths;
3735
import java.nio.file.StandardCopyOption;
36+
import java.time.Duration;
37+
import java.time.ZonedDateTime;
3838
import java.util.Iterator;
3939
import java.util.Map;
4040
import java.util.Optional;
@@ -66,7 +66,7 @@ public void setPosition(final String identifier, final long position) {
6666
.setPosition(position)
6767
.build());
6868

69-
final DateTime now = DateTime.now();
69+
final ZonedDateTime now = ZonedDateTime.now();
7070
boolean requiresFlush = now.minus(_flushInterval).isAfter(_lastFlush);
7171
if (descriptor != null) {
7272
descriptor.update(position, now);
@@ -105,8 +105,8 @@ public String toString() {
105105

106106
private void flush() {
107107
// Age out old state
108-
final DateTime now = DateTime.now();
109-
final DateTime oldest = now.minus(_retention);
108+
final ZonedDateTime now = ZonedDateTime.now();
109+
final ZonedDateTime oldest = now.minus(_retention);
110110
final long sizeBefore = _state.size();
111111
final Iterator<Map.Entry<String, Descriptor>> iterator = _state.entrySet().iterator();
112112
while (iterator.hasNext()) {
@@ -171,7 +171,7 @@ private FilePositionStore(final Builder builder) {
171171
private final Duration _retention;
172172
private final ConcurrentMap<String, Descriptor> _state;
173173

174-
private DateTime _lastFlush = DateTime.now();
174+
private ZonedDateTime _lastFlush = ZonedDateTime.now();
175175

176176
private static final TypeReference<ConcurrentMap<String, Descriptor>> STATE_MAP_TYPE_REFERENCE =
177177
new TypeReference<ConcurrentMap<String, Descriptor>>(){};
@@ -180,7 +180,7 @@ private FilePositionStore(final Builder builder) {
180180

181181
private static final class Descriptor {
182182

183-
public void update(final long position, final DateTime updatedAt) {
183+
public void update(final long position, final ZonedDateTime updatedAt) {
184184
_delta += position - _position;
185185
_lastUpdated = updatedAt;
186186
_position = position;
@@ -194,7 +194,7 @@ public long getPosition() {
194194
return _position;
195195
}
196196

197-
public DateTime getLastUpdated() {
197+
public ZonedDateTime getLastUpdated() {
198198
return _lastUpdated;
199199
}
200200

@@ -210,7 +210,7 @@ private Descriptor(final Builder builder) {
210210
}
211211

212212
private long _position;
213-
private DateTime _lastUpdated;
213+
private ZonedDateTime _lastUpdated;
214214
private long _delta;
215215

216216
private static final class Builder extends OvalBuilder<Descriptor> {
@@ -224,15 +224,15 @@ public Builder setPosition(final Long value) {
224224
return this;
225225
}
226226

227-
public Builder setLastUpdated(final DateTime value) {
227+
public Builder setLastUpdated(final ZonedDateTime value) {
228228
_lastUpdated = value;
229229
return this;
230230
}
231231

232232
@NotNull
233233
private Long _position;
234234
@NotNull
235-
private DateTime _lastUpdated = DateTime.now();
235+
private ZonedDateTime _lastUpdated = ZonedDateTime.now();
236236
}
237237
}
238238

@@ -300,11 +300,11 @@ public Builder setRetention(final Duration value) {
300300
@NotNull
301301
private Path _file;
302302
@NotNull
303-
private Duration _flushInterval = Duration.standardSeconds(10);
303+
private Duration _flushInterval = Duration.ofSeconds(10);
304304
@NotNull
305305
@Min(0)
306306
private Long _flushThreshold = 10485760L; // 2^20 * 10 = (10 Mebibyte)
307307
@NotNull
308-
private Duration _retention = Duration.standardDays(1);
308+
private Duration _retention = Duration.ofDays(1);
309309
}
310310
}

src/main/java/com/arpnetworking/metrics/common/tailer/StatefulTailer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.arpnetworking.utility.Trigger;
2525
import com.google.common.base.MoreObjects;
2626
import net.sf.oval.constraint.NotNull;
27-
import org.joda.time.Duration;
2827

2928
import java.io.ByteArrayOutputStream;
3029
import java.io.IOException;
@@ -37,6 +36,7 @@
3736
import java.nio.file.attribute.BasicFileAttributes;
3837
import java.security.MessageDigest;
3938
import java.security.NoSuchAlgorithmException;
39+
import java.time.Duration;
4040
import java.util.Objects;
4141
import java.util.Optional;
4242
import javax.xml.bind.DatatypeConverter;
@@ -672,7 +672,7 @@ public Builder setMaximumOffsetOnResume(final Long maximumOffsetOnResume) {
672672
@NotNull
673673
private TailerListener _listener;
674674
@NotNull
675-
private Duration _readInterval = Duration.millis(250);
675+
private Duration _readInterval = Duration.ofMillis(250);
676676
@NotNull
677677
private InitialPosition _initialPosition = InitialPosition.START;
678678
private Long _maximumOffsetOnResume = null;

src/main/java/com/arpnetworking/metrics/mad/Aggregator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
import com.google.common.collect.Maps;
3838
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
3939
import net.sf.oval.constraint.NotNull;
40-
import org.joda.time.Period;
4140

41+
import java.time.Duration;
4242
import java.util.Collections;
4343
import java.util.List;
4444
import java.util.Map;
@@ -141,7 +141,7 @@ public String toString() {
141141

142142
private List<PeriodWorker> createPeriodWorkers(final Key key) {
143143
final List<PeriodWorker> periodWorkerList = Lists.newArrayListWithExpectedSize(_periods.size());
144-
for (final Period period : _periods) {
144+
for (final Duration period : _periods) {
145145
final PeriodWorker periodWorker = new PeriodWorker.Builder()
146146
.setPeriod(period)
147147
.setBucketBuilder(
@@ -229,7 +229,7 @@ public Optional<ImmutableSet<Statistic>> load(final String metric) throws Except
229229
});
230230
}
231231

232-
private final ImmutableSet<Period> _periods;
232+
private final ImmutableSet<Duration> _periods;
233233
private final Sink _sink;
234234
private final ImmutableSet<Statistic> _specifiedTimerStatistics;
235235
private final ImmutableSet<Statistic> _specifiedCounterStatistics;
@@ -275,7 +275,7 @@ public Builder setSink(final Sink value) {
275275
* @param value The periods.
276276
* @return This <code>Builder</code> instance.
277277
*/
278-
public Builder setPeriods(final Set<Period> value) {
278+
public Builder setPeriods(final Set<Duration> value) {
279279
_periods = value;
280280
return this;
281281
}
@@ -328,7 +328,7 @@ public Builder setStatistics(final Map<String, Set<Statistic>> value) {
328328
@NotNull
329329
private Sink _sink;
330330
@NotNull
331-
private Set<Period> _periods;
331+
private Set<Duration> _periods;
332332
@NotNull
333333
private Set<Statistic> _timerStatistics;
334334
@NotNull

src/main/java/com/arpnetworking/metrics/mad/Bucket.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@
3939
import com.google.common.collect.Maps;
4040
import com.google.common.collect.Sets;
4141
import net.sf.oval.constraint.NotNull;
42-
import org.joda.time.DateTime;
43-
import org.joda.time.Period;
4442

4543
import java.time.Duration;
44+
import java.time.ZonedDateTime;
4645
import java.util.Collection;
4746
import java.util.Collections;
4847
import java.util.Map;
@@ -187,7 +186,7 @@ public void add(final Record record) {
187186
}
188187
}
189188

190-
public DateTime getStart() {
189+
public ZonedDateTime getStart() {
191190
return _start;
192191
}
193192

@@ -298,7 +297,7 @@ private void computeStatistics(
298297
private void addMetric(
299298
final String name,
300299
final Metric metric,
301-
final DateTime time,
300+
final ZonedDateTime time,
302301
final Collection<Calculator<?>> calculators) {
303302

304303
try {
@@ -382,8 +381,8 @@ private Collection<Calculator<?>> getOrCreateCalculators(
382381
private final ConcurrentMap<String, Collection<Calculator<?>>> _explicitMetricCalculators = Maps.newConcurrentMap();
383382
private final Sink _sink;
384383
private final Key _key;
385-
private final DateTime _start;
386-
private final Period _period;
384+
private final ZonedDateTime _start;
385+
private final Duration _period;
387386
private final ImmutableSet<Statistic> _specifiedCounterStatistics;
388387
private final ImmutableSet<Statistic> _specifiedGaugeStatistics;
389388
private final ImmutableSet<Statistic> _specifiedTimerStatistics;
@@ -509,7 +508,7 @@ public Builder setDependentGaugeStatistics(final ImmutableSet<Statistic> value)
509508
* @param value The start.
510509
* @return This <code>Builder</code> instance.
511510
*/
512-
public Builder setStart(final DateTime value) {
511+
public Builder setStart(final ZonedDateTime value) {
513512
_start = value;
514513
return this;
515514
}
@@ -520,7 +519,7 @@ public Builder setStart(final DateTime value) {
520519
* @param value The period.
521520
* @return This <code>Builder</code> instance.
522521
*/
523-
public Builder setPeriod(final Period value) {
522+
public Builder setPeriod(final Duration value) {
524523
_period = value;
525524
return this;
526525
}
@@ -579,9 +578,9 @@ public String toString() {
579578
@NotNull
580579
private Key _key;
581580
@NotNull
582-
private DateTime _start;
581+
private ZonedDateTime _start;
583582
@NotNull
584-
private Period _period;
583+
private Duration _period;
585584
@NotNull
586585
private ImmutableSet<Statistic> _specifiedTimerStatistics;
587586
@NotNull

src/main/java/com/arpnetworking/metrics/mad/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private void launchJvmMetricsCollector(final Injector injector) {
188188
_jvmMetricsCollector.scheduleAtFixedRate(
189189
runnable,
190190
INITIAL_DELAY_IN_MILLIS,
191-
_configuration.getJvmMetricsCollectionInterval().toStandardDuration().getMillis(),
191+
_configuration.getJvmMetricsCollectionInterval().toMillis(),
192192
TIME_UNIT);
193193
}
194194

0 commit comments

Comments
 (0)