Skip to content

Commit

Permalink
ref: Refactor the way Application is initialized. (jitsi#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrozev authored Jul 9, 2024
1 parent 6b5c8c5 commit 1ccfaeb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
27 changes: 3 additions & 24 deletions jicofo/src/main/java/org/jitsi/jicofo/rest/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@

import org.glassfish.hk2.utilities.binding.*;
import org.glassfish.jersey.server.*;
import org.jetbrains.annotations.*;
import org.jitsi.jicofo.health.*;
import org.jitsi.jicofo.metrics.*;
import org.jitsi.rest.prometheus.*;
import org.jitsi.utils.version.*;

import java.time.*;
import java.util.*;

/**
* Adds the configuration for the REST web endpoints.
Expand All @@ -33,9 +29,7 @@ public class Application
{
protected final Clock clock = Clock.systemUTC();

public Application(@NotNull Version version,
JicofoHealthChecker healthChecker,
ConferenceRequest conferenceRequest)
public Application(List<Object> components)
{
register(new AbstractBinder()
{
Expand All @@ -47,21 +41,6 @@ protected void configure()
});
packages("org.jitsi.jicofo.rest");

if (healthChecker != null)
{
register(new org.jitsi.rest.Health(healthChecker));
}

register(new org.jitsi.rest.Version(version));

if (RestConfig.config.getEnablePrometheus())
{
register(new Prometheus(JicofoMetricsContainer.getInstance()));
}

if (conferenceRequest != null)
{
register(conferenceRequest);
}
components.forEach(this::register);
}
}
20 changes: 14 additions & 6 deletions jicofo/src/main/kotlin/org/jitsi/jicofo/JicofoServices.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ import org.jitsi.jicofo.version.CurrentVersionImpl
import org.jitsi.jicofo.xmpp.XmppServices
import org.jitsi.jicofo.xmpp.initializeSmack
import org.jitsi.jicofo.xmpp.jingle.JingleStats
import org.jitsi.rest.Version
import org.jitsi.rest.createServer
import org.jitsi.rest.prometheus.Prometheus
import org.jitsi.rest.servletContextHandler
import org.jitsi.utils.OrderedJsonObject
import org.jitsi.utils.logging2.createLogger
Expand Down Expand Up @@ -145,12 +147,18 @@ class JicofoServices {
jettyServer = if (RestConfig.config.enabled) {
logger.info("Starting HTTP server with config: ${RestConfig.config.httpServerConfig}.")
val restApp = Application(
CurrentVersionImpl.VERSION,
healthChecker,
if (RestConfig.config.enableConferenceRequest) {
ConferenceRequest(xmppServices.conferenceIqHandler)
} else {
null
buildList
{
healthChecker?.let {
add(org.jitsi.rest.Health(it))
}
add(Version(CurrentVersionImpl.VERSION))
if (RestConfig.config.enableConferenceRequest) {
add(ConferenceRequest(xmppServices.conferenceIqHandler))
}
if (RestConfig.config.enablePrometheus) {
add(Prometheus(JicofoMetricsContainer.instance))
}
}
)
createServer(RestConfig.config.httpServerConfig).also {
Expand Down

0 comments on commit 1ccfaeb

Please sign in to comment.