From 32ca1dd9a03091daa35e150075d4edd36843445d Mon Sep 17 00:00:00 2001 From: norangebit Date: Sun, 3 May 2020 11:04:28 +0200 Subject: [PATCH] remove packet prototype --- .../drill09/average}/AverageNode.kt | 12 +++--- .../drill09/average}/Test.kt | 2 +- .../drill09/dbreplica}/DbNode.kt | 12 +++--- .../drill09/dbreplica}/Test.kt | 4 +- .../util/network/epidemic/EpidemicNode.kt | 15 +++---- .../util/network/epidemic/EpidemicPacket.kt | 41 ------------------- .../network/epidemic/replay/ReplayPacket.kt | 17 -------- .../network/simulator/packet/NetworkPacket.kt | 7 ---- .../util/network/simulator/packet/Packet.kt | 4 -- .../network/simulator/packet/PayloadPacket.kt | 4 -- 10 files changed, 24 insertions(+), 94 deletions(-) rename src/main/kotlin/{util/network/epidemic/consinstence => drills/drill09/average}/AverageNode.kt (82%) rename src/main/kotlin/{util/network/epidemic/consinstence => drills/drill09/average}/Test.kt (94%) rename src/main/kotlin/{util/network/epidemic/consinstence => drills/drill09/dbreplica}/DbNode.kt (80%) rename src/main/kotlin/{util/network/epidemic => drills/drill09/dbreplica}/Test.kt (87%) diff --git a/src/main/kotlin/util/network/epidemic/consinstence/AverageNode.kt b/src/main/kotlin/drills/drill09/average/AverageNode.kt similarity index 82% rename from src/main/kotlin/util/network/epidemic/consinstence/AverageNode.kt rename to src/main/kotlin/drills/drill09/average/AverageNode.kt index e6089cc..80d4bbc 100644 --- a/src/main/kotlin/util/network/epidemic/consinstence/AverageNode.kt +++ b/src/main/kotlin/drills/drill09/average/AverageNode.kt @@ -1,10 +1,8 @@ -package util.network.epidemic.consinstence +package drills.drill09.average import util.network.epidemic.EpidemicNode import util.network.epidemic.EpidemicPacket -import util.network.epidemic.EpidemicPacketPrototype import util.network.epidemic.replay.ReplayPacket -import util.network.epidemic.replay.ReplayPacketPrototype import util.network.simulator.Address import util.network.simulator.Network @@ -46,11 +44,13 @@ class AverageNode( Thread.interrupted() } - override fun makeInfectionPrototypePacket( + override fun makeInfectionPacket( + receiverAddress: Address, type: EpidemicPacket.Type - ): EpidemicPacketPrototype { - return ReplayPacketPrototype( + ): EpidemicPacket { + return ReplayPacket( address, + receiverAddress, nodeValue, type, false diff --git a/src/main/kotlin/util/network/epidemic/consinstence/Test.kt b/src/main/kotlin/drills/drill09/average/Test.kt similarity index 94% rename from src/main/kotlin/util/network/epidemic/consinstence/Test.kt rename to src/main/kotlin/drills/drill09/average/Test.kt index 9db4cb1..ae5aef9 100644 --- a/src/main/kotlin/util/network/epidemic/consinstence/Test.kt +++ b/src/main/kotlin/drills/drill09/average/Test.kt @@ -1,4 +1,4 @@ -package util.network.epidemic.consinstence +package drills.drill09.average import util.network.epidemic.EpidemicPacket import util.network.epidemic.replay.ReplayPacket diff --git a/src/main/kotlin/util/network/epidemic/consinstence/DbNode.kt b/src/main/kotlin/drills/drill09/dbreplica/DbNode.kt similarity index 80% rename from src/main/kotlin/util/network/epidemic/consinstence/DbNode.kt rename to src/main/kotlin/drills/drill09/dbreplica/DbNode.kt index 5a06bff..9e3b300 100644 --- a/src/main/kotlin/util/network/epidemic/consinstence/DbNode.kt +++ b/src/main/kotlin/drills/drill09/dbreplica/DbNode.kt @@ -1,10 +1,8 @@ -package util.network.epidemic.consinstence +package drills.drill09.dbreplica import util.network.epidemic.TimePayload import util.network.epidemic.EpidemicNode import util.network.epidemic.EpidemicPacket -import util.network.epidemic.EpidemicPacketPrototype -import util.network.epidemic.replay.ReplayPacketPrototype import util.network.simulator.Address import util.network.simulator.Network @@ -42,9 +40,13 @@ class DbNode( Thread.sleep(100) } - override fun makeInfectionPrototypePacket(type: EpidemicPacket.Type): EpidemicPacketPrototype> { - return EpidemicPacketPrototype( + override fun makeInfectionPacket( + receiverAddress: Address, + type: EpidemicPacket.Type + ): EpidemicPacket> { + return EpidemicPacket( address, + receiverAddress, nodeValue, type ) diff --git a/src/main/kotlin/util/network/epidemic/Test.kt b/src/main/kotlin/drills/drill09/dbreplica/Test.kt similarity index 87% rename from src/main/kotlin/util/network/epidemic/Test.kt rename to src/main/kotlin/drills/drill09/dbreplica/Test.kt index 625f0de..0c80018 100644 --- a/src/main/kotlin/util/network/epidemic/Test.kt +++ b/src/main/kotlin/drills/drill09/dbreplica/Test.kt @@ -1,6 +1,6 @@ -package util.network.epidemic +package drills.drill09.dbreplica -import util.network.epidemic.consinstence.DbNode +import util.network.epidemic.TimePayload import util.network.simulator.Address import util.network.simulator.Network diff --git a/src/main/kotlin/util/network/epidemic/EpidemicNode.kt b/src/main/kotlin/util/network/epidemic/EpidemicNode.kt index 02d1c23..5c2d0c6 100644 --- a/src/main/kotlin/util/network/epidemic/EpidemicNode.kt +++ b/src/main/kotlin/util/network/epidemic/EpidemicNode.kt @@ -21,7 +21,7 @@ abstract class EpidemicNode>( } private fun sendToRandom( - packetPrototype: EpidemicPacketPrototype, + type: EpidemicPacket.Type, numberOfReceiver: Int = 1 ) { val toExclude = mutableListOf(address) @@ -31,31 +31,32 @@ abstract class EpidemicNode>( receiverAddress = network.getRandomAddress() toExclude.add(receiverAddress) - send(packetPrototype.makePacket(receiverAddress)) + send(makeInfectionPacket(receiverAddress, type)) } } - abstract fun makeInfectionPrototypePacket( + abstract fun makeInfectionPacket( + receiverAddress: Address, type: EpidemicPacket.Type - ): EpidemicPacketPrototype + ): EpidemicPacket protected fun sendPush(numberOfReceiver: Int = 1) { sendToRandom( - makeInfectionPrototypePacket(EpidemicPacket.Type.PUSH), + EpidemicPacket.Type.PUSH, numberOfReceiver ) } protected fun sendPull(numberOfReceiver: Int = 1) { sendToRandom( - makeInfectionPrototypePacket(EpidemicPacket.Type.PULL), + EpidemicPacket.Type.PULL, numberOfReceiver ) } protected fun sendPushPull(numberOfReceiver: Int = 1) { sendToRandom( - makeInfectionPrototypePacket(EpidemicPacket.Type.PUSHPULL), + EpidemicPacket.Type.PUSHPULL, numberOfReceiver ) } diff --git a/src/main/kotlin/util/network/epidemic/EpidemicPacket.kt b/src/main/kotlin/util/network/epidemic/EpidemicPacket.kt index 5429f2c..469f2b5 100644 --- a/src/main/kotlin/util/network/epidemic/EpidemicPacket.kt +++ b/src/main/kotlin/util/network/epidemic/EpidemicPacket.kt @@ -1,9 +1,7 @@ package util.network.epidemic import util.network.simulator.Address -import util.network.simulator.packet.Packet import util.network.simulator.packet.PayloadPacket -import util.network.simulator.packet.PayloadPacketPrototype open class EpidemicPacket( override val senderAddress: Address, @@ -12,48 +10,9 @@ open class EpidemicPacket( val type: Type ) : PayloadPacket { - fun clone( - senderAddress: Address = this.senderAddress, - receiverAddress: Address = this.receiverAddress, - payload: T = this.payload, - type: Type = this.type - ): EpidemicPacket = - EpidemicPacket(senderAddress, receiverAddress, payload, type) - enum class Type { PUSH, PULL, PUSHPULL, REPLY } - companion object { - fun createFromNetworkPacket( - packet: Packet, - payload: TimePayload, - type: Type - ): EpidemicPacket> = EpidemicPacket( - packet.senderAddress, - packet.receiverAddress, - payload, - type - ) - - fun createFromPayloadPacket( - packet: PayloadPacket>, - type: Type - ): EpidemicPacket> = EpidemicPacket( - packet.senderAddress, - packet.receiverAddress, - packet.payload, - type - ) - } } -open class EpidemicPacketPrototype( - override val senderAddress: Address, - override val payload: T, - val type: EpidemicPacket.Type -) : PayloadPacketPrototype { - open fun makePacket(receiverAddress: Address): EpidemicPacket { - return EpidemicPacket(senderAddress, receiverAddress, payload, type) - } -} diff --git a/src/main/kotlin/util/network/epidemic/replay/ReplayPacket.kt b/src/main/kotlin/util/network/epidemic/replay/ReplayPacket.kt index 4d11798..b3eb725 100644 --- a/src/main/kotlin/util/network/epidemic/replay/ReplayPacket.kt +++ b/src/main/kotlin/util/network/epidemic/replay/ReplayPacket.kt @@ -1,7 +1,6 @@ package util.network.epidemic.replay import util.network.epidemic.EpidemicPacket -import util.network.epidemic.EpidemicPacketPrototype import util.network.simulator.Address class ReplayPacket( @@ -12,19 +11,3 @@ class ReplayPacket( val isReplay: Boolean ) : EpidemicPacket(senderAddress, receiverAddress, payload, type) -class ReplayPacketPrototype ( - senderAddress: Address, - payload: T, - type: EpidemicPacket.Type, - val isReplay: Boolean -) : EpidemicPacketPrototype(senderAddress, payload, type) { - override fun makePacket(receiverAddress: Address): EpidemicPacket { - return ReplayPacket( - senderAddress, - receiverAddress, - payload, - type, - isReplay - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/util/network/simulator/packet/NetworkPacket.kt b/src/main/kotlin/util/network/simulator/packet/NetworkPacket.kt index f1d9e37..8ffa831 100644 --- a/src/main/kotlin/util/network/simulator/packet/NetworkPacket.kt +++ b/src/main/kotlin/util/network/simulator/packet/NetworkPacket.kt @@ -7,10 +7,3 @@ data class NetworkPacket( override val receiverAddress: Address ) : Packet -data class NetworkPacketPrototype( - override val senderAddress: Address -): PacketPrototype { - fun makePacket(receiverAddress: Address): NetworkPacket { - return NetworkPacket(senderAddress, receiverAddress) - } -} diff --git a/src/main/kotlin/util/network/simulator/packet/Packet.kt b/src/main/kotlin/util/network/simulator/packet/Packet.kt index 8083556..668f46f 100644 --- a/src/main/kotlin/util/network/simulator/packet/Packet.kt +++ b/src/main/kotlin/util/network/simulator/packet/Packet.kt @@ -6,7 +6,3 @@ interface Packet { val senderAddress: Address val receiverAddress: Address } - -interface PacketPrototype { - val senderAddress: Address -} diff --git a/src/main/kotlin/util/network/simulator/packet/PayloadPacket.kt b/src/main/kotlin/util/network/simulator/packet/PayloadPacket.kt index bc23b2c..669abee 100644 --- a/src/main/kotlin/util/network/simulator/packet/PayloadPacket.kt +++ b/src/main/kotlin/util/network/simulator/packet/PayloadPacket.kt @@ -3,7 +3,3 @@ package util.network.simulator.packet interface PayloadPacket: Packet { val payload: T } - -interface PayloadPacketPrototype : PacketPrototype { - val payload: T -} \ No newline at end of file