mirror of https://github.com/zlatinb/muwire
will use spring boot for json-rpc endpoints
parent
4aed958319
commit
7be3821e53
|
@ -10,18 +10,32 @@ buildscript {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id 'org.springframework.boot' version '2.2.6.RELEASE'
|
||||||
|
}
|
||||||
|
|
||||||
apply plugin : 'application'
|
apply plugin : 'application'
|
||||||
|
apply plugin : 'io.spring.dependency-management'
|
||||||
|
|
||||||
application {
|
application {
|
||||||
mainClassName = 'com.muwire.tracker.Tracker'
|
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'
|
applicationName = 'mwtrackerd'
|
||||||
}
|
}
|
||||||
|
|
||||||
apply plugin : 'com.github.johnrengelman.shadow'
|
apply plugin : 'com.github.johnrengelman.shadow'
|
||||||
|
|
||||||
|
springBoot {
|
||||||
|
buildInfo {
|
||||||
|
properties {
|
||||||
|
version = "${project.version}"
|
||||||
|
name = "mwtrackerd"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(":core")
|
compile project(":core")
|
||||||
compile 'com.github.arteam:simple-json-rpc-server:1.0'
|
compile 'com.github.briandilley.jsonrpc4j:jsonrpc4j:1.5.3'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import java.nio.charset.StandardCharsets
|
||||||
import java.util.concurrent.ExecutorService
|
import java.util.concurrent.ExecutorService
|
||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
|
|
||||||
import com.github.arteam.simplejsonrpc.server.JsonRpcServer
|
|
||||||
import com.muwire.core.Core
|
import com.muwire.core.Core
|
||||||
import com.muwire.core.MuWireSettings
|
import com.muwire.core.MuWireSettings
|
||||||
import com.muwire.core.UILoadedEvent
|
import com.muwire.core.UILoadedEvent
|
||||||
|
@ -12,10 +11,10 @@ import com.muwire.core.files.AllFilesLoadedEvent
|
||||||
|
|
||||||
class Tracker {
|
class Tracker {
|
||||||
|
|
||||||
private static final String VERSION = "0.6.12"
|
|
||||||
|
|
||||||
private static final ExecutorService EXECUTOR_SERVICE = Executors.newCachedThreadPool()
|
private static final ExecutorService EXECUTOR_SERVICE = Executors.newCachedThreadPool()
|
||||||
|
|
||||||
|
private static final String VERSION = System.getProperty("build.version")
|
||||||
|
|
||||||
public static void main(String [] args) {
|
public static void main(String [] args) {
|
||||||
println "Launching MuWire Tracker version $VERSION"
|
println "Launching MuWire Tracker version $VERSION"
|
||||||
|
|
||||||
|
@ -74,9 +73,6 @@ class Tracker {
|
||||||
|
|
||||||
InetAddress toBind = InetAddress.getByName(p['jsonrpc.iface'])
|
InetAddress toBind = InetAddress.getByName(p['jsonrpc.iface'])
|
||||||
int port = Integer.parseInt(p['jsonrpc.port'])
|
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)
|
Core core = new Core(muSettings, home, VERSION)
|
||||||
|
|
||||||
|
@ -93,33 +89,6 @@ class Tracker {
|
||||||
} as Runnable)
|
} as Runnable)
|
||||||
coreStarter.start()
|
coreStarter.start()
|
||||||
|
|
||||||
|
// TODO: rewrite as Spring app
|
||||||
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()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
package com.muwire.tracker
|
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.Core
|
||||||
import com.muwire.core.UILoadedEvent
|
import com.muwire.core.UILoadedEvent
|
||||||
|
|
||||||
@JsonRpcService
|
|
||||||
class TrackerService {
|
class TrackerService {
|
||||||
|
|
||||||
private final TrackerStatus status = new TrackerStatus()
|
private final TrackerStatus status = new TrackerStatus()
|
||||||
|
@ -16,7 +13,6 @@ class TrackerService {
|
||||||
status.status = "Starting"
|
status.status = "Starting"
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonRpcMethod
|
|
||||||
public TrackerStatus status() {
|
public TrackerStatus status() {
|
||||||
status.connections = core.getConnectionManager().getConnections().size()
|
status.connections = core.getConnectionManager().getConnections().size()
|
||||||
status
|
status
|
||||||
|
|
Loading…
Reference in New Issue