openvidu-server: store Media Node num of sessions, connections and composed recordings

pull/609/head
pabloFuente 2021-02-10 21:32:34 +01:00
parent 1c63047a69
commit 45dc06fb59
4 changed files with 30 additions and 7 deletions

View File

@ -272,4 +272,8 @@ public class Session implements SessionInterface {
return false;
}
public int getNumberOfConnections() {
return this.participants.size();
}
}

View File

@ -347,6 +347,7 @@ public class KurentoSession extends Session {
public int getNumberOfWebrtcConnections() {
return this.getActivePublishers() + this.participants.values().stream()
.filter(p -> !ProtocolElements.RECORDER_PARTICIPANT_PUBLICID.equals(p.getParticipantPublicId()))
.mapToInt(p -> ((KurentoParticipant) p).getSubscribers().size()).reduce(0, Integer::sum);
}

View File

@ -71,17 +71,16 @@ public class FixedOneKmsManager extends KmsManager {
@Override
public void incrementActiveRecordings(RecordingProperties properties, String recordingId, Session session) {
try {
this.getKmss().iterator().next().incrementActiveRecordings(recordingId, session.getSessionId());
this.getKmss().iterator().next().incrementActiveRecordings(session.getSessionId(), recordingId, properties);
} catch (NoSuchElementException e) {
log.error("There is no KMS available when incrementing active recordings");
}
}
@Override
public void decrementActiveRecordings(RecordingProperties recordingProperties, String recordingId,
Session session) {
public void decrementActiveRecordings(RecordingProperties properties, String recordingId, Session session) {
try {
this.getKmss().iterator().next().decrementActiveRecordings(recordingId);
this.getKmss().iterator().next().decrementActiveRecordings(recordingId, properties);
} catch (NoSuchElementException e) {
log.error("There is no KMS available when decrementing active recordings");
}

View File

@ -36,8 +36,10 @@ import org.slf4j.LoggerFactory;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import io.openvidu.java.client.RecordingProperties;
import io.openvidu.server.kurento.core.KurentoSession;
import io.openvidu.server.utils.QuarantineKiller;
import io.openvidu.server.utils.RecordingUtils;
import io.openvidu.server.utils.UpdatableTimerTask;
/**
@ -69,6 +71,7 @@ public class Kms {
private Map<String, KurentoSession> kurentoSessions = new ConcurrentHashMap<>();
private Map<String, String> activeRecordings = new ConcurrentHashMap<>();
private AtomicLong activeComposedRecordings = new AtomicLong();
public Kms(KmsProperties props, LoadManager loadManager, QuarantineKiller quarantineKiller) {
this.id = props.getId();
@ -163,12 +166,19 @@ public class Kms {
return this.activeRecordings.entrySet();
}
public synchronized void incrementActiveRecordings(String recordingId, String sessionId) {
public synchronized void incrementActiveRecordings(String sessionId, String recordingId,
RecordingProperties properties) {
this.activeRecordings.put(recordingId, sessionId);
if (RecordingUtils.IS_COMPOSED(properties.outputMode())) {
this.activeComposedRecordings.incrementAndGet();
}
}
public synchronized void decrementActiveRecordings(String recordingId) {
public synchronized void decrementActiveRecordings(String recordingId, RecordingProperties properties) {
this.activeRecordings.remove(recordingId);
if (RecordingUtils.IS_COMPOSED(properties.outputMode())) {
this.activeComposedRecordings.decrementAndGet();
}
this.quarantineKiller.dropMediaNode(this.id);
}
@ -250,9 +260,18 @@ public class Kms {
return this.uri;
}
public int getNumberOfConnections() {
return this.kurentoSessions.values().stream().mapToInt(kSession -> kSession.getNumberOfConnections()).reduce(0,
Integer::sum);
}
public int getNumberOfWebrtcConnections() {
return this.kurentoSessions.values().stream().mapToInt(session -> session.getNumberOfWebrtcConnections())
return this.kurentoSessions.values().stream().mapToInt(kSession -> kSession.getNumberOfWebrtcConnections())
.reduce(0, Integer::sum);
}
public int getNumberOfComposedRecordings() {
return this.activeComposedRecordings.intValue();
}
}