From 7be3821e5304072ad809c572e07eec25f8d5e46d Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Tue, 28 Apr 2020 17:03:00 +0100 Subject: [PATCH] will use spring boot for json-rpc endpoints --- tracker/build.gradle | 18 ++++++++- .../groovy/com/muwire/tracker/Tracker.groovy | 39 ++----------------- .../com/muwire/tracker/TrackerService.groovy | 4 -- 3 files changed, 20 insertions(+), 41 deletions(-) diff --git a/tracker/build.gradle b/tracker/build.gradle index 60c438cf..e452dbf2 100644 --- a/tracker/build.gradle +++ b/tracker/build.gradle @@ -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' } diff --git a/tracker/src/main/groovy/com/muwire/tracker/Tracker.groovy b/tracker/src/main/groovy/com/muwire/tracker/Tracker.groovy index f194dd69..e287b21e 100644 --- a/tracker/src/main/groovy/com/muwire/tracker/Tracker.groovy +++ b/tracker/src/main/groovy/com/muwire/tracker/Tracker.groovy @@ -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 } } diff --git a/tracker/src/main/groovy/com/muwire/tracker/TrackerService.groovy b/tracker/src/main/groovy/com/muwire/tracker/TrackerService.groovy index 02778993..60358975 100644 --- a/tracker/src/main/groovy/com/muwire/tracker/TrackerService.groovy +++ b/tracker/src/main/groovy/com/muwire/tracker/TrackerService.groovy @@ -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