Update TransferClient.java and TransferServiceImpl.java
This commit is contained in:
parent
1045dd0ef3
commit
bd4132e6a7
@ -22,6 +22,7 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Scheduler;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
public class TransferClient {
|
||||
@ -30,12 +31,16 @@ public class TransferClient {
|
||||
private final ConcurrentHashMap<Integer, Supergroup> supergroupInfos = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<Integer, SupergroupFullInfo> supergroupFullInfos = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<Long, Chat> chats = new ConcurrentHashMap<>();
|
||||
private final Scheduler scheduler;
|
||||
|
||||
public TransferClient(AsyncTdEasy client) {
|
||||
this.client = client;
|
||||
|
||||
this.scheduler = Schedulers.boundedElastic();
|
||||
|
||||
this.client.getIncomingUpdates()
|
||||
.subscribeOn(Schedulers.newParallel("bot_updates"))
|
||||
.subscribeOn(scheduler)
|
||||
.publishOn(scheduler)
|
||||
.flatMap(this::onUpdate)
|
||||
.subscribe();
|
||||
}
|
||||
@ -96,7 +101,7 @@ public class TransferClient {
|
||||
* @return The response or {@link TdApi.Error}.
|
||||
*/
|
||||
public <T extends Object> Mono<TdResult<T>> send(TdApi.Function request) {
|
||||
return client.send(request);
|
||||
return client.<T>send(request).publishOn(scheduler);
|
||||
}
|
||||
|
||||
public Set<BaseChatInfo> getAdminSupergroups(boolean canRestrictMembers, boolean canInviteUsers) {
|
||||
|
@ -35,17 +35,20 @@ import org.slf4j.LoggerFactory;
|
||||
import reactor.core.publisher.EmitterProcessor;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Scheduler;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
public class TransferServiceImpl implements TransferService {
|
||||
|
||||
private final TdClusterManager clusterManager;
|
||||
private final ConcurrentHashMap<Long, TransferClient> clients = new ConcurrentHashMap<>();
|
||||
private final Scheduler updatesScheduler;
|
||||
private int apiId;
|
||||
private String apiHash;
|
||||
|
||||
public TransferServiceImpl(TdClusterManager clusterManager) {
|
||||
this.clusterManager = clusterManager;
|
||||
this.updatesScheduler = Schedulers.boundedElastic();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -128,7 +131,7 @@ public class TransferServiceImpl implements TransferService {
|
||||
})
|
||||
.build())
|
||||
.then(Mono.defer(() -> {
|
||||
var clientStateFlux = client.getState().publish().autoConnect(2);
|
||||
var clientStateFlux = client.getState().publish().autoConnect(3);
|
||||
|
||||
clientStateFlux
|
||||
.filter(state -> state.getConstructor() == AuthorizationStateClosing.CONSTRUCTOR
|
||||
@ -140,16 +143,19 @@ public class TransferServiceImpl implements TransferService {
|
||||
.materialize()
|
||||
.flatMap(signal -> onUserbotClosed.get().thenReturn(signal))
|
||||
.dematerialize()
|
||||
.subscribeOn(updatesScheduler)
|
||||
.subscribe(state -> System.out.println("Userbot closed with state: " + state));
|
||||
|
||||
clientStateFlux.subscribe(state -> System.out.println("state: " + state));
|
||||
clientStateFlux.subscribeOn(updatesScheduler).subscribe(state -> System.out.println("state: " + state));
|
||||
|
||||
client
|
||||
.getIncomingUpdates()
|
||||
.subscribeOn(updatesScheduler)
|
||||
.flatMap(update -> onClientUpdate(update))
|
||||
.subscribe(_v -> {}, e -> System.err.println(e));
|
||||
|
||||
return clientStateFlux
|
||||
.subscribeOn(updatesScheduler)
|
||||
.filter(state -> state.getConstructor() == AuthorizationStateClosing.CONSTRUCTOR
|
||||
|| state.getConstructor() == AuthorizationStateClosed.CONSTRUCTOR
|
||||
|| state.getConstructor() == AuthorizationStateLoggingOut.CONSTRUCTOR
|
||||
|
Loading…
Reference in New Issue
Block a user