mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: abstract KmsManager increment and decrement active recordings
parent
5295a3a497
commit
e241d3ff0e
|
@ -20,6 +20,7 @@ package io.openvidu.server.kurento.kms;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
|
@ -63,6 +64,24 @@ public class FixedOneKmsManager extends KmsManager {
|
|||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementActiveRecordings(String mediaNodeId) {
|
||||
try {
|
||||
this.getKmss().iterator().next().incrementActiveRecordings();
|
||||
} catch (NoSuchElementException e) {
|
||||
log.error("There is no KMS available when incrementing active recordings");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decrementActiveRecordings(String mediaNodeId) {
|
||||
try {
|
||||
this.getKmss().iterator().next().decrementActiveRecordings();
|
||||
} catch (NoSuchElementException e) {
|
||||
log.error("There is no KMS available when decrementing active recordings");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@PostConstruct
|
||||
protected void postConstructInitKurentoClients() {
|
||||
|
|
|
@ -42,8 +42,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import io.openvidu.client.OpenViduException;
|
||||
import io.openvidu.client.OpenViduException.Code;
|
||||
import io.openvidu.server.config.OpenviduConfig;
|
||||
import io.openvidu.server.core.IdentifierPrefixes;
|
||||
import io.openvidu.server.kurento.core.KurentoSession;
|
||||
|
@ -351,67 +349,6 @@ public abstract class KmsManager {
|
|||
return intervals[intervals.length - 1][0];
|
||||
}
|
||||
|
||||
public void incrementActiveRecordings(String mediaNodeId) throws OpenViduException {
|
||||
try {
|
||||
if (KmsManager.selectAndRemoveKmsLock.tryLock(KmsManager.MAX_SECONDS_LOCK_WAIT, TimeUnit.SECONDS)) {
|
||||
try {
|
||||
final Kms kms = this.getKms(mediaNodeId);
|
||||
if (kms == null) {
|
||||
throw new OpenViduException(Code.MEDIA_NODE_NOT_FOUND,
|
||||
"Media Node " + mediaNodeId + " does not exist");
|
||||
}
|
||||
kms.incrementActiveRecordings();
|
||||
log.info("Incremented number of active recordings in Media Node {}. Current number: {}",
|
||||
mediaNodeId, kms.getActiveRecordings());
|
||||
|
||||
if (!isMediaNodeAvailableForRecording(mediaNodeId)) {
|
||||
throw new OpenViduException(Code.MEDIA_NODE_STATUS_WRONG,
|
||||
"Media Node " + mediaNodeId + " does not allow starting new Recordings");
|
||||
}
|
||||
|
||||
} finally {
|
||||
KmsManager.selectAndRemoveKmsLock.unlock();
|
||||
}
|
||||
} else {
|
||||
throw new OpenViduException(Code.GENERIC_ERROR_CODE,
|
||||
"selectAndRemoveKmsLock couldn't be acquired within " + KmsManager.MAX_SECONDS_LOCK_WAIT
|
||||
+ " seconds when incrementing active recordings of Media Node " + mediaNodeId);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new OpenViduException(Code.GENERIC_ERROR_CODE,
|
||||
"InterruptedException waiting to acquire selectAndRemoveKmsLock when incrementing active recordings of Media Node "
|
||||
+ mediaNodeId + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void decrementActiveRecordings(String mediaNodeId) throws OpenViduException {
|
||||
try {
|
||||
if (KmsManager.selectAndRemoveKmsLock.tryLock(KmsManager.MAX_SECONDS_LOCK_WAIT, TimeUnit.SECONDS)) {
|
||||
try {
|
||||
final Kms kms = this.getKms(mediaNodeId);
|
||||
if (kms != null) {
|
||||
kms.decrementActiveRecordings();
|
||||
log.info("Decremented number of active recordings in Media Node {}. Current number: {}",
|
||||
mediaNodeId, kms.getActiveRecordings());
|
||||
} else {
|
||||
log.warn("Trying to decrement active recordings of Media Node {} but cannot be found",
|
||||
mediaNodeId);
|
||||
}
|
||||
} finally {
|
||||
KmsManager.selectAndRemoveKmsLock.unlock();
|
||||
}
|
||||
} else {
|
||||
throw new OpenViduException(Code.GENERIC_ERROR_CODE,
|
||||
"selectAndRemoveKmsLock couldn't be acquired within " + KmsManager.MAX_SECONDS_LOCK_WAIT
|
||||
+ " seconds when decrementing active recordings of Media Node " + mediaNodeId);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
throw new OpenViduException(Code.GENERIC_ERROR_CODE,
|
||||
"InterruptedException waiting to acquire selectAndRemoveKmsLock when decrementing active recordings of Media Node "
|
||||
+ mediaNodeId + ": " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public abstract List<Kms> initializeKurentoClients(List<KmsProperties> kmsProperties, boolean disconnectUponFailure)
|
||||
throws Exception;
|
||||
|
||||
|
@ -419,6 +356,10 @@ public abstract class KmsManager {
|
|||
|
||||
public abstract boolean isMediaNodeAvailableForRecording(String mediaNodeId);
|
||||
|
||||
public abstract void incrementActiveRecordings(String mediaNodeId);
|
||||
|
||||
public abstract void decrementActiveRecordings(String mediaNodeId);
|
||||
|
||||
@PostConstruct
|
||||
protected abstract void postConstructInitKurentoClients();
|
||||
|
||||
|
|
Loading…
Reference in New Issue