Проверка жизнеспособности SFU
This commit is contained in:
@@ -2,6 +2,10 @@ package im.rosetta.service.services;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import im.rosetta.client.ClientManager;
|
||||
import im.rosetta.logger.Logger;
|
||||
@@ -22,14 +26,43 @@ import io.orprotocol.ProtocolException;
|
||||
public class ForwardUnitService {
|
||||
|
||||
private Logger logger;
|
||||
private Set<SFU> sfuConnections = new HashSet<>();
|
||||
private Set<SFU> sfuConnections = ConcurrentHashMap.newKeySet();
|
||||
private ClientManager clientManager;
|
||||
private Set<RTCIceServer> turnServers = new HashSet<>();
|
||||
private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
|
||||
|
||||
public ForwardUnitService(Logger logger, ClientManager clientManager) {
|
||||
this.logger = logger;
|
||||
this.clientManager = clientManager;
|
||||
this.readAllTurnServers();
|
||||
this.sfuConnectionsSheduler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Каждые 10 секунд проверяет доступность всех SFU серверов, и если сервер недоступен, то удаляет его из
|
||||
* пула доступных серверов для организации звонков.
|
||||
* Проверка доступности сервера осуществляется через отправку специального сообщения проверки соединения,
|
||||
* и ожидание ответа от сервера. Если ответ не приходит в течение 10 секунд, то сервер считается недоступным.
|
||||
*
|
||||
* Так же, если sfuConnections пустой, то мы стараемся установить соединение со всеми серверами еще раз.
|
||||
*/
|
||||
private void sfuConnectionsSheduler() {
|
||||
this.scheduler.scheduleAtFixedRate(() -> {
|
||||
for(SFU sfu : this.sfuConnections) {
|
||||
try{
|
||||
if(!sfu.getConnection().checkConnection()){
|
||||
this.logger.error("Server " + sfu.getServerAddress() + " not responding");
|
||||
this.sfuConnections.remove(sfu);
|
||||
}
|
||||
}catch(Exception e) {
|
||||
this.logger.error("Failed to check connection to SFU server: " + sfu.getServerAddress() + ", error: " + e.getMessage());
|
||||
this.sfuConnections.remove(sfu);
|
||||
}
|
||||
}
|
||||
if(this.sfuConnections.isEmpty()) {
|
||||
this.connectToAllSFUServers();
|
||||
}
|
||||
}, 10, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -108,7 +141,7 @@ public class ForwardUnitService {
|
||||
this.sfuConnections.add(connection);
|
||||
this.logger.info(Color.GREEN + "Successfully connected to SFU server: " + address);
|
||||
} catch (Exception e) {
|
||||
this.logger.error(Color.RED + "Failed to connect to SFU server: " + address + ", error: " + e.getMessage());
|
||||
//this.logger.error(Color.RED + "Failed to connect to SFU server: " + address + ", error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user