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.EpidemicNode
|
||||||
import util.network.epidemic.EpidemicPacket
|
import util.network.epidemic.EpidemicPacket
|
||||||
import util.network.epidemic.EpidemicPacketPrototype
|
|
||||||
import util.network.epidemic.replay.ReplayPacket
|
import util.network.epidemic.replay.ReplayPacket
|
||||||
import util.network.epidemic.replay.ReplayPacketPrototype
|
|
||||||
import util.network.simulator.Address
|
import util.network.simulator.Address
|
||||||
import util.network.simulator.Network
|
import util.network.simulator.Network
|
||||||
|
|
||||||
@ -46,11 +44,13 @@ class AverageNode(
|
|||||||
Thread.interrupted()
|
Thread.interrupted()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun makeInfectionPrototypePacket(
|
override fun makeInfectionPacket(
|
||||||
|
receiverAddress: Address,
|
||||||
type: EpidemicPacket.Type
|
type: EpidemicPacket.Type
|
||||||
): EpidemicPacketPrototype<Double> {
|
): EpidemicPacket<Double> {
|
||||||
return ReplayPacketPrototype(
|
return ReplayPacket(
|
||||||
address,
|
address,
|
||||||
|
receiverAddress,
|
||||||
nodeValue,
|
nodeValue,
|
||||||
type,
|
type,
|
||||||
false
|
false
|
@ -1,4 +1,4 @@
|
|||||||
package util.network.epidemic.consinstence
|
package drills.drill09.average
|
||||||
|
|
||||||
import util.network.epidemic.EpidemicPacket
|
import util.network.epidemic.EpidemicPacket
|
||||||
import util.network.epidemic.replay.ReplayPacket
|
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.TimePayload
|
||||||
import util.network.epidemic.EpidemicNode
|
import util.network.epidemic.EpidemicNode
|
||||||
import util.network.epidemic.EpidemicPacket
|
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.Address
|
||||||
import util.network.simulator.Network
|
import util.network.simulator.Network
|
||||||
|
|
||||||
@ -42,9 +40,13 @@ class DbNode<T>(
|
|||||||
Thread.sleep(100)
|
Thread.sleep(100)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun makeInfectionPrototypePacket(type: EpidemicPacket.Type): EpidemicPacketPrototype<TimePayload<T>> {
|
override fun makeInfectionPacket(
|
||||||
return EpidemicPacketPrototype(
|
receiverAddress: Address,
|
||||||
|
type: EpidemicPacket.Type
|
||||||
|
): EpidemicPacket<TimePayload<T>> {
|
||||||
|
return EpidemicPacket(
|
||||||
address,
|
address,
|
||||||
|
receiverAddress,
|
||||||
nodeValue,
|
nodeValue,
|
||||||
type
|
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.Address
|
||||||
import util.network.simulator.Network
|
import util.network.simulator.Network
|
||||||
|
|
@ -21,7 +21,7 @@ abstract class EpidemicNode<T, P: EpidemicPacket<T>>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun sendToRandom(
|
private fun sendToRandom(
|
||||||
packetPrototype: EpidemicPacketPrototype<T>,
|
type: EpidemicPacket.Type,
|
||||||
numberOfReceiver: Int = 1
|
numberOfReceiver: Int = 1
|
||||||
) {
|
) {
|
||||||
val toExclude = mutableListOf(address)
|
val toExclude = mutableListOf(address)
|
||||||
@ -31,31 +31,32 @@ abstract class EpidemicNode<T, P: EpidemicPacket<T>>(
|
|||||||
receiverAddress = network.getRandomAddress()
|
receiverAddress = network.getRandomAddress()
|
||||||
toExclude.add(receiverAddress)
|
toExclude.add(receiverAddress)
|
||||||
|
|
||||||
send(packetPrototype.makePacket(receiverAddress))
|
send(makeInfectionPacket(receiverAddress, type))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun makeInfectionPrototypePacket(
|
abstract fun makeInfectionPacket(
|
||||||
|
receiverAddress: Address,
|
||||||
type: EpidemicPacket.Type
|
type: EpidemicPacket.Type
|
||||||
): EpidemicPacketPrototype<T>
|
): EpidemicPacket<T>
|
||||||
|
|
||||||
protected fun sendPush(numberOfReceiver: Int = 1) {
|
protected fun sendPush(numberOfReceiver: Int = 1) {
|
||||||
sendToRandom(
|
sendToRandom(
|
||||||
makeInfectionPrototypePacket(EpidemicPacket.Type.PUSH),
|
EpidemicPacket.Type.PUSH,
|
||||||
numberOfReceiver
|
numberOfReceiver
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun sendPull(numberOfReceiver: Int = 1) {
|
protected fun sendPull(numberOfReceiver: Int = 1) {
|
||||||
sendToRandom(
|
sendToRandom(
|
||||||
makeInfectionPrototypePacket(EpidemicPacket.Type.PULL),
|
EpidemicPacket.Type.PULL,
|
||||||
numberOfReceiver
|
numberOfReceiver
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun sendPushPull(numberOfReceiver: Int = 1) {
|
protected fun sendPushPull(numberOfReceiver: Int = 1) {
|
||||||
sendToRandom(
|
sendToRandom(
|
||||||
makeInfectionPrototypePacket(EpidemicPacket.Type.PUSHPULL),
|
EpidemicPacket.Type.PUSHPULL,
|
||||||
numberOfReceiver
|
numberOfReceiver
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package util.network.epidemic
|
package util.network.epidemic
|
||||||
|
|
||||||
import util.network.simulator.Address
|
import util.network.simulator.Address
|
||||||
import util.network.simulator.packet.Packet
|
|
||||||
import util.network.simulator.packet.PayloadPacket
|
import util.network.simulator.packet.PayloadPacket
|
||||||
import util.network.simulator.packet.PayloadPacketPrototype
|
|
||||||
|
|
||||||
open class EpidemicPacket<T>(
|
open class EpidemicPacket<T>(
|
||||||
override val senderAddress: Address,
|
override val senderAddress: Address,
|
||||||
@ -12,48 +10,9 @@ open class EpidemicPacket<T>(
|
|||||||
val type: Type
|
val type: Type
|
||||||
) : PayloadPacket<T> {
|
) : 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 {
|
enum class Type {
|
||||||
PUSH, PULL, PUSHPULL, REPLY
|
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
|
package util.network.epidemic.replay
|
||||||
|
|
||||||
import util.network.epidemic.EpidemicPacket
|
import util.network.epidemic.EpidemicPacket
|
||||||
import util.network.epidemic.EpidemicPacketPrototype
|
|
||||||
import util.network.simulator.Address
|
import util.network.simulator.Address
|
||||||
|
|
||||||
class ReplayPacket<T>(
|
class ReplayPacket<T>(
|
||||||
@ -12,19 +11,3 @@ class ReplayPacket<T>(
|
|||||||
val isReplay: Boolean
|
val isReplay: Boolean
|
||||||
) : EpidemicPacket<T>(senderAddress, receiverAddress, payload, type)
|
) : 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
|
override val receiverAddress: Address
|
||||||
) : Packet
|
) : 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 senderAddress: Address
|
||||||
val receiverAddress: Address
|
val receiverAddress: Address
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PacketPrototype {
|
|
||||||
val senderAddress: Address
|
|
||||||
}
|
|
||||||
|
@ -3,7 +3,3 @@ package util.network.simulator.packet
|
|||||||
interface PayloadPacket<T>: Packet {
|
interface PayloadPacket<T>: Packet {
|
||||||
val payload: T
|
val payload: T
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PayloadPacketPrototype<T> : PacketPrototype {
|
|
||||||
val payload: T
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user