Update InternalClient.java

This commit is contained in:
Andrea Cavalli 2021-01-24 18:25:53 +01:00
parent 3448e980b4
commit 417ea0c41e

View File

@ -16,8 +16,6 @@ public class InternalClient implements ClientEventsHandler, TelegramClient {
private static final Logger logger = LoggerFactory.getLogger(TelegramClient.class); private static final Logger logger = LoggerFactory.getLogger(TelegramClient.class);
private final ConcurrentHashMap<Long, Handler> handlers = new ConcurrentHashMap<Long, Handler>(); private final ConcurrentHashMap<Long, Handler> handlers = new ConcurrentHashMap<Long, Handler>();
private static final java.lang.Object nextClientIdLock = new java.lang.Object();
private static int nextClientId = 1;
private volatile Integer clientId = null; private volatile Integer clientId = null;
private final InternalClientManager clientManager; private final InternalClientManager clientManager;
@ -136,15 +134,10 @@ public class InternalClient implements ClientEventsHandler, TelegramClient {
} }
private void createAndRegisterClient() { private void createAndRegisterClient() {
synchronized (nextClientIdLock) { if (clientId != null) throw new UnsupportedOperationException("Can't initialize the same client twice!");
int nextClientId = InternalClient.nextClientId++; clientId = NativeClientAccess.create();
logger.info("Registering client {}", nextClientId); clientManager.registerClient(clientId, this);
clientManager.registerClient(nextClientId, this); logger.info("Registered new client {}", clientId);
this.clientId = NativeClientAccess.create();
if (this.clientId != nextClientId) {
throw new RuntimeException("FATAL ERROR 00 -- REPORT AT https://github.com/tdlight-team/tdlight-java/issues");
}
}
// Send a dummy request because @levlam is too lazy to fix race conditions in a better way // Send a dummy request because @levlam is too lazy to fix race conditions in a better way
this.send(new TdApi.GetAuthorizationState(), (result) -> {}, ex -> {}); this.send(new TdApi.GetAuthorizationState(), (result) -> {}, ex -> {});