Skip to content

Commit

Permalink
Merge pull request #118 from maxmind/greg/module
Browse files Browse the repository at this point in the history
Require Java 11, use modules, and prepare for release
  • Loading branch information
shadromani committed Dec 12, 2022
2 parents 9bfb629 + 958e2a4 commit dbaa873
Show file tree
Hide file tree
Showing 24 changed files with 960 additions and 509 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
matrix:
distribution: ['zulu']
os: [ubuntu-latest, windows-latest, macos-latest]
version: [ 8, 9, 10, 11, 12, 13, 14, 15 ]
version: [ 11, 12, 13, 14, 15, 16, 17, 18, 19 ]
steps:
- uses: actions/checkout@v3
with:
Expand Down
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
CHANGELOG
=========

3.0.0
------------------

* Java 11 or greater is now required.
* This library is now a Java module.

2.1.0 (2022-10-31)
------------------

* Messages for `DeserializationException` have been improved, and the cause
is included, if any. Moreover, the message provides detail about the involved
types, if the exception is caused by an `IllegalArgumentException`.
is included, if any. Moreover, the message provides detail about the involved
types, if the exception is caused by an `IllegalArgumentException`.

2.0.0 (2020-10-13)
------------------
Expand Down Expand Up @@ -101,7 +107,6 @@ CHANGELOG
* Several optimizations have been made to reduce allocations when decoding a
record. Pull requests by Viktor Szathmáry. GitHub #16 & #17.


1.0.0 (2014-09-29)
------------------

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ specific to this reader, please [contact MaxMind support](https://www.maxmind.co

## Requirements ##

This API requires Java 8 or greater.
This API requires Java 11 or greater.

## Contributing ##

Expand All @@ -198,6 +198,6 @@ The MaxMind DB Reader API uses [Semantic Versioning](https://semver.org/).

## Copyright and License ##

This software is Copyright (c) 2014-2020 by MaxMind, Inc.
This software is Copyright (c) 2014-2022 by MaxMind, Inc.

This is free software, licensed under the Apache License, Version 2.0.
9 changes: 9 additions & 0 deletions checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN"
"https://checkstyle.org/dtds/suppressions_1_0.dtd">

<suppressions>
<suppress checks="AbbreviationAsWordInName" files="CHMCache.java" lines="11"/>
</suppressions>
382 changes: 382 additions & 0 deletions checkstyle.xml

Large diffs are not rendered by default.

38 changes: 33 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.maxmind.db</groupId>
<artifactId>maxmind-db</artifactId>
Expand Down Expand Up @@ -45,6 +46,33 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<consoleOutput>true</consoleOutput>
<configLocation>checkstyle.xml</configLocation>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
<violationSeverity>warning</violationSeverity>
</configuration>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.3</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>test</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
Expand Down Expand Up @@ -78,8 +106,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>8</source>
<target>8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
Expand All @@ -97,7 +125,7 @@
<configuration>
<format>xml</format>
<maxmem>256m</maxmem>
<check />
<check/>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -141,7 +169,7 @@
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>8</release>
<release>11</release>
</configuration>
</plugin>
</plugins>
Expand Down
29 changes: 15 additions & 14 deletions src/main/java/com/maxmind/db/BufferHolder.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.maxmind.db;

import com.maxmind.db.Reader.FileMode;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
Expand All @@ -9,23 +10,21 @@
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;

import com.maxmind.db.Reader.FileMode;

final class BufferHolder {
// DO NOT PASS OUTSIDE THIS CLASS. Doing so will remove thread safety.
private final ByteBuffer buffer;

BufferHolder(File database, FileMode mode) throws IOException {
try (
final RandomAccessFile file = new RandomAccessFile(database, "r");
final FileChannel channel = file.getChannel()
final RandomAccessFile file = new RandomAccessFile(database, "r");
final FileChannel channel = file.getChannel()
) {
if (mode == FileMode.MEMORY) {
final ByteBuffer buf = ByteBuffer.wrap(new byte[(int) channel.size()]);
if (channel.read(buf) != buf.capacity()) {
throw new IOException("Unable to read "
+ database.getName()
+ " into memory. Unexpected end of stream.");
+ database.getName()
+ " into memory. Unexpected end of stream.");
}
this.buffer = buf.asReadOnlyBuffer();
} else {
Expand Down Expand Up @@ -61,19 +60,21 @@ final class BufferHolder {
ByteBuffer get() {
// The Java API docs for buffer state:
//
// Buffers are not safe for use by multiple concurrent threads. If a buffer is to be used by more than
// one thread then access to the buffer should be controlled by appropriate synchronization.
// Buffers are not safe for use by multiple concurrent threads. If a buffer is to be
// used by more than one thread then access to the buffer should be controlled by
// appropriate synchronization.
//
// As such, you may think that this should be synchronized. This used to be the case, but we had several
// complaints about the synchronization causing contention, e.g.:
// As such, you may think that this should be synchronized. This used to be the case, but
// we had several complaints about the synchronization causing contention, e.g.:
//
// * https://github.com/maxmind/MaxMind-DB-Reader-java/issues/65
// * https://github.com/maxmind/MaxMind-DB-Reader-java/pull/69
//
// Given that we are not modifying the original ByteBuffer in any way and all currently known and most
// reasonably imaginable implementations of duplicate() only do read operations on the original buffer object,
// the risk of not synchronizing this call seems relatively low and worth taking for the performance benefit
// when lookups are being done from many threads.
// Given that we are not modifying the original ByteBuffer in any way and all currently
// known and most reasonably imaginable implementations of duplicate() only do read
// operations on the original buffer object, the risk of not synchronizing this call seems
// relatively low and worth taking for the performance benefit when lookups are being done
// from many threads.
return this.buffer.duplicate();
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/maxmind/db/CachedConstructor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ final class CachedConstructor<T> {
private final Map<String, Integer> parameterIndexes;

CachedConstructor(
Constructor<T> constructor,
Class<?>[] parameterTypes,
java.lang.reflect.Type[] parameterGenericTypes,
Map<String, Integer> parameterIndexes
Constructor<T> constructor,
Class<?>[] parameterTypes,
java.lang.reflect.Type[] parameterGenericTypes,
Map<String, Integer> parameterIndexes
) {
this.constructor = constructor;
this.parameterTypes = parameterTypes;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/maxmind/db/DecodedValue.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.maxmind.db;

public final class DecodedValue {
final Object value;
final Object value;

DecodedValue(Object value) {
this.value = value;
Expand Down
Loading

0 comments on commit dbaa873

Please sign in to comment.