This is an automated email from the ASF dual-hosted git repository. toulmean pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/incubator-tuweni.git
The following commit(s) were added to refs/heads/main by this push: new c0ed26f Replace the functions with an interface, pass the address new df266db Merge pull request #235 from atoulme/replace_with_controller c0ed26f is described below commit c0ed26f9e4d00d8bc3d61a5ef6112f42776aec38 Author: Antoine Toulme <anto...@lunar-ocean.com> AuthorDate: Fri May 7 00:43:54 2021 -0700 Replace the functions with an interface, pass the address --- .../apache/tuweni/ethstats/EthStatsReporterTest.kt | 12 +++---- .../org/apache/tuweni/ethstats/EthStatsServer.kt | 22 +++++------- .../tuweni/ethstats/EthStatsServerController.kt | 42 ++++++++++++++++++++++ 3 files changed, 56 insertions(+), 20 deletions(-) diff --git a/ethstats/src/integrationTest/kotlin/org/apache/tuweni/ethstats/EthStatsReporterTest.kt b/ethstats/src/integrationTest/kotlin/org/apache/tuweni/ethstats/EthStatsReporterTest.kt index 72a9da3..da2dda7 100644 --- a/ethstats/src/integrationTest/kotlin/org/apache/tuweni/ethstats/EthStatsReporterTest.kt +++ b/ethstats/src/integrationTest/kotlin/org/apache/tuweni/ethstats/EthStatsReporterTest.kt @@ -113,14 +113,14 @@ public class EthStatsReporterTest { val now = Instant.EPOCH val nodeInfoReference = AtomicReference<NodeInfo>() + val controller = object : EthStatsServerController { + override fun readNodeInfo(remoteAddress: String, id: String, nodeInfo: NodeInfo) { + nodeInfoReference.set(nodeInfo) + } + } val server = EthStatsServer( vertx, "127.0.0.1", 33030, "wat", { now }, - { _, info -> nodeInfoReference.set(info) }, - { _, _, _ -> }, - { _, _ -> }, - { _, _ -> }, - { }, - { _, _ -> }, + controller ) server.start() val reporter = EthStatsReporter( diff --git a/ethstats/src/main/kotlin/org/apache/tuweni/ethstats/EthStatsServer.kt b/ethstats/src/main/kotlin/org/apache/tuweni/ethstats/EthStatsServer.kt index 1a6a745..a926360 100644 --- a/ethstats/src/main/kotlin/org/apache/tuweni/ethstats/EthStatsServer.kt +++ b/ethstats/src/main/kotlin/org/apache/tuweni/ethstats/EthStatsServer.kt @@ -21,7 +21,6 @@ import com.fasterxml.jackson.databind.node.ArrayNode import io.vertx.core.Vertx import io.vertx.core.http.HttpServer import io.vertx.core.http.ServerWebSocket -import io.vertx.core.net.SocketAddress import io.vertx.kotlin.core.http.closeAwait import io.vertx.kotlin.core.http.listenAwait import kotlinx.coroutines.CoroutineScope @@ -38,13 +37,8 @@ class EthStatsServer( val networkInterface: String, var port: Int, val secret: String, - private val timeSupplier: () -> Instant, - private val nodeInfoReader: (String, NodeInfo) -> Unit, - private val latencyReader: (String, SocketAddress, Long) -> Unit, - private val pendingTxReader: (String, Long) -> Unit, - private val nodeStatsReader: (String, NodeStats) -> Unit, - private val disconnectionReader: (String) -> Unit, - private val blockReader: (String, BlockStats) -> Unit, + private val timeSupplier: () -> Instant = Instant::now, + private val controller: EthStatsServerController, override val coroutineContext: CoroutineContext = Dispatchers.Default, ) : CoroutineScope { @@ -107,7 +101,7 @@ class EthStatsServer( websocket.writeTextMessage("{\"emit\":[\"ready\"]}") val id = event.get(1).get("id").textValue() val nodeInfo = mapper.readerFor(NodeInfo::class.java).readValue<NodeInfo>(event.get(1).get("info")) - nodeInfoReader(id, nodeInfo) + controller.readNodeInfo(websocket.remoteAddress().toString(), id, nodeInfo) } ("node-ping") -> { logger.debug("Received a ping {}", event.get(1)) @@ -121,26 +115,26 @@ class EthStatsServer( ("latency") -> { val id = event.get(1).get("id").textValue() val latency = event.get(1).get("latency").longValue() - latencyReader(id, websocket.remoteAddress(), latency) + controller.readLatency(websocket.remoteAddress().toString(), id, websocket.remoteAddress(), latency) } ("end") -> { val id = event.get(1).get("id").textValue() - disconnectionReader(id) + controller.readDisconnect(websocket.remoteAddress().toString(), id) } ("stats") -> { val id = event.get(1).get("id").textValue() val nodeStats = mapper.readerFor(NodeStats::class.java).readValue<NodeStats>(event.get(1).get("stats")) - nodeStatsReader(id, nodeStats) + controller.readNodeStats(websocket.remoteAddress().toString(), id, nodeStats) } ("pending") -> { val id = event.get(1).get("id").textValue() val pendingTx = event.get(1).get("stats").get("pending").longValue() - pendingTxReader(id, pendingTx) + controller.readPendingTx(websocket.remoteAddress().toString(), id, pendingTx) } ("block") -> { val id = event.get(1).get("id").textValue() val block = mapper.readerFor(BlockStats::class.java).readValue<BlockStats>(event.get(1).get("block")) - blockReader(id, block) + controller.readBlock(websocket.remoteAddress().toString(), id, block) } ("update") -> { // TODO implement diff --git a/ethstats/src/main/kotlin/org/apache/tuweni/ethstats/EthStatsServerController.kt b/ethstats/src/main/kotlin/org/apache/tuweni/ethstats/EthStatsServerController.kt new file mode 100644 index 0000000..b296601 --- /dev/null +++ b/ethstats/src/main/kotlin/org/apache/tuweni/ethstats/EthStatsServerController.kt @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuweni.ethstats + +import io.vertx.core.net.SocketAddress + +/** + * Controller receiving information of all clients connected to the ethstats server. + */ +interface EthStatsServerController { + fun readNodeInfo(remoteAddress: String, id: String, nodeInfo: NodeInfo) { + } + + fun readLatency(remoteAddress: String, id: String, remoteAddress1: SocketAddress, latency: Long) { + } + + fun readDisconnect(remoteAddress: String, id: String) { + } + + fun readNodeStats(remoteAddress: String, id: String, nodeStats: NodeStats) { + } + + fun readPendingTx(remoteAddress: String, id: String, pendingTx: Long) { + } + + fun readBlock(remoteAddress: String, id: String, block: BlockStats) { + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@tuweni.apache.org For additional commands, e-mail: commits-h...@tuweni.apache.org