diff --git a/tracker/build.gradle b/tracker/build.gradle index e452dbf2..a13de7de 100644 --- a/tracker/build.gradle +++ b/tracker/build.gradle @@ -37,5 +37,9 @@ springBoot { dependencies { compile project(":core") compile 'com.github.briandilley.jsonrpc4j:jsonrpc4j:1.5.3' + + compile 'org.springframework.boot:spring-boot-starter' + compile 'org.springframework.boot:spring-boot-starter-actuator' + compile 'org.springframework.boot:spring-boot-starter-web' } diff --git a/tracker/src/main/groovy/com/muwire/tracker/Tracker.groovy b/tracker/src/main/groovy/com/muwire/tracker/Tracker.groovy index e287b21e..5dc72dc3 100644 --- a/tracker/src/main/groovy/com/muwire/tracker/Tracker.groovy +++ b/tracker/src/main/groovy/com/muwire/tracker/Tracker.groovy @@ -4,17 +4,24 @@ import java.nio.charset.StandardCharsets import java.util.concurrent.ExecutorService import java.util.concurrent.Executors +import org.springframework.boot.SpringApplication +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.context.annotation.Bean + +import com.googlecode.jsonrpc4j.spring.JsonServiceExporter import com.muwire.core.Core import com.muwire.core.MuWireSettings import com.muwire.core.UILoadedEvent import com.muwire.core.files.AllFilesLoadedEvent +@SpringBootApplication class Tracker { - private static final ExecutorService EXECUTOR_SERVICE = Executors.newCachedThreadPool() - private static final String VERSION = System.getProperty("build.version") + private static Core core + private static TrackerService trackerService + public static void main(String [] args) { println "Launching MuWire Tracker version $VERSION" @@ -74,11 +81,11 @@ class Tracker { InetAddress toBind = InetAddress.getByName(p['jsonrpc.iface']) int port = Integer.parseInt(p['jsonrpc.port']) - Core core = new Core(muSettings, home, VERSION) + core = new Core(muSettings, home, VERSION) // init json service object - TrackerService trackerService = new TrackerService() + trackerService = new TrackerServiceImpl(core) core.eventBus.with { register(UILoadedEvent.class, trackerService) } @@ -89,6 +96,19 @@ class Tracker { } as Runnable) coreStarter.start() - // TODO: rewrite as Spring app + SpringApplication.run(Tracker.class, args) + } + + @Bean + public TrackerService trackerService() { + trackerService + } + + @Bean(name = '/tracker') + public JsonServiceExporter jsonServiceExporter() { + def exporter = new JsonServiceExporter() + exporter.setService(trackerService()) + exporter.setServiceInterface(TrackerService.class) + exporter } } diff --git a/tracker/src/main/groovy/com/muwire/tracker/TrackerService.java b/tracker/src/main/groovy/com/muwire/tracker/TrackerService.java new file mode 100644 index 00000000..aaae77c2 --- /dev/null +++ b/tracker/src/main/groovy/com/muwire/tracker/TrackerService.java @@ -0,0 +1,5 @@ +package com.muwire.tracker; + +public interface TrackerService { + public TrackerStatus status(); +} diff --git a/tracker/src/main/groovy/com/muwire/tracker/TrackerService.groovy b/tracker/src/main/groovy/com/muwire/tracker/TrackerServiceImpl.groovy similarity index 84% rename from tracker/src/main/groovy/com/muwire/tracker/TrackerService.groovy rename to tracker/src/main/groovy/com/muwire/tracker/TrackerServiceImpl.groovy index 60358975..573ad1c7 100644 --- a/tracker/src/main/groovy/com/muwire/tracker/TrackerService.groovy +++ b/tracker/src/main/groovy/com/muwire/tracker/TrackerServiceImpl.groovy @@ -3,12 +3,12 @@ package com.muwire.tracker import com.muwire.core.Core import com.muwire.core.UILoadedEvent -class TrackerService { +class TrackerServiceImpl implements TrackerService { private final TrackerStatus status = new TrackerStatus() private final Core core - TrackerService(Core core) { + TrackerServiceImpl(Core core) { this.core = core status.status = "Starting" }