Verwendung und Grenzen

Ein Adapter erkennt den vollständigen ResourceKey eines Gegenstands und liefert die Komponentendefinition. Für andere Gegenstände gilt null. Der Anzeigename allein genügt nicht.

NebulaHardware

NebulaHardware
package dev.nebulastorage.api.hardware

import dev.nebulastorage.api.resource.ResourceKey
import dev.nebulastorage.api.resource.ResourceTypeId
import java.util.Collections

enum class HardwareKind { MOTHERBOARD, CPU, RAM, DRIVE, NIC, PSU, EXPANSION }

/** Power is FE/t at the initial 1 FE/W conversion. Memory is a logical plan budget, in bytes. */
class HardwareDefinition private constructor(
    val profile: HardwareProfile,
    val kind: HardwareKind, val idlePower: Long, val computePower: Long,
    val operationCost: Long, val memory: Long, val supplyPower: Long,
    capacities: Map<ResourceTypeId, Long>, slots: Map<HardwareKind, Int>
) {
    constructor(kind: HardwareKind, idlePower: Long = 0, computePower: Long = 0,
                operationCost: Long = 0, memory: Long = 0, supplyPower: Long = 0,
                capacities: Map<ResourceTypeId, Long> = emptyMap(), slots: Map<HardwareKind, Int> = emptyMap()) :
        this(HardwareProfile(), kind, idlePower, computePower, operationCost, memory, supplyPower, capacities, slots)

    constructor(kind: HardwareKind, profile: HardwareProfile, idlePower: Long = 0, computePower: Long = 0,
                operationCost: Long = 0, memory: Long = 0, supplyPower: Long = 0,
                capacities: Map<ResourceTypeId, Long> = emptyMap(), slots: Map<HardwareKind, Int> = emptyMap()) :
        this(profile, kind, idlePower, computePower, operationCost, memory, supplyPower, capacities, slots)

    val capacities: Map<ResourceTypeId, Long> = Collections.unmodifiableMap(capacities.toMap())
    val slots: Map<HardwareKind, Int> = Collections.unmodifiableMap(slots.toMap())

    init {
        require(listOf(idlePower, computePower, operationCost, supplyPower).all { it in 0..1_000_000_000L })
        require(memory in 0..(1L shl 50))
        require(capacities.values.all { it >= 0 } && slots.values.all { it in 0..64 })
        require(kind == HardwareKind.CPU || computePower == 0L && operationCost == 0L)
        require(kind != HardwareKind.CPU || computePower > 0 && operationCost > 0)
        require(kind == HardwareKind.RAM || memory == 0L)
        require(kind == HardwareKind.PSU || supplyPower == 0L)
        require(kind == HardwareKind.DRIVE || capacities.isEmpty())
        require(kind == HardwareKind.MOTHERBOARD || slots.isEmpty())
        require(HardwareKind.MOTHERBOARD !in slots)
        require(profile.io == null || kind == HardwareKind.DRIVE)
        require(profile.networkBandwidth == null || kind == HardwareKind.NIC)
    }
}

fun interface NebulaHardwareAdapter {
    /** Resolve the exact immutable item key, including components; null means unsupported. Called on the server thread. */
    fun describe(item: ResourceKey): HardwareDefinition?
}
Quelle

src/main/kotlin/dev/nebulastorage/api/hardware/NebulaHardware.kt; editorial/de.json

43b4d12d69e6033c24fa8c39dac383ef2429b446