Reference theo việc cần làm · JVM 3.3.2

Cấu hình CoAkka Runtime · Java + Kotlin/JVM

Mở đúng nhóm cho công việc đang thực hiện. Các ví dụ dùng named arguments để intent không bị ẩn trong vị trí tham số; effective state phải đọc lại từ Core, không dựng lại từ input Kotlin.

Build và dependencyMaven hoặc Gradle, không cần cả hai
Build JDK
JDK 17 cho bài học. Java 8 là consumer floor của connector, tách biệt với JDK dùng để chạy build tool.
Maven
Maven 3.9+; Java và Kotlin dùng cùng coordinate io.github.phuong-tran.coakka:runtime:3.3.2.
Gradle
Java dùng application plugin; Kotlin dùng Kotlin JVM plugin 2.3.10. Cả hai dùng toolchain 17.
Native Core
JAR mang theo đúng Core/JNI pair cho platform được đóng gói và verify integrity khi load. Không đặt manual library path cho quick path.

Copy trọn pom.xml hoặc build.gradle.kts.

Chọn API ownerCoAkka.local · ConnectorOrchestrator
CoAkka.local(...)
Level 1 được ưu tiên cho học tập, same-process handlers và plain-text request/reply.
LocalRuntime
Giữ local targets, route generation và shutdown của owner bên dưới. Không tạo theo từng request.
ConnectorOrchestrator
Tên public Level 2 trong đúng JAR JVM 3.3.2, dùng cho explicit routes, network, typed outcomes, Monitor và effective state.
Không dịch API theo ngôn ngữ khác
Go/Node/Bun dùng tên RuntimeHost, nhưng JVM 3.3.2 chưa xuất type đó. Không tự tạo alias trong sample và không dựa vào sample Git bị drift.
Startup intentRuntimeStartSpec
systemName
Tên logical system/app-host.
nodeId
Identity duy nhất của runtime owner trong system.
routes
Snapshot route generation đầu tiên; local-first có thể dùng RuntimeClient.localRoutes(targets = ...).
queueCapacity = 0
Không ép connector default; yêu cầu Core chọn và báo production default.
strictNoDrop = true
Giữ strict no-drop ở nơi Core hỗ trợ. Overload policy vẫn là contract riêng.
generation
Generation ban đầu của control snapshot. Update cũ phải bị từ chối.
execution, io
Bỏ cả group nếu muốn Core defaults và capability probe. Không mirror default trong JVM.
monitor = RuntimeMonitorOptions(enabled = true)
Cho phép collection trước startup; việc đọc doorbell không tự bật Monitor.
Network, route và endpointRuntimeNetworkConfig · RuntimeRouteSpec
network = null
Để Core chọn default Embedded. Explicit embedded() phù hợp khi bài đang dạy policy presence.
outboundOnly()
Cho process gọi peer mà không sở hữu inbound listener.
networkNode(bindHost = …, bindPort = …, advertiseHost = …, advertisePort = …)
Bind và advertise là hai facts khác nhau; loopback không dùng cho peer ở máy khác.
target
Địa chỉ capability nghiệp vụ, giữ nguyên khi handler chuyển process.
endpoints
Các owner candidate có host, port, weight và endpoint flags.
SINGLE_OWNER
Đúng một owner; WEIGHTED_ROUND_ROBIN phân phối theo weight; RENDEZVOUS_HASH chọn ổn định theo route key.
weight
Trọng số route selection, không phải retry count hay priority.
LOCAL / UNAVAILABLE
Flags do runtime contract định nghĩa; dùng exported values, không tự gán số.

Tra routing và checklist chung · Tra failover/retry

Kết nối và bảo mậtRuntimeTcpConnectionStrategySpec · RuntimeTcpSecuritySpec
connectionStrategy = null
Giữ Core default MULTIPLEXING. Đừng gửi một object zero chỉ để “dùng default”; zero mode là explicit PER_EXCHANGE intent.
mode
PER_EXCHANGE, BOUNDED_POOL, PERSISTENT_SINGLE_FLIGHT hoặc MULTIPLEXING; đọc capability trước khi chọn mode tùy chọn.
maxConnections
Bound connection khi mode/capability cho phép.
maxRequestsPerConnection
Bound request trước khi Core retire connection.
idleTimeoutMs
Bound thời gian giữ connection rảnh.
security.mode
PLAINTEXT, TLS hoặc MUTUAL_TLS theo trust boundary.
credentialGeneration
Generation khác 0 và tăng dần cho credential set mới.
credentialId
ID chẩn đoán không bí mật; không chứa token/key.
caCertificateFile
PEM CA dùng verify peer.
identityCertificateFile / privateKeyFile
Identity chain và private key của instance; không log nội dung hoặc path nhạy cảm.

Tra connection strategies · Tra TLS/mTLS

File Lane và Stream LaneOwner độc lập với runtime message owner
FileLane.openOwned
Receiver cấp grant gắn đúng owner instance, address, port và transfer.
FileLane.sha256(path = ...)
Tính size và digest trước khi prepare.
waitTransfer(..., afterUpdateSequence = ...)
Chờ state mới; terminal success cần state COMPLETED, result OK và terminal receipt.
StreamLane.openOwned
Publisher cấp grant cho một exact-owner session.
maxFrameBytes
Bound từng frame; tối đa public contract hiện tại là 4 MiB.
initialWindowBytes
Receive credit ban đầu, phải chứa ít nhất một max frame.
StreamSource
Ghi vào destination ByteBuffer chỉ trong callback; không giữ view.
StreamConsumer
Data ByteBuffer chỉ được borrow trong callback; copy trước khi retain.
close()
File/Stream Lane là owner độc lập và close đồng bộ sau khi operation đã terminal/cancel.

Tra lifecycle, pressure, security và outcomes chung.

Đọc Core accepted/effective statestartupConfig · runtimeConfig · networkConfig

Tạo Configuration.kt cạnh các file advanced, dán source và chạy bằng build tool đã chọn.

Configuration.kt
import coakka.v2.connector.ConnectorOrchestrator
import coakka.v2.connector.RuntimeClient
import coakka.v2.connector.RuntimeMonitorOptions
import coakka.v2.connector.RuntimeNetworkConfig
import coakka.v2.connector.RuntimeStartSpec
import kotlinx.coroutines.runBlocking

fun main() = runBlocking {
    val runtime = ConnectorOrchestrator.start(
        startSpec = RuntimeStartSpec(
            systemName = "config-lab",
            nodeId = "config-lab-1",
            queueCapacity = 64,
            strictNoDrop = true,
            routes = RuntimeClient.localRoutes(
                targets = listOf("config.echo"),
            ),
            network = RuntimeNetworkConfig.embedded(),
            monitor = RuntimeMonitorOptions(enabled = true),
        ),
    )

    try {
        val startup = runtime.startupConfig()
        val accepted = runtime.runtimeConfig()
        val network = runtime.networkConfig()
        println(
            "generation=${accepted.appliedGeneration} " +
                "queue_capacity=${accepted.queueCapacity} " +
                "strict_no_drop=${accepted.strictNoDrop} " +
                "monitor=${startup.monitorEnabled} " +
                "network_mode=${network.mode.value}",
        )
    } finally {
        runtime.kotlin.shutdown()
    }
}
Maven
mvn -q compile exec:java -Dexec.mainClass=ConfigurationKt
Gradle
gradle run -PmainClass=ConfigurationKt

Kết quả đã kiểm chứng

generation=1 queue_capacity=64 strict_no_drop=true monitor=true network_mode=1
startupConfig()
Defaults revision, defaulted groups, execution, connection, I/O và Monitor facts Core đã nhận.
runtimeConfig()
Runtime state, applied generation, routes, queue và effective overload facts.
networkConfig()
Mode, explicit-policy provenance và bind/advertise facts.
runtimeCapabilities()
Compiled, entitled và effective feature bits trước advanced transport.
health() / stats()
Copied observed state và counters.

Đối chiếu requested, accepted, effective và observed.