hello spring boot

This commit is contained in:
Zlatin Balevsky
2020-04-28 18:11:26 +01:00
parent 7be3821e53
commit d34c4e1990
4 changed files with 36 additions and 7 deletions

View File

@ -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'
}

View File

@ -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
}
}

View File

@ -0,0 +1,5 @@
package com.muwire.tracker;
public interface TrackerService {
public TrackerStatus status();
}

View File

@ -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"
}