main server refactoring
This commit is contained in:
@@ -4,7 +4,6 @@ import net.car.Dropper
|
|||||||
import net.car.client.Client
|
import net.car.client.Client
|
||||||
import objects.Environment
|
import objects.Environment
|
||||||
|
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
var roomScanner: RoomScanner? = null
|
var roomScanner: RoomScanner? = null
|
||||||
val carServer = net.car.server.Server.createCarServerThread()
|
val carServer = net.car.server.Server.createCarServerThread()
|
||||||
@@ -21,7 +20,6 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//todo запуск потока алгоритма нужно вынести сюда,
|
//todo запуск потока алгоритма нужно вынести сюда,
|
||||||
//todo а debug интерфейсутребуется исключительно возможность установки кол-ва итераций
|
//todo а debug интерфейсутребуется исключительно возможность установки кол-ва итераций
|
||||||
//CL user interface
|
//CL user interface
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import kotlin.concurrent.thread
|
|||||||
|
|
||||||
object Dropper {
|
object Dropper {
|
||||||
|
|
||||||
|
private val WAIT_TIMEOUT = 2L * 60 * 1000
|
||||||
|
|
||||||
fun createCarsDestroyThread(): Thread {
|
fun createCarsDestroyThread(): Thread {
|
||||||
return thread(false, false, null, "dropCar", -1, getThreadCode())
|
return thread(false, false, null, "dropCar", -1, getThreadCode())
|
||||||
}
|
}
|
||||||
@@ -19,7 +21,7 @@ object Dropper {
|
|||||||
dropInactiveCar(Environment)
|
dropInactiveCar(Environment)
|
||||||
})
|
})
|
||||||
try {
|
try {
|
||||||
Thread.sleep(120000)
|
Thread.sleep(WAIT_TIMEOUT)
|
||||||
} catch (e: InterruptedException) {
|
} catch (e: InterruptedException) {
|
||||||
println("thread for destroy cars stopped")
|
println("thread for destroy cars stopped")
|
||||||
stopped = true
|
stopped = true
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import java.rmi.UnexpectedException
|
|||||||
object Client {
|
object Client {
|
||||||
|
|
||||||
private val client = DefaultAsyncHttpClient()
|
private val client = DefaultAsyncHttpClient()
|
||||||
private val timeout = 5 * 60 * 60 * 1000
|
private val TIMEOUT = 5 * 60 * 60 * 1000
|
||||||
|
|
||||||
enum class Request(val url: String) {
|
enum class Request(val url: String) {
|
||||||
CONNECT("connect"),
|
CONNECT("connect"),
|
||||||
@@ -27,6 +27,6 @@ object Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun makeRequest(request: String, data: ByteArray): ListenableFuture<Response> =
|
fun makeRequest(request: String, data: ByteArray): ListenableFuture<Response> =
|
||||||
client.preparePost(request).setBody(data).setRequestTimeout(timeout).execute() ?: throw UnexpectedException(request)
|
client.preparePost(request).setBody(data).setRequestTimeout(TIMEOUT).execute() ?: throw UnexpectedException(request)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,10 @@ package objects
|
|||||||
|
|
||||||
|
|
||||||
class Car constructor(val uid: Int, host: String, port: Int) {
|
class Car constructor(val uid: Int, host: String, port: Int) {
|
||||||
|
|
||||||
var x = 0.0
|
var x = 0.0
|
||||||
var y = 0.0
|
var y = 0.0
|
||||||
var angle = 0.0
|
var angle = 0.0
|
||||||
|
val carConnection = CarConnection(host, port)
|
||||||
val carConnection: CarConnection
|
|
||||||
|
|
||||||
init {
|
|
||||||
carConnection = CarConnection(host, port)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return "$uid ; x:$x; y:$y; target:$angle"
|
return "$uid ; x:$x; y:$y; target:$angle"
|
||||||
|
|||||||
@@ -6,9 +6,7 @@ import org.asynchttpclient.Response
|
|||||||
|
|
||||||
|
|
||||||
class CarConnection(val host: String, val port: Int) {
|
class CarConnection(val host: String, val port: Int) {
|
||||||
|
|
||||||
fun sendRequest(request: Client.Request, data: ByteArray): ListenableFuture<Response> {
|
fun sendRequest(request: Client.Request, data: ByteArray): ListenableFuture<Response> {
|
||||||
return Client.makeRequest("http://$host:$port/${request.url}", data)
|
return Client.makeRequest("http://$host:$port/${request.url}", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user