Fix initialization
This commit is contained in:
parent
909a5a2e6d
commit
6a52cab8de
19
pom.xml
19
pom.xml
|
@ -201,25 +201,6 @@
|
||||||
<artifactId>maven-install-plugin</artifactId>
|
<artifactId>maven-install-plugin</artifactId>
|
||||||
<version>3.0.0-M1</version>
|
<version>3.0.0-M1</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
|
||||||
<version>3.1.2</version>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>copy-dependencies</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
|
||||||
<overWriteReleases>false</overWriteReleases>
|
|
||||||
<overWriteSnapshots>false</overWriteSnapshots>
|
|
||||||
<overWriteIfNewer>true</overWriteIfNewer>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
|
|
@ -7,7 +7,9 @@ import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
public interface ReactorTelegramClient {
|
public interface ReactorTelegramClient {
|
||||||
|
|
||||||
Flux<Object> initialize();
|
Mono<Void> initialize();
|
||||||
|
|
||||||
|
Flux<Object> receive();
|
||||||
|
|
||||||
Mono<Object> send(TdApi.Function query);
|
Mono<Object> send(TdApi.Function query);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package it.tdlight.tdlibsession.td;
|
||||||
|
|
||||||
import it.tdlight.common.ReactiveTelegramClient;
|
import it.tdlight.common.ReactiveTelegramClient;
|
||||||
import it.tdlight.jni.TdApi;
|
import it.tdlight.jni.TdApi;
|
||||||
|
import it.tdlight.utils.MonoUtils;
|
||||||
import reactor.core.publisher.Flux;
|
import reactor.core.publisher.Flux;
|
||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
|
@ -13,19 +14,27 @@ public class WrappedReactorTelegramClient implements ReactorTelegramClient {
|
||||||
this.reactiveTelegramClient = reactiveTelegramClient;
|
this.reactiveTelegramClient = reactiveTelegramClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("Convert2MethodRef")
|
||||||
|
public Mono<Void> initialize() {
|
||||||
|
return MonoUtils
|
||||||
|
.fromBlockingEmpty(() -> reactiveTelegramClient.createAndRegisterClient());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Flux<TdApi.Object> initialize() {
|
public Flux<TdApi.Object> receive() {
|
||||||
return Flux.from(reactiveTelegramClient).concatMap(item -> {
|
return Flux
|
||||||
if (item.isUpdate()) {
|
.from(reactiveTelegramClient)
|
||||||
return Mono.just(item.getUpdate());
|
.concatMap(item -> {
|
||||||
} else if (item.isHandleException()) {
|
if (item.isUpdate()) {
|
||||||
return Mono.error(item.getHandleException());
|
return Mono.just(item.getUpdate());
|
||||||
} else if (item.isUpdateException()) {
|
} else if (item.isHandleException()) {
|
||||||
return Mono.error(item.getUpdateException());
|
return Mono.error(item.getHandleException());
|
||||||
} else {
|
} else if (item.isUpdateException()) {
|
||||||
return Mono.error(new IllegalStateException("This shouldn't happen. Received unknown ReactiveItem type"));
|
return Mono.error(item.getUpdateException());
|
||||||
}
|
} else {
|
||||||
});
|
return Mono.error(new IllegalStateException("This shouldn't happen. Received unknown ReactiveItem type"));
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,6 +8,8 @@ import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
public interface AsyncTdDirect {
|
public interface AsyncTdDirect {
|
||||||
|
|
||||||
|
Mono<Void> initialize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receives incoming updates and request responses from TDLib.
|
* Receives incoming updates and request responses from TDLib.
|
||||||
* Can be called only once.
|
* Can be called only once.
|
||||||
|
|
|
@ -71,11 +71,10 @@ public class AsyncTdDirectImpl implements AsyncTdDirect {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Flux<TdApi.Object> receive(AsyncTdDirectOptions options) {
|
public Mono<Void> initialize() {
|
||||||
// If closed it will be either true or false
|
|
||||||
final One<Boolean> closedFromTd = Sinks.one();
|
|
||||||
return telegramClientFactory
|
return telegramClientFactory
|
||||||
.create(implementationDetails)
|
.create(implementationDetails)
|
||||||
|
.flatMap(reactorTelegramClient -> reactorTelegramClient.initialize().thenReturn(reactorTelegramClient))
|
||||||
.doOnNext(client -> client.execute(new TdApi.SetLogVerbosityLevel(1)))
|
.doOnNext(client -> client.execute(new TdApi.SetLogVerbosityLevel(1)))
|
||||||
.flatMap(client -> {
|
.flatMap(client -> {
|
||||||
if (td.tryEmitValue(client).isFailure()) {
|
if (td.tryEmitValue(client).isFailure()) {
|
||||||
|
@ -83,7 +82,16 @@ public class AsyncTdDirectImpl implements AsyncTdDirect {
|
||||||
}
|
}
|
||||||
return Mono.just(client);
|
return Mono.just(client);
|
||||||
})
|
})
|
||||||
.flatMapMany(ReactorTelegramClient::initialize)
|
.then();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Flux<TdApi.Object> receive(AsyncTdDirectOptions options) {
|
||||||
|
// If closed it will be either true or false
|
||||||
|
final One<Boolean> closedFromTd = Sinks.one();
|
||||||
|
return td
|
||||||
|
.asMono()
|
||||||
|
.flatMapMany(ReactorTelegramClient::receive)
|
||||||
.doOnNext(update -> {
|
.doOnNext(update -> {
|
||||||
// Close the emitter if receive closed state
|
// Close the emitter if receive closed state
|
||||||
if (update.getConstructor() == UpdateAuthorizationState.CONSTRUCTOR
|
if (update.getConstructor() == UpdateAuthorizationState.CONSTRUCTOR
|
||||||
|
|
|
@ -68,7 +68,12 @@ public class TestClient implements ReactorTelegramClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Flux<TdApi.Object> initialize() {
|
public Mono<Void> initialize() {
|
||||||
|
return Mono.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Flux<TdApi.Object> receive() {
|
||||||
return Flux.fromIterable(features).flatMap(featureName -> {
|
return Flux.fromIterable(features).flatMap(featureName -> {
|
||||||
switch (featureName) {
|
switch (featureName) {
|
||||||
case "status-update":
|
case "status-update":
|
||||||
|
|
|
@ -144,7 +144,8 @@ public class AsyncTdEasy {
|
||||||
.flatMap(_v -> {
|
.flatMap(_v -> {
|
||||||
this.settings.tryEmitNext(settings);
|
this.settings.tryEmitNext(settings);
|
||||||
return Mono.empty();
|
return Mono.empty();
|
||||||
});
|
})
|
||||||
|
.then(td.initialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,6 +7,8 @@ import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
public interface AsyncTdMiddle {
|
public interface AsyncTdMiddle {
|
||||||
|
|
||||||
|
Mono<Void> initialize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Receives incoming updates from TDLib.
|
* Receives incoming updates from TDLib.
|
||||||
*
|
*
|
||||||
|
|
|
@ -144,6 +144,7 @@ public class TdClusterManager {
|
||||||
cfg.setProperty("hazelcast.wait.seconds.before.join", "0");
|
cfg.setProperty("hazelcast.wait.seconds.before.join", "0");
|
||||||
cfg.setProperty("hazelcast.tcp.join.port.try.count", "5");
|
cfg.setProperty("hazelcast.tcp.join.port.try.count", "5");
|
||||||
cfg.setProperty("hazelcast.socket.bind.any", "false");
|
cfg.setProperty("hazelcast.socket.bind.any", "false");
|
||||||
|
cfg.setProperty("hazelcast.health.monitoring.level", "OFF");
|
||||||
cfg.setClusterName("tdlib-session-container");
|
cfg.setClusterName("tdlib-session-container");
|
||||||
mgr = new HazelcastClusterManager(cfg);
|
mgr = new HazelcastClusterManager(cfg);
|
||||||
vertxOptions.setClusterManager(mgr);
|
vertxOptions.setClusterManager(mgr);
|
||||||
|
|
|
@ -64,10 +64,15 @@ public class AsyncTdMiddleEventBusClient implements AsyncTdMiddle {
|
||||||
this.deliveryOptionsWithTimeout = cluster.newDeliveryOpts().setLocalOnly(local).setSendTimeout(30000);
|
this.deliveryOptionsWithTimeout = cluster.newDeliveryOpts().setLocalOnly(local).setSendTimeout(30000);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mono<AsyncTdMiddleEventBusClient> initialize() {
|
private Mono<AsyncTdMiddleEventBusClient> initializeEb() {
|
||||||
return Mono.just(this);
|
return Mono.just(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<Void> initialize() {
|
||||||
|
return Mono.empty();
|
||||||
|
}
|
||||||
|
|
||||||
public static Mono<AsyncTdMiddle> getAndDeployInstance(TdClusterManager clusterManager,
|
public static Mono<AsyncTdMiddle> getAndDeployInstance(TdClusterManager clusterManager,
|
||||||
int botId,
|
int botId,
|
||||||
String botAlias,
|
String botAlias,
|
||||||
|
@ -75,7 +80,7 @@ public class AsyncTdMiddleEventBusClient implements AsyncTdMiddle {
|
||||||
JsonObject implementationDetails,
|
JsonObject implementationDetails,
|
||||||
Path binlogsArchiveDirectory) {
|
Path binlogsArchiveDirectory) {
|
||||||
return new AsyncTdMiddleEventBusClient(clusterManager)
|
return new AsyncTdMiddleEventBusClient(clusterManager)
|
||||||
.initialize()
|
.initializeEb()
|
||||||
.flatMap(instance -> retrieveBinlog(clusterManager.getVertx(), binlogsArchiveDirectory, botId)
|
.flatMap(instance -> retrieveBinlog(clusterManager.getVertx(), binlogsArchiveDirectory, botId)
|
||||||
.flatMap(binlog -> binlog
|
.flatMap(binlog -> binlog
|
||||||
.getLastModifiedTime()
|
.getLastModifiedTime()
|
||||||
|
|
|
@ -83,6 +83,12 @@ public class AsyncTdMiddleDirect extends AbstractVerticle implements AsyncTdMidd
|
||||||
return Completable.complete();
|
return Completable.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<Void> initialize() {
|
||||||
|
return td
|
||||||
|
.initialize();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Flux<TdApi.Object> receive() {
|
public Flux<TdApi.Object> receive() {
|
||||||
return td
|
return td
|
||||||
|
|
|
@ -68,6 +68,11 @@ public class AsyncTdMiddleLocal implements AsyncTdMiddle {
|
||||||
.thenReturn(this);
|
.thenReturn(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Mono<Void> initialize() {
|
||||||
|
return cli.asMono().single().flatMap(AsyncTdMiddle::initialize);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Flux<TdApi.Object> receive() {
|
public Flux<TdApi.Object> receive() {
|
||||||
return cli.asMono().single().flatMapMany(AsyncTdMiddle::receive);
|
return cli.asMono().single().flatMapMany(AsyncTdMiddle::receive);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user