Skip to content

Commit

Permalink
ref: Remove unnecessary functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrozev committed Nov 12, 2024
1 parent 0090c0c commit cd92fa5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
17 changes: 6 additions & 11 deletions jicofo-selector/src/main/kotlin/org/jitsi/jicofo/bridge/Bridge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.jxmpp.jid.Jid
import java.time.Clock
import java.time.Duration
import java.time.Instant
import org.jitsi.jicofo.bridge.BridgeConfig.Companion.config as config

/**
* Represents a jitsi-videobridge instance, reachable at a certain JID, which
Expand All @@ -51,7 +52,7 @@ class Bridge @JvmOverloads internal constructor(
* Keep track of the recently added endpoints.
*/
private val newEndpointsRate = RateTracker(
BridgeConfig.config.participantRampupInterval(),
config.participantRampupInterval,
Duration.ofMillis(100),
clock
)
Expand Down Expand Up @@ -93,7 +94,7 @@ class Bridge @JvmOverloads internal constructor(
// To filter out intermittent failures, do not return operational
// until past the reset threshold since the last failure.
if (failureInstant != null &&
Duration.between(failureInstant, clock.instant()).compareTo(failureResetThreshold) < 0
Duration.between(failureInstant, clock.instant()).compareTo(config.failureResetThreshold) < 0
) {
false
} else {
Expand All @@ -110,7 +111,7 @@ class Bridge @JvmOverloads internal constructor(
/**
* Start out with the configured value, update if the bridge reports a value.
*/
private var averageParticipantStress = BridgeConfig.config.averageParticipantStress()
private var averageParticipantStress = config.averageParticipantStress

/**
* Stores a boolean that indicates whether the bridge is in graceful shutdown mode.
Expand Down Expand Up @@ -216,7 +217,7 @@ class Bridge @JvmOverloads internal constructor(
val healthy = stats.getValueAsString("healthy")
if (healthy != null) {
isHealthy = java.lang.Boolean.parseBoolean(healthy)
} else if (BridgeConfig.config.usePresenceForHealth) {
} else if (config.usePresenceForHealth) {
logger.warn(
"Presence-based health checks are enabled, but presence did not include health status. Health " +
"checks for this bridge are effectively disabled."
Expand Down Expand Up @@ -286,7 +287,7 @@ class Bridge @JvmOverloads internal constructor(
* @return true if the stress of the bridge is greater-than-or-equal to the threshold.
*/
val isOverloaded: Boolean
get() = stress >= BridgeConfig.config.stressThreshold()
get() = stress >= config.stressThreshold

val debugState: OrderedJsonObject
get() {
Expand All @@ -306,12 +307,6 @@ class Bridge @JvmOverloads internal constructor(
}

companion object {
/**
* How long the "failed" state should be sticky for. Once a [Bridge] goes in a non-operational state (via
* [.setIsOperational]) it will be considered non-operational for at least this amount of time.
* See the tests for example behavior.
*/
private val failureResetThreshold = BridgeConfig.config.failureResetThreshold()

/**
* Returns a negative number if b1 is more able to serve conferences than b2. The computation is based on the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,38 @@ class BridgeConfig private constructor() {
"org.jitsi.jicofo.BridgeSelector.MAX_PARTICIPANTS_PER_BRIDGE".from(JitsiConfig.legacyConfig)
"$BASE.max-bridge-participants".from(JitsiConfig.newConfig)
}
fun maxBridgeParticipants() = maxBridgeParticipants

val maxBridgePacketRatePps: Int by config {
"org.jitsi.jicofo.BridgeSelector.MAX_BRIDGE_PACKET_RATE".from(JitsiConfig.legacyConfig)
"$BASE.max-bridge-packet-rate".from(JitsiConfig.newConfig)
}
fun maxBridgePacketRatePps() = maxBridgePacketRatePps

val averageParticipantPacketRatePps: Int by config {
"org.jitsi.jicofo.BridgeSelector.AVG_PARTICIPANT_PACKET_RATE".from(JitsiConfig.legacyConfig)
"$BASE.average-participant-packet-rate-pps"
.from(JitsiConfig.newConfig).softDeprecated("use $BASE.average-participant-stress")
}
fun averageParticipantPacketRatePps() = averageParticipantPacketRatePps

val averageParticipantStress: Double by config {
"$BASE.average-participant-stress".from(JitsiConfig.newConfig)
}
fun averageParticipantStress() = averageParticipantStress

val stressThreshold: Double by config { "$BASE.stress-threshold".from(JitsiConfig.newConfig) }
fun stressThreshold() = stressThreshold

/**
* How long the "failed" state should be sticky for. Once a [Bridge] goes in a non-operational state (via
* [.setIsOperational]) it will be considered non-operational for at least this amount of time.
* See the tests for example behavior.
*/
val failureResetThreshold: Duration by config {
"org.jitsi.focus.BRIDGE_FAILURE_RESET_THRESHOLD".from(JitsiConfig.legacyConfig)
.convertFrom<Long> { Duration.ofMillis(it) }
"$BASE.failure-reset-threshold".from(JitsiConfig.newConfig)
}
fun failureResetThreshold() = failureResetThreshold

val participantRampupInterval: Duration by config {
"$BASE.participant-rampup-interval".from(JitsiConfig.newConfig)
}
fun participantRampupInterval() = participantRampupInterval

val selectionStrategy: BridgeSelectionStrategy by config {
"org.jitsi.jicofo.BridgeSelector.BRIDGE_SELECTION_STRATEGY".from(JitsiConfig.legacyConfig)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ abstract class BridgeSelectionStrategy {
*/
private var totalLeastLoaded = 0

/**
* Maximum participants per bridge in one conference, or `-1` for no maximum.
*/
private val maxParticipantsPerBridge = config.maxBridgeParticipants()

/**
* Selects a bridge to be used for a new participant in a conference.
*
Expand Down Expand Up @@ -401,9 +396,9 @@ abstract class BridgeSelectionStrategy {
*/
private fun isOverloaded(bridge: Bridge, conferenceBridges: Map<Bridge, ConferenceBridgeProperties>): Boolean {
return bridge.isOverloaded || (
maxParticipantsPerBridge > 0 &&
config.maxBridgeParticipants > 0 &&
conferenceBridges.containsKey(bridge) &&
conferenceBridges[bridge]!!.participantCount >= maxParticipantsPerBridge
conferenceBridges[bridge]!!.participantCount >= config.maxBridgeParticipants
)
}

Expand Down

0 comments on commit cd92fa5

Please sign in to comment.