Remove again initialization lock
This commit is contained in:
parent
8bec749d64
commit
d1766ed0e8
@ -7,11 +7,9 @@ import it.unimi.dsi.fastutil.longs.LongArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
public class InternalClient implements ClientEventsHandler, TelegramClient {
|
||||
|
||||
static final ReentrantReadWriteLock clientInitializationLock = new ReentrantReadWriteLock(true);
|
||||
private final ConcurrentHashMap<Long, Handler> handlers = new ConcurrentHashMap<Long, Handler>();
|
||||
|
||||
private final int clientId;
|
||||
@ -23,39 +21,29 @@ public class InternalClient implements ClientEventsHandler, TelegramClient {
|
||||
private final AtomicBoolean isClosed = new AtomicBoolean();
|
||||
|
||||
public InternalClient(InternalClientManager clientManager,
|
||||
ResultHandler updateHandler,
|
||||
ExceptionHandler updateExceptionHandler,
|
||||
ExceptionHandler defaultExceptionHandler) {
|
||||
clientInitializationLock.writeLock().lock();
|
||||
try {
|
||||
this.updateHandler = new Handler(updateHandler, updateExceptionHandler);
|
||||
this.updatesHandler = null;
|
||||
this.defaultExceptionHandler = defaultExceptionHandler;
|
||||
this.clientManager = clientManager;
|
||||
this.clientId = NativeClientAccess.create();
|
||||
ResultHandler updateHandler,
|
||||
ExceptionHandler updateExceptionHandler,
|
||||
ExceptionHandler defaultExceptionHandler) {
|
||||
this.updateHandler = new Handler(updateHandler, updateExceptionHandler);
|
||||
this.updatesHandler = null;
|
||||
this.defaultExceptionHandler = defaultExceptionHandler;
|
||||
this.clientManager = clientManager;
|
||||
this.clientId = NativeClientAccess.create();
|
||||
|
||||
clientManager.registerClient(clientId, this);
|
||||
} finally {
|
||||
clientInitializationLock.writeLock().unlock();
|
||||
}
|
||||
clientManager.registerClient(clientId, this);
|
||||
}
|
||||
|
||||
public InternalClient(InternalClientManager clientManager,
|
||||
UpdatesHandler updatesHandler,
|
||||
ExceptionHandler updateExceptionHandler,
|
||||
ExceptionHandler defaultExceptionHandler) {
|
||||
clientInitializationLock.writeLock().lock();
|
||||
try {
|
||||
this.updateHandler = null;
|
||||
this.updatesHandler = new MultiHandler(updatesHandler, updateExceptionHandler);
|
||||
this.clientManager = clientManager;
|
||||
this.defaultExceptionHandler = defaultExceptionHandler;
|
||||
this.clientId = NativeClientAccess.create();
|
||||
this.updateHandler = null;
|
||||
this.updatesHandler = new MultiHandler(updatesHandler, updateExceptionHandler);
|
||||
this.clientManager = clientManager;
|
||||
this.defaultExceptionHandler = defaultExceptionHandler;
|
||||
this.clientId = NativeClientAccess.create();
|
||||
|
||||
clientManager.registerClient(clientId, this);
|
||||
} finally {
|
||||
clientInitializationLock.writeLock().unlock();
|
||||
}
|
||||
clientManager.registerClient(clientId, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,7 +1,5 @@
|
||||
package it.tdlight.common;
|
||||
|
||||
import static it.tdlight.common.InternalClient.clientInitializationLock;
|
||||
|
||||
import it.tdlight.common.utils.IntSwapper;
|
||||
import it.tdlight.jni.TdApi;
|
||||
import it.tdlight.jni.TdApi.Object;
|
||||
@ -53,13 +51,7 @@ public class ResponseReceiver extends Thread implements AutoCloseable {
|
||||
int[] sortIndex;
|
||||
try {
|
||||
while(!closeRequested || !registeredClients.isEmpty()) {
|
||||
int resultsCount;
|
||||
clientInitializationLock.readLock().lock();
|
||||
try {
|
||||
resultsCount = NativeClientAccess.receive(clientIds, eventIds, events, 2.0 /*seconds*/);
|
||||
} finally {
|
||||
clientInitializationLock.readLock().unlock();
|
||||
};
|
||||
int resultsCount = NativeClientAccess.receive(clientIds, eventIds, events, 2.0 /*seconds*/);
|
||||
|
||||
if (resultsCount <= 0)
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user