Re-add Java 8 support, update tdlib and tdlight
This commit is contained in:
parent
a855b4fdba
commit
9dba2c7071
|
@ -9,7 +9,7 @@ A barebone java wrapper for TDLib (and TDLight)
|
|||
This wrapper gives you direct access to TDLib API in Java.
|
||||
|
||||
## Requirements
|
||||
Java versions: Java 11, 12, 13, 14, 15, 16
|
||||
Java versions: Java 8, 9, 10, 11, 12, 13, 14, 15, 16
|
||||
|
||||
Operating system: Linux, Windows, MacOS
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ public class InternalClientManager implements AutoCloseable {
|
|||
TdApi.Object event = clientEvents[i];
|
||||
boolean mustPrintError = true;
|
||||
if (event instanceof TdApi.Error) {
|
||||
var errorEvent = (TdApi.Error) event;
|
||||
TdApi.Error errorEvent = (TdApi.Error) event;
|
||||
if (Objects.equals("Request aborted", errorEvent.message)) {
|
||||
mustPrintError = false;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ public class InternalReactiveClient implements ClientEventsHandler, ReactiveTele
|
|||
this.clientManager = clientManager;
|
||||
this.updateHandler = new Handler(
|
||||
updateItem -> {
|
||||
var item = ReactiveItem.ofUpdate(updateItem);
|
||||
ReactiveItem item = ReactiveItem.ofUpdate(updateItem);
|
||||
if (subscriber != null && requested.getAndUpdate(n -> n == 0 ? 0 : (n - 1)) > 0) {
|
||||
subscriber.onNext(item);
|
||||
} else {
|
||||
|
@ -49,7 +49,7 @@ public class InternalReactiveClient implements ClientEventsHandler, ReactiveTele
|
|||
}
|
||||
},
|
||||
updateEx -> {
|
||||
var item = ReactiveItem.ofUpdateException(updateEx);
|
||||
ReactiveItem item = ReactiveItem.ofUpdateException(updateEx);
|
||||
if (subscriber != null && requested.getAndUpdate(n -> n == 0 ? 0 : (n - 1)) > 0) {
|
||||
subscriber.onNext(item);
|
||||
} else {
|
||||
|
@ -128,7 +128,7 @@ public class InternalReactiveClient implements ClientEventsHandler, ReactiveTele
|
|||
public void subscribe(Subscriber<? super ReactiveItem> subscriber) {
|
||||
AtomicBoolean alreadyCompleted = new AtomicBoolean();
|
||||
if (updatesAlreadySubscribed.compareAndSet(false, true)) {
|
||||
var subscription = new Subscription() {
|
||||
Subscription subscription = new Subscription() {
|
||||
|
||||
@Override
|
||||
public void request(long n) {
|
||||
|
@ -228,7 +228,7 @@ public class InternalReactiveClient implements ClientEventsHandler, ReactiveTele
|
|||
@Override
|
||||
public Publisher<TdApi.Object> send(Function query) {
|
||||
return subscriber -> {
|
||||
var subscription = new Subscription() {
|
||||
Subscription subscription = new Subscription() {
|
||||
|
||||
private final AtomicBoolean alreadyRequested = new AtomicBoolean(false);
|
||||
private volatile boolean cancelled = false;
|
||||
|
|
|
@ -2,6 +2,7 @@ package it.tdlight.common.internal;
|
|||
|
||||
import it.tdlight.common.EventsHandler;
|
||||
import it.tdlight.common.utils.IntSwapper;
|
||||
import it.tdlight.common.utils.SpinWaitSupport;
|
||||
import it.tdlight.jni.TdApi;
|
||||
import it.tdlight.jni.TdApi.Object;
|
||||
import java.util.ArrayList;
|
||||
|
@ -51,17 +52,11 @@ public class ResponseReceiver extends Thread implements AutoCloseable {
|
|||
public void run() {
|
||||
int[] sortIndex;
|
||||
try {
|
||||
boolean useSpinWait = "amd64".equalsIgnoreCase(System.getProperty("os.arch"));
|
||||
while (!closeRequested || !registeredClients.isEmpty()) {
|
||||
int resultsCount = NativeClientAccess.receive(clientIds, eventIds, events, 2.0 /*seconds*/);
|
||||
|
||||
if (resultsCount <= 0) {
|
||||
if (useSpinWait) {
|
||||
Thread.onSpinWait();
|
||||
} else {
|
||||
//noinspection BusyWait
|
||||
Thread.sleep(20);
|
||||
}
|
||||
SpinWaitSupport.onSpinWait();
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -157,8 +152,6 @@ public class ResponseReceiver extends Thread implements AutoCloseable {
|
|||
this.registeredClients.addAll(closedClients);
|
||||
}
|
||||
}
|
||||
} catch (InterruptedException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
} finally {
|
||||
this.closeWait.countDown();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package it.tdlight.common.utils;
|
||||
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
|
||||
public class SpinWaitSupport {
|
||||
private static final MethodHandle onSpinWaitHandle;
|
||||
|
||||
static {
|
||||
MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
|
||||
MethodHandle handle;
|
||||
try {
|
||||
handle = lookup.findStatic(java.lang.Thread.class, "onSpinWait", MethodType.methodType(void.class));
|
||||
} catch (Exception e) {
|
||||
handle = null;
|
||||
}
|
||||
|
||||
onSpinWaitHandle = handle;
|
||||
}
|
||||
|
||||
private SpinWaitSupport() {
|
||||
}
|
||||
|
||||
public static void onSpinWait() {
|
||||
if (onSpinWaitHandle != null) {
|
||||
try {
|
||||
onSpinWaitHandle.invokeExact();
|
||||
} catch (Throwable throwable) {
|
||||
// This can't happen
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<revision>0-SNAPSHOT</revision>
|
||||
<natives-version>3.3.28</natives-version>
|
||||
<natives-version>3.3.37</natives-version>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
|
@ -161,17 +161,76 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- ensure the project is compiling with JDK 9+ -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.0.0-M3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-jdk9</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireJavaVersion>
|
||||
<version>[1.9,)</version>
|
||||
<message>JDK 9+ is required for compilation</message>
|
||||
</requireJavaVersion>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- compile sources -->
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<encoding>UTF-8</encoding>
|
||||
<release>11</release>
|
||||
<release>8</release>
|
||||
<useIncrementalCompilation>false</useIncrementalCompilation>
|
||||
<excludes>
|
||||
<exclude>it/tdlight/tdlight/ClientManager.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
<executions>
|
||||
<!-- disable default phase due to fixed id and position in lifecycle -->
|
||||
<execution>
|
||||
<id>default-compile</id>
|
||||
<phase>none</phase>
|
||||
<!-- specify source/target for IDE integration -->
|
||||
<configuration>
|
||||
<release>9</release>
|
||||
</configuration>
|
||||
</execution>
|
||||
<!-- compile sources with Java 9 to generate and validate module-info.java -->
|
||||
<execution>
|
||||
<id>java-9-module-compile</id>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<release>9</release>
|
||||
</configuration>
|
||||
</execution>
|
||||
<!-- recompile sources as Java 8 to overwrite Java 9 class files, except module-info.java -->
|
||||
<execution>
|
||||
<id>java-8-compile</id>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<!-- specify JDK 9+ release flag to ensure no classes/methods later than Java 8 are used accidentally -->
|
||||
<release>8</release>
|
||||
<!-- exclude module-info.java from the compilation, as it is unsupported by Java 8 -->
|
||||
<excludes>
|
||||
<exclude>module-info.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<revision>0-SNAPSHOT</revision>
|
||||
<natives-version>3.3.28</natives-version>
|
||||
<natives-version>3.3.37</natives-version>
|
||||
</properties>
|
||||
<repositories>
|
||||
<repository>
|
||||
|
@ -161,17 +161,76 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- ensure the project is compiling with JDK 9+ -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-enforcer-plugin</artifactId>
|
||||
<version>3.0.0-M3</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>enforce-jdk9</id>
|
||||
<goals>
|
||||
<goal>enforce</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<rules>
|
||||
<requireJavaVersion>
|
||||
<version>[1.9,)</version>
|
||||
<message>JDK 9+ is required for compilation</message>
|
||||
</requireJavaVersion>
|
||||
</rules>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- compile sources -->
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<encoding>UTF-8</encoding>
|
||||
<release>11</release>
|
||||
<release>8</release>
|
||||
<useIncrementalCompilation>false</useIncrementalCompilation>
|
||||
<excludes>
|
||||
<exclude>it/tdlight/tdlib/ClientManager.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
<executions>
|
||||
<!-- disable default phase due to fixed id and position in lifecycle -->
|
||||
<execution>
|
||||
<id>default-compile</id>
|
||||
<phase>none</phase>
|
||||
<!-- specify source/target for IDE integration -->
|
||||
<configuration>
|
||||
<release>9</release>
|
||||
</configuration>
|
||||
</execution>
|
||||
<!-- compile sources with Java 9 to generate and validate module-info.java -->
|
||||
<execution>
|
||||
<id>java-9-module-compile</id>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<release>9</release>
|
||||
</configuration>
|
||||
</execution>
|
||||
<!-- recompile sources as Java 8 to overwrite Java 9 class files, except module-info.java -->
|
||||
<execution>
|
||||
<id>java-8-compile</id>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<!-- specify JDK 9+ release flag to ensure no classes/methods later than Java 8 are used accidentally -->
|
||||
<release>8</release>
|
||||
<!-- exclude module-info.java from the compilation, as it is unsupported by Java 8 -->
|
||||
<excludes>
|
||||
<exclude>module-info.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
|
|
Loading…
Reference in New Issue