Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 96 additions & 41 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,12 @@
<sourceCompatible>true</sourceCompatible>
<semanticVersionLevel>PATCH</semanticVersionLevel>
</overrideCompatibilityChangeParameter>
<overrideCompatibilityChangeParameter>
<compatibilityChange>SUPERCLASS_ADDED</compatibilityChange>
<binaryCompatible>true</binaryCompatible>
<sourceCompatible>true</sourceCompatible>
<semanticVersionLevel>PATCH</semanticVersionLevel>
</overrideCompatibilityChangeParameter>
<overrideCompatibilityChangeParameter>
<compatibilityChange>ANNOTATION_DEPRECATED_ADDED</compatibilityChange>
<semanticVersionLevel>PATCH</semanticVersionLevel>
Expand Down Expand Up @@ -497,41 +503,6 @@
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.24</version>
<configuration>
<signature>
<groupId>net.sf.androidscents.signature</groupId>
<artifactId>android-api-level-26</artifactId>
<version>8.0.0_r2</version>
</signature>
<ignores>
<ignore>javax.naming.NamingException</ignore>
<ignore>javax.naming.directory.*</ignore>
<ignore>sun.net.spi.nameservice.*</ignore>
<ignore>java.net.spi.*</ignore>
</ignores>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.7.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>animal-sniffer</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
Expand Down Expand Up @@ -719,6 +690,60 @@
<target>${target.jdk}</target>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.24</version>
<configuration>
<signature>
<groupId>com.toasttab.android</groupId>
<artifactId>gummy-bears-api-26</artifactId>
<version>0.12.0</version>
</signature>
<ignores>
<ignore>javax.naming.NamingException</ignore>
<ignore>javax.naming.directory.*</ignore>
<ignore>sun.net.spi.nameservice.*</ignore>
<ignore>java.net.spi.*</ignore>
</ignores>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>9.8</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>animal-sniffer</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<executions>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<excludes>
<exclude>META-INF/**</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
Expand Down Expand Up @@ -815,18 +840,38 @@
@{argLine}
--add-opens java.base/sun.net.dns=ALL-UNNAMED
</argLine>

<!--
Workaround to actually use / prefer the versioned classes
https://issues.apache.org/jira/browse/SUREFIRE-1731
-->
<useModulePath>false</useModulePath>
<classesDirectory>${project.build.outputDirectory}/META-INF/versions/11</classesDirectory>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.outputDirectory}/META-INF/versions/11</additionalClasspathElement>
<additionalClasspathElement>${project.build.outputDirectory}</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>org/xbill/DNS/AsyncSemaphore*</exclude>
<exclude>org/xbill/DNS/DohResolver*</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</profile>

<profile>
<!-- Required only for maven-source-plugin, but needs to be hidden from IntelliJ -->
<!-- https://github.com/apache/maven-source-plugin/issues/215 -->
<!--
Required only for maven-source-plugin, but needs to be hidden from IntelliJ
https://github.com/apache/maven-source-plugin/issues/215
-->
<id>java11-not-idea</id>
<activation>
<activeByDefault>false</activeByDefault>
Expand Down Expand Up @@ -910,10 +955,18 @@
@{argLine}
--add-opens java.base/sun.net.dns=ALL-UNNAMED
-javaagent:${net.bytebuddy:byte-buddy-agent:jar}
-javaagent:${org.mockito:mockito-core:jar}
</argLine>

<!--
Workaround to actually use / prefer the versioned classes
https://issues.apache.org/jira/browse/SUREFIRE-1731
-->
<useModulePath>false</useModulePath>
<classesDirectory>${project.build.outputDirectory}/META-INF/versions/18</classesDirectory>
<additionalClasspathElements>
<additionalClasspathElement>${project.build.outputDirectory}/META-INF/versions/11</additionalClasspathElement>
<additionalClasspathElement>${project.build.outputDirectory}/META-INF/versions/18</additionalClasspathElement>
<additionalClasspathElement>${project.build.outputDirectory}</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
Expand All @@ -922,8 +975,10 @@
</profile>

<profile>
<!-- Required only for maven-source-plugin, but needs to be hidden from IntelliJ -->
<!-- https://github.com/apache/maven-source-plugin/issues/215 -->
<!--
Required only for maven-source-plugin, but needs to be hidden from IntelliJ
https://github.com/apache/maven-source-plugin/issues/215
-->
<id>java18-not-idea</id>
<activation>
<activeByDefault>false</activeByDefault>
Expand Down
27 changes: 22 additions & 5 deletions src/main/java/org/xbill/DNS/AsyncSemaphore.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,58 @@
import java.util.Queue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;

@Slf4j
final class AsyncSemaphore {
private final Queue<CompletableFuture<Permit>> queue = new ArrayDeque<>();
private final Permit singletonPermit = new Permit();
private final String name;
private volatile int permits;

final class Permit {
public void release() {
public void release(int id, Executor executor) {
synchronized (queue) {
CompletableFuture<Permit> next = queue.poll();
if (next == null) {
permits++;
log.trace("{} permit released id={}, available={}", name, id, permits);

Check warning on line 26 in src/main/java/org/xbill/DNS/AsyncSemaphore.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/xbill/DNS/AsyncSemaphore.java#L26

Added line #L26 was not covered by tests
} else {
next.complete(this);
log.trace("{} permit released id={}, available={}, immediate next", name, id, permits);
executor.execute(() -> next.complete(this));

Check warning on line 29 in src/main/java/org/xbill/DNS/AsyncSemaphore.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/xbill/DNS/AsyncSemaphore.java#L28-L29

Added lines #L28 - L29 were not covered by tests
}
}
}
}

AsyncSemaphore(int permits) {
AsyncSemaphore(int permits, String name) {

Check warning on line 35 in src/main/java/org/xbill/DNS/AsyncSemaphore.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/xbill/DNS/AsyncSemaphore.java#L35

Added line #L35 was not covered by tests
this.permits = permits;
this.name = name;
log.debug("Using Java 8 implementation for {}", name);

Check warning on line 38 in src/main/java/org/xbill/DNS/AsyncSemaphore.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/xbill/DNS/AsyncSemaphore.java#L37-L38

Added lines #L37 - L38 were not covered by tests
}

CompletionStage<Permit> acquire(Duration timeout) {
CompletionStage<Permit> acquire(Duration timeout, int id, Executor executor) {
synchronized (queue) {
if (permits > 0) {
permits--;
log.trace("{} permit acquired id={}, available={}", name, id, permits);

Check warning on line 45 in src/main/java/org/xbill/DNS/AsyncSemaphore.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/xbill/DNS/AsyncSemaphore.java#L45

Added line #L45 was not covered by tests
return CompletableFuture.completedFuture(singletonPermit);
} else {
TimeoutCompletableFuture<Permit> f = new TimeoutCompletableFuture<>();
f.compatTimeout(timeout.toNanos(), TimeUnit.NANOSECONDS)
.whenComplete((result, ex) -> queue.remove(f));
.whenCompleteAsync(

Check warning on line 50 in src/main/java/org/xbill/DNS/AsyncSemaphore.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/xbill/DNS/AsyncSemaphore.java#L50

Added line #L50 was not covered by tests
(result, ex) -> {
synchronized (queue) {

Check warning on line 52 in src/main/java/org/xbill/DNS/AsyncSemaphore.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/xbill/DNS/AsyncSemaphore.java#L52

Added line #L52 was not covered by tests
if (ex != null) {
log.trace("{} permit timed out id={}, available={}", name, id, permits);

Check warning on line 54 in src/main/java/org/xbill/DNS/AsyncSemaphore.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/xbill/DNS/AsyncSemaphore.java#L54

Added line #L54 was not covered by tests
}
queue.remove(f);
}
},

Check warning on line 58 in src/main/java/org/xbill/DNS/AsyncSemaphore.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/xbill/DNS/AsyncSemaphore.java#L56-L58

Added lines #L56 - L58 were not covered by tests
executor);
log.trace("{} permit queued id={}, available={}", name, id, permits);

Check warning on line 60 in src/main/java/org/xbill/DNS/AsyncSemaphore.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/xbill/DNS/AsyncSemaphore.java#L60

Added line #L60 was not covered by tests
queue.add(f);
return f;
}
Expand Down
Loading
Loading