will use spring boot for json-rpc endpoints

pull/53/head
Zlatin Balevsky 2020-04-28 17:03:00 +01:00
parent 4aed958319
commit 7be3821e53
3 changed files with 20 additions and 41 deletions

View File

@ -10,18 +10,32 @@ buildscript {
}
}
plugins {
id 'org.springframework.boot' version '2.2.6.RELEASE'
}
apply plugin : 'application'
apply plugin : 'io.spring.dependency-management'
application {
mainClassName = 'com.muwire.tracker.Tracker'
applicationDefaultJvmArgs = ['-Djava.util.logging.config.file=logging.properties','-Xmx256M']
applicationDefaultJvmArgs = ['-Djava.util.logging.config.file=logging.properties','-Xmx256M',"-Dbuild.version=${project.version}"]
applicationName = 'mwtrackerd'
}
apply plugin : 'com.github.johnrengelman.shadow'
springBoot {
buildInfo {
properties {
version = "${project.version}"
name = "mwtrackerd"
}
}
}
dependencies {
compile project(":core")
compile 'com.github.arteam:simple-json-rpc-server:1.0'
compile 'com.github.briandilley.jsonrpc4j:jsonrpc4j:1.5.3'
}

View File

@ -4,7 +4,6 @@ import java.nio.charset.StandardCharsets
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import com.github.arteam.simplejsonrpc.server.JsonRpcServer
import com.muwire.core.Core
import com.muwire.core.MuWireSettings
import com.muwire.core.UILoadedEvent
@ -12,10 +11,10 @@ import com.muwire.core.files.AllFilesLoadedEvent
class Tracker {
private static final String VERSION = "0.6.12"
private static final ExecutorService EXECUTOR_SERVICE = Executors.newCachedThreadPool()
private static final String VERSION = System.getProperty("build.version")
public static void main(String [] args) {
println "Launching MuWire Tracker version $VERSION"
@ -74,9 +73,6 @@ class Tracker {
InetAddress toBind = InetAddress.getByName(p['jsonrpc.iface'])
int port = Integer.parseInt(p['jsonrpc.port'])
ServerSocket ss = new ServerSocket(port, Integer.MAX_VALUE, toBind)
println "json rpc listening on $toBind:$port"
JsonRpcServer rpcServer = new JsonRpcServer()
Core core = new Core(muSettings, home, VERSION)
@ -92,34 +88,7 @@ class Tracker {
core.eventBus.publish(new UILoadedEvent())
} as Runnable)
coreStarter.start()
try {
while(true) {
Socket s = ss.accept()
println "accepted connection from " + s.getInetAddress()
EXECUTOR_SERVICE.submit {
try {
def reader = new BufferedReader(new InputStreamReader(s.getInputStream()))
String request;
while((request = reader.readLine()) != null) {
println "got request \"$request\""
String response = rpcServer.handle(request, trackerService)
println "sending response \"$response\""
s.getOutputStream().newWriter("UTF-8").write(response)
s.getOutputStream().write("\n".getBytes(StandardCharsets.US_ASCII))
s.getOutputStream().flush()
}
} catch (Exception bad) {
bad.printStackTrace()
} finally {
s.close()
}
} as Runnable
}
} catch (Exception bad) {
bad.printStackTrace()
}
// TODO: rewrite as Spring app
}
}

View File

@ -1,11 +1,8 @@
package com.muwire.tracker
import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcMethod
import com.github.arteam.simplejsonrpc.core.annotation.JsonRpcService
import com.muwire.core.Core
import com.muwire.core.UILoadedEvent
@JsonRpcService
class TrackerService {
private final TrackerStatus status = new TrackerStatus()
@ -16,7 +13,6 @@ class TrackerService {
status.status = "Starting"
}
@JsonRpcMethod
public TrackerStatus status() {
status.connections = core.getConnectionManager().getConnections().size()
status