From c04f1d207e92870577be792df7ca90c80b574450 Mon Sep 17 00:00:00 2001 From: MaximZaitsev Date: Tue, 23 Aug 2016 13:38:20 +0300 Subject: [PATCH] add command for shut down all threads --- server/src/main/java/DebugClInterface.kt | 3 ++- server/src/main/java/ServerMain.kt | 2 ++ server/src/main/java/car/client/Client.kt | 7 ++++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/DebugClInterface.kt b/server/src/main/java/DebugClInterface.kt index 6ccc155c82e..f47ae2ae0cb 100644 --- a/server/src/main/java/DebugClInterface.kt +++ b/server/src/main/java/DebugClInterface.kt @@ -15,7 +15,8 @@ class DebugClInterface { "refloc - refresh all car locations\n" + "sonar [car_id] - get sonar data\n" + "dbinfo [car_id] [type] - refresh all car locations\n." + - "type is string name of value or int value. available values: MEMORYSTATS - 0" + "type is string name of value or int value. available values: MEMORYSTATS - 0\n" + + "stop - exit from this interface and stop all threads\n" fun run() { diff --git a/server/src/main/java/ServerMain.kt b/server/src/main/java/ServerMain.kt index 59e866a4b5b..8a6caec7093 100644 --- a/server/src/main/java/ServerMain.kt +++ b/server/src/main/java/ServerMain.kt @@ -1,4 +1,5 @@ import car.Dropper +import car.client.Client val carServerPort: Int = 7925 val webServerPort: Int = 7926 @@ -23,4 +24,5 @@ fun main(args: Array) { carsDestroy.interrupt() carServer.interrupt() webServer.interrupt() + Client.shutDownClient() } diff --git a/server/src/main/java/car/client/Client.kt b/server/src/main/java/car/client/Client.kt index 83fc9bcb331..53ee3d1d478 100644 --- a/server/src/main/java/car/client/Client.kt +++ b/server/src/main/java/car/client/Client.kt @@ -10,17 +10,22 @@ import java.net.ConnectException object Client { + val group: NioEventLoopGroup = NioEventLoopGroup() val bootstrap: Bootstrap = makeBootstrap() private fun makeBootstrap(): Bootstrap { - val group = NioEventLoopGroup() val b = Bootstrap() b.group(group).channel(NioSocketChannel().javaClass).handler(ClientInitializer()) .attr(AttributeKey.newInstance("url"), "") .attr(AttributeKey.newInstance("uid"), 0) + .attr(AttributeKey.newInstance("angles"), IntArray(0)) return b } + fun shutDownClient() { + group.shutdownGracefully() + } + fun sendRequest(request: HttpRequest, host: String, port: Int, options: Map) { try { bootstrap.attr(AttributeKey.valueOf("url"), request.uri())