remove packet prototype
This commit is contained in:
parent
5688bd653a
commit
32ca1dd9a0
@ -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<Double> {
|
||||
return ReplayPacketPrototype(
|
||||
): EpidemicPacket<Double> {
|
||||
return ReplayPacket(
|
||||
address,
|
||||
receiverAddress,
|
||||
nodeValue,
|
||||
type,
|
||||
false
|
@ -1,4 +1,4 @@
|
||||
package util.network.epidemic.consinstence
|
||||
package drills.drill09.average
|
||||
|
||||
import util.network.epidemic.EpidemicPacket
|
||||
import util.network.epidemic.replay.ReplayPacket
|
@ -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<T>(
|
||||
Thread.sleep(100)
|
||||
}
|
||||
|
||||
override fun makeInfectionPrototypePacket(type: EpidemicPacket.Type): EpidemicPacketPrototype<TimePayload<T>> {
|
||||
return EpidemicPacketPrototype(
|
||||
override fun makeInfectionPacket(
|
||||
receiverAddress: Address,
|
||||
type: EpidemicPacket.Type
|
||||
): EpidemicPacket<TimePayload<T>> {
|
||||
return EpidemicPacket(
|
||||
address,
|
||||
receiverAddress,
|
||||
nodeValue,
|
||||
type
|
||||
)
|
@ -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
|
||||
|
@ -21,7 +21,7 @@ abstract class EpidemicNode<T, P: EpidemicPacket<T>>(
|
||||
}
|
||||
|
||||
private fun sendToRandom(
|
||||
packetPrototype: EpidemicPacketPrototype<T>,
|
||||
type: EpidemicPacket.Type,
|
||||
numberOfReceiver: Int = 1
|
||||
) {
|
||||
val toExclude = mutableListOf(address)
|
||||
@ -31,31 +31,32 @@ abstract class EpidemicNode<T, P: EpidemicPacket<T>>(
|
||||
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<T>
|
||||
): EpidemicPacket<T>
|
||||
|
||||
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
|
||||
)
|
||||
}
|
||||
|
@ -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<T>(
|
||||
override val senderAddress: Address,
|
||||
@ -12,48 +10,9 @@ open class EpidemicPacket<T>(
|
||||
val type: Type
|
||||
) : PayloadPacket<T> {
|
||||
|
||||
fun clone(
|
||||
senderAddress: Address = this.senderAddress,
|
||||
receiverAddress: Address = this.receiverAddress,
|
||||
payload: T = this.payload,
|
||||
type: Type = this.type
|
||||
): EpidemicPacket<T> =
|
||||
EpidemicPacket(senderAddress, receiverAddress, payload, type)
|
||||
|
||||
enum class Type {
|
||||
PUSH, PULL, PUSHPULL, REPLY
|
||||
}
|
||||
|
||||
companion object {
|
||||
fun <T> createFromNetworkPacket(
|
||||
packet: Packet,
|
||||
payload: TimePayload<T>,
|
||||
type: Type
|
||||
): EpidemicPacket<TimePayload<T>> = EpidemicPacket(
|
||||
packet.senderAddress,
|
||||
packet.receiverAddress,
|
||||
payload,
|
||||
type
|
||||
)
|
||||
|
||||
fun <T> createFromPayloadPacket(
|
||||
packet: PayloadPacket<TimePayload<T>>,
|
||||
type: Type
|
||||
): EpidemicPacket<TimePayload<T>> = EpidemicPacket(
|
||||
packet.senderAddress,
|
||||
packet.receiverAddress,
|
||||
packet.payload,
|
||||
type
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
open class EpidemicPacketPrototype<T>(
|
||||
override val senderAddress: Address,
|
||||
override val payload: T,
|
||||
val type: EpidemicPacket.Type
|
||||
) : PayloadPacketPrototype<T> {
|
||||
open fun makePacket(receiverAddress: Address): EpidemicPacket<T> {
|
||||
return EpidemicPacket(senderAddress, receiverAddress, payload, type)
|
||||
}
|
||||
}
|
||||
|
@ -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<T>(
|
||||
@ -12,19 +11,3 @@ class ReplayPacket<T>(
|
||||
val isReplay: Boolean
|
||||
) : EpidemicPacket<T>(senderAddress, receiverAddress, payload, type)
|
||||
|
||||
class ReplayPacketPrototype<T> (
|
||||
senderAddress: Address,
|
||||
payload: T,
|
||||
type: EpidemicPacket.Type,
|
||||
val isReplay: Boolean
|
||||
) : EpidemicPacketPrototype<T>(senderAddress, payload, type) {
|
||||
override fun makePacket(receiverAddress: Address): EpidemicPacket<T> {
|
||||
return ReplayPacket(
|
||||
senderAddress,
|
||||
receiverAddress,
|
||||
payload,
|
||||
type,
|
||||
isReplay
|
||||
)
|
||||
}
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,3 @@ interface Packet {
|
||||
val senderAddress: Address
|
||||
val receiverAddress: Address
|
||||
}
|
||||
|
||||
interface PacketPrototype {
|
||||
val senderAddress: Address
|
||||
}
|
||||
|
@ -3,7 +3,3 @@ package util.network.simulator.packet
|
||||
interface PayloadPacket<T>: Packet {
|
||||
val payload: T
|
||||
}
|
||||
|
||||
interface PayloadPacketPrototype<T> : PacketPrototype {
|
||||
val payload: T
|
||||
}
|
Loading…
Reference in New Issue
Block a user