Study · Kotlin + Java · exact package 2.3.2

Kotlin-first; Java on the same JVM connector

Kotlin uses explicit named arguments; Java uses lambdas, getters and explicit overloads. Both use the same managed JAR, target-native classifier and CoAkka HTTP Runtime contract.

Beginner · 01 / 04

Install directly from Maven Central

Use JDK 17 to build and run this Study. The JAR ships Java 8 bytecode, but that is not a reason to use an old JDK for the lesson. Choose the build tool you already use; no GitHub clone or manual JAR download is required.

Official channel · Maven Central

Maven or Gradle resolves both the managed JAR and the native ZIP classifier at exact 2.3.2 from the same registry.

io.github.phuong-tran.coakka:coakka-http-runtime-jvm:2.3.2

MavenUse pom.xml for a Maven project or an IDE Maven import.

Check JDK 17 and Maven 3.9+, then copy the POM into your project.

Terminal · environment check
java --version
mvn --version
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>example.coakka</groupId>
  <artifactId>coakka-http-jvm-study</artifactId>
  <version>1.0.0</version>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.release>8</maven.compiler.release>
    <kotlin.version>2.3.10</kotlin.version>
    <coakka.version>2.3.2</coakka.version>
    <coakka.target>macos-aarch64</coakka.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>io.github.phuong-tran.coakka</groupId>
      <artifactId>coakka-http-runtime-jvm</artifactId>
      <version>${coakka.version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-maven-plugin</artifactId>
        <version>${kotlin.version}</version>
        <executions>
          <execution>
            <id>compile-kotlin</id>
            <phase>process-sources</phase>
            <goals><goal>compile</goal></goals>
            <configuration>
              <jvmTarget>1.8</jvmTarget>
              <args><arg>-Werror</arg><arg>-Xjdk-release=8</arg></args>
              <sourceDirs>
                <sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
              </sourceDirs>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.14.1</version>
        <configuration>
          <release>8</release>
          <showWarnings>true</showWarnings>
          <compilerArgs><arg>-Xlint:all</arg><arg>-Werror</arg></compilerArgs>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.8.1</version>
        <executions>
          <execution>
            <id>unpack-coakka-native</id>
            <phase>process-resources</phase>
            <goals><goal>unpack</goal></goals>
            <configuration>
              <artifactItems>
                <artifactItem>
                  <groupId>io.github.phuong-tran.coakka</groupId>
                  <artifactId>coakka-http-runtime-jvm</artifactId>
                  <version>${coakka.version}</version>
                  <classifier>${coakka.target}</classifier>
                  <type>zip</type>
                  <outputDirectory>${project.build.directory}/coakka-native</outputDirectory>
                </artifactItem>
              </artifactItems>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
Gradle Kotlin DSLUse build.gradle.kts; create the Wrapper once, then run through it.

Check JDK 17 and Gradle, create the 9.2.1 Wrapper, then use ./gradlew or gradlew.bat.

Terminal · create the Gradle Wrapper
java --version
gradle --version
gradle wrapper --gradle-version 9.2.1
build.gradle.kts
plugins {
    kotlin("jvm") version "2.3.10"
    application
}

repositories {
    mavenCentral()
}

val coakkaTarget = providers.gradleProperty("coakkaTarget")
    .orElse("macos-aarch64")
val coakkaNative by configurations.creating

dependencies {
    implementation("io.github.phuong-tran.coakka:coakka-http-runtime-jvm:2.3.2")
    coakkaNative("io.github.phuong-tran.coakka:coakka-http-runtime-jvm:2.3.2:${coakkaTarget.get()}@zip")
}

val unpackCoakkaNative by tasks.registering(Sync::class) {
    from(coakkaNative.map(::zipTree))
    into(layout.buildDirectory.dir("coakka-native"))
}

kotlin {
    jvmToolchain(17)
    compilerOptions {
        jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8)
        freeCompilerArgs.add("-Xjdk-release=8")
        allWarningsAsErrors.set(true)
    }
}

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.withType<JavaCompile>().configureEach {
    options.release.set(8)
    options.compilerArgs.addAll(listOf("-Xlint:all", "-Werror"))
}

application {
    mainClass.set("study.KotlinMainKt")
}

tasks.withType<JavaExec>().configureEach {
    dependsOn(unpackCoakkaNative)
    standardInput = System.`in`
    jvmArgs("-Djava.library.path=" +
        layout.buildDirectory.dir("coakka-native/native").get().asFile.absolutePath)
}

tasks.register<JavaExec>("runJava") {
    group = "application"
    classpath = sourceSets.main.get().runtimeClasspath
    mainClass.set("study.JavaMain")
}

tasks.register<JavaExec>("runKotlinAdvanced") {
    group = "application"
    classpath = sourceSets.main.get().runtimeClasspath
    mainClass.set("study.KotlinAdvancedKt")
}

tasks.register<JavaExec>("runJavaAdvanced") {
    group = "application"
    classpath = sourceSets.main.get().runtimeClasspath
    mainClass.set("study.JavaAdvanced")
}

tasks.register<JavaExec>("runKotlinFile") {
    group = "application"
    classpath = sourceSets.main.get().runtimeClasspath
    mainClass.set("study.KotlinFileKt")
}

tasks.register<JavaExec>("runKotlinSse") {
    group = "application"
    classpath = sourceSets.main.get().runtimeClasspath
    mainClass.set("study.KotlinSseKt")
}

tasks.register<JavaExec>("runKotlinWebSocket") {
    group = "application"
    classpath = sourceSets.main.get().runtimeClasspath
    mainClass.set("study.KotlinWebSocketKt")
}

tasks.register<JavaExec>("runJavaFile") {
    group = "application"
    classpath = sourceSets.main.get().runtimeClasspath
    mainClass.set("study.JavaFile")
}

tasks.register<JavaExec>("runJavaSse") {
    group = "application"
    classpath = sourceSets.main.get().runtimeClasspath
    mainClass.set("study.JavaSse")
}

tasks.register<JavaExec>("runJavaWebSocket") {
    group = "application"
    classpath = sourceSets.main.get().runtimeClasspath
    mainClass.set("study.JavaWebSocket")
}

tasks.register<JavaExec>("runKotlinOutbound") {
    group = "application"
    classpath = sourceSets.main.get().runtimeClasspath
    mainClass.set("study.KotlinOutboundKt")
}

tasks.register<JavaExec>("runJavaOutbound") {
    group = "application"
    classpath = sourceSets.main.get().runtimeClasspath
    mainClass.set("study.JavaOutbound")
}
Choose the native classifierOpen only when you need to change the default OS/CPU target.
macOS Apple Silicon
macos-aarch64
Linux ARM64 / Raspberry Pi
linux-aarch64
Linux x86-64 / WSL2 x86-64
linux-x86_64
Windows ARM64
windows-aarch64
Windows x86-64
windows-x86_64
java.library.path
Points at the extracted native/ directory, not the ZIP or its parent.
Kotlin stdlib
The transitive dependency is pinned to 2.3.10; a Java-only app still keeps it because the connector is written in Kotlin.
There is no current ConnectorOrchestrator.

This Study uses the public 2.3.2 ServiceBuilder/Service API. The historical orchestration name is not the current surface.

Beginner · 02 / 04

Run the first Kotlin service

Save this file as src/main/kotlin/study/KotlinMain.kt:

KotlinMain.kt
package study

import coakka.http.Handler
import coakka.http.Responses
import coakka.http.ServiceBuilder

fun main() {
    val service = ServiceBuilder()
        .listen("127.0.0.1", 0)
        .get("/hello/{name}", Handler { request ->
            val name = request.pathParameters.first().encodedValue()
                .toString(Charsets.UTF_8)
            Responses.text("hello $name", status = 200)
        })
        .start()

    service.use {
        println("http://127.0.0.1:${it.port}/hello/Ada")
        println("Press Enter to close")
        readlnOrNull()
    }
}
Run with MavenBuild, resolve the classpath and run Kotlin main on POSIX.
Terminal
mvn -Dcoakka.target=macos-aarch64 clean package \
  dependency:build-classpath -Dmdep.outputFile=target/classpath.txt
java -Djava.library.path=target/coakka-native/native \
  -cp "target/classes:$(cat target/classpath.txt)" study.KotlinMainKt
Run with GradleUse the Wrapper created in episode 01.
Terminal
./gradlew run -PcoakkaTarget=macos-aarch64

Use the URL printed by the program: curl -i http://127.0.0.1:49321/hello/Ada → 200 hello Ada, then press Enter to close.

Beginner · 03 / 04

Read the request and use named arguments deliberately

val name = request.pathParameters.first().encodedValue()
    .toString(Charsets.UTF_8)
Responses.text("hello $name", status = 200)
pathParameters
Preserves route order; encodedValue() remains encoded, so the app chooses decode and validation.
status = 200
The named argument makes intent explicit; prefer it in Kotlin when metadata exposes a name.
request.bytes()
A buffered body within its configured bound; large uploads use postStream.
Headers
Names have case-insensitive lookup; ordered and duplicate entries remain available.

JNI adapter calls copy request values; no borrowed native pointer escapes into the JVM. JSON/domain codecs remain application choices.

Path, query, headers, body and trailers

Beginner · 04 / 04

Java uses the same artifact and requires no Kotlin source

Save the file as src/main/java/study/JavaMain.java:

JavaMain.java
package study;

import coakka.http.Responses;
import coakka.http.Service;
import coakka.http.ServiceBuilder;
import java.nio.charset.StandardCharsets;

public final class JavaMain {
    private JavaMain() {}

    public static void main(String[] args) throws Exception {
        Service service = new ServiceBuilder()
                .listen("127.0.0.1", 0)
                .get("/hello/{name}", request -> Responses.text(
                        "hello " + new String(
                                request.getPathParameters().get(0).encodedValue(),
                                StandardCharsets.UTF_8),
                        200))
                .start();
        try {
            System.out.printf("http://127.0.0.1:%d/hello/Ada%n", service.getPort());
            System.out.println("Press Enter to close");
            System.in.read();
        } finally {
            service.close();
        }
    }
}
Run with MavenUse the same POM and selected native classifier.
Terminal
mvn -Dcoakka.target=macos-aarch64 clean package \
  dependency:build-classpath -Dmdep.outputFile=target/classpath.txt
java -Djava.library.path=target/coakka-native/native \
  -cp "target/classes:$(cat target/classpath.txt)" study.JavaMain
Run with GradleUse the runJava task from the copied build.
Terminal
./gradlew runJava -PcoakkaTarget=macos-aarch64

Java uses the explicit Responses.text(body, status) overload, getters and a lambda. finally keeps close failure observable and prevents dropping the service owner.

Advanced · 05

Learn one capability at a time, then combine them

Start with a service that does one job. Choose Kotlin or Java inside each topic; both use the same Maven Central 2.3.2 artifact and native classifier installed in episode 1.

01 · File deliveryAuthority, relative path and limits; CoAkka HTTP Runtime selects sendfile when eligible.
KotlinNamed parameters expose each limit.
KotlinFile.kt
package study

import coakka.http.FileAuthority
import coakka.http.Handler
import coakka.http.Responses
import coakka.http.ServiceBuilder
import java.nio.file.Files

fun main() {
    val root = Files.createTempDirectory("coakka-http-file-")
    val manual = root.resolve("manual.txt")
    Files.write(manual, "CoAkka file delivery\n".toByteArray())

    val service = ServiceBuilder()
        .listen(host = "127.0.0.1", port = 0)
        .fileAuthority(
            FileAuthority(
                id = 1,
                rootPath = root.toString(),
                maxActiveFiles = 4,
                maxFileBytes = 1_024,
            ),
        )
        .get("/download", Handler {
            Responses.file(authorityId = 1, encodedPath = "/manual.txt")
        })
        .start()

    try {
        println("curl http://127.0.0.1:${service.port}/download")
        println("Press Enter to close")
        readlnOrNull()
    } finally {
        service.close()
        Files.deleteIfExists(manual)
        Files.deleteIfExists(root)
    }
}
Gradle
./gradlew runKotlinFile -PcoakkaTarget=macos-aarch64
Maven
java -Djava.library.path=target/coakka-native/native \
  -cp "target/classes:$(cat target/classpath.txt)" study.KotlinFileKt
JavaThe same file-response contract through Java.
JavaFile.java
package study;

import coakka.http.FileAuthority;
import coakka.http.Responses;
import coakka.http.Service;
import coakka.http.ServiceBuilder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

public final class JavaFile {
    private JavaFile() {}

    public static void main(String[] args) throws Exception {
        Path root = Files.createTempDirectory("coakka-http-file-");
        Path manual = root.resolve("manual.txt");
        Files.write(manual, "CoAkka file delivery\n".getBytes(StandardCharsets.UTF_8));

        Service service = new ServiceBuilder()
                .listen("127.0.0.1", 0)
                .fileAuthority(new FileAuthority(1L, root.toString(), 4, 1024))
                .get("/download", request -> Responses.file(1L, "/manual.txt"))
                .start();

        try {
            System.out.printf("curl http://127.0.0.1:%d/download%n", service.getPort());
            System.out.println("Press Enter to close");
            System.in.read();
        } finally {
            service.close();
            Files.deleteIfExists(manual);
            Files.deleteIfExists(root);
        }
    }
}
Gradle
./gradlew runJavaFile -PcoakkaTarget=macos-aarch64
Maven
java -Djava.library.path=target/coakka-native/native \
  -cp "target/classes:$(cat target/classpath.txt)" study.JavaFile
02 · Server-Sent EventsOne one-way response stream with data, event, id and retry.
KotlinEmit two events, then finish the stream.
KotlinSse.kt
package study

import coakka.http.Handler
import coakka.http.Responses
import coakka.http.ServerSentEvent
import coakka.http.ServerSentEventsProducer
import coakka.http.ServiceBuilder

fun main() {
    val events = Responses.serverSentEvents(
        producer = ServerSentEventsProducer { writer ->
            writer.write(
                ServerSentEvent(
                    data = "ready".toByteArray(),
                    eventType = "state",
                    id = "1",
                    retryMillis = 1_000,
                ),
            )
            writer.write(ServerSentEvent(data = "done".toByteArray()))
        },
    )
    val service = ServiceBuilder()
        .listen(host = "127.0.0.1", port = 0)
        .get("/events", Handler { events })
        .start()

    try {
        println("curl -N http://127.0.0.1:${service.port}/events")
        println("Press Enter to close")
        readlnOrNull()
    } finally {
        service.close()
    }
}
Gradle
./gradlew runKotlinSse -PcoakkaTarget=macos-aarch64
Maven
java -Djava.library.path=target/coakka-native/native \
  -cp "target/classes:$(cat target/classpath.txt)" study.KotlinSseKt
JavaThe same event fields through Java constructors.
JavaSse.java
package study;

import coakka.http.Responses;
import coakka.http.ServerSentEvent;
import coakka.http.Service;
import coakka.http.ServiceBuilder;
import java.nio.charset.StandardCharsets;

public final class JavaSse {
    private JavaSse() {}

    public static void main(String[] args) throws Exception {
        Service service = new ServiceBuilder()
                .listen("127.0.0.1", 0)
                .get("/events", request -> Responses.serverSentEvents(writer -> {
                    writer.write(new ServerSentEvent(
                            "ready".getBytes(StandardCharsets.UTF_8), "state", "1", 1000L));
                    writer.write(new ServerSentEvent(
                            "done".getBytes(StandardCharsets.UTF_8)));
                }))
                .start();

        try {
            System.out.printf("curl -N http://127.0.0.1:%d/events%n", service.getPort());
            System.out.println("Press Enter to close");
            System.in.read();
        } finally {
            service.close();
        }
    }
}
Gradle
./gradlew runJavaSse -PcoakkaTarget=macos-aarch64
Maven
java -Djava.library.path=target/coakka-native/native \
  -cp "target/classes:$(cat target/classpath.txt)" study.JavaSse
03 · WebSocketUpgrade with a subprotocol, greeting and bidirectional text echo.
KotlinHandle OPEN and TEXT independently.
KotlinWebSocket.kt
package study

import coakka.http.Handler
import coakka.http.Responses
import coakka.http.ServiceBuilder
import coakka.http.ServiceWebSocketHandler
import coakka.http.WebSocketEventKind

fun main() {
    val socket = Responses.webSocket(
        handler = ServiceWebSocketHandler { session, event ->
            when (event.kind) {
                WebSocketEventKind.OPEN -> session.sendText("ready")
                WebSocketEventKind.TEXT -> {
                    val message = event.bytes().toString(Charsets.UTF_8)
                    session.sendText("echo: $message")
                }
                else -> Unit
            }
        },
        subprotocol = "coakka.demo",
    )
    val service = ServiceBuilder()
        .listen(host = "127.0.0.1", port = 0)
        .webSocket("/socket", Handler { socket })
        .start()

    try {
        println(
            "new WebSocket('ws://127.0.0.1:${service.port}/socket', 'coakka.demo')",
        )
        println("Press Enter to close")
        readlnOrNull()
    } finally {
        service.close()
    }
}
Gradle
./gradlew runKotlinWebSocket -PcoakkaTarget=macos-aarch64
Maven
java -Djava.library.path=target/coakka-native/native \
  -cp "target/classes:$(cat target/classpath.txt)" study.KotlinWebSocketKt
JavaThe same session lifecycle through Java.
JavaWebSocket.java
package study;

import coakka.http.Responses;
import coakka.http.Service;
import coakka.http.ServiceBuilder;
import coakka.http.WebSocketEventKind;
import java.nio.charset.StandardCharsets;

public final class JavaWebSocket {
    private JavaWebSocket() {}

    public static void main(String[] args) throws Exception {
        Service service = new ServiceBuilder()
                .listen("127.0.0.1", 0)
                .webSocket("/socket", request -> Responses.webSocket((session, event) -> {
                    if (event.getKind() == WebSocketEventKind.OPEN) {
                        session.sendText("ready");
                    } else if (event.getKind() == WebSocketEventKind.TEXT) {
                        String message = new String(event.bytes(), StandardCharsets.UTF_8);
                        session.sendText("echo: " + message);
                    }
                }, "coakka.demo"))
                .start();

        try {
            System.out.printf(
                    "new WebSocket('ws://127.0.0.1:%d/socket', 'coakka.demo')%n",
                    service.getPort());
            System.out.println("Press Enter to close");
            System.in.read();
        } finally {
            service.close();
        }
    }
}
Gradle
./gradlew runJavaWebSocket -PcoakkaTarget=macos-aarch64
Maven
java -Djava.library.path=target/coakka-native/native \
  -cp "target/classes:$(cat target/classpath.txt)" study.JavaWebSocket
04 · Combine them in one serviceAn optional integration exercise after the three contracts are clear.
KotlinThree endpoints, one service owner.
KotlinAdvanced.kt
package study

import coakka.http.FileAuthority
import coakka.http.Handler
import coakka.http.Responses
import coakka.http.ServerSentEvent
import coakka.http.ServerSentEventsProducer
import coakka.http.ServiceBuilder
import coakka.http.ServiceWebSocketHandler
import coakka.http.WebSocketEventKind
import java.nio.file.Files

private const val fileAuthorityId = 1L

fun main() {
    val root = Files.createTempDirectory("coakka-http-advanced-")
    val manual = root.resolve("manual.txt")
    Files.write(manual, "CoAkka file delivery\n".toByteArray())

    val events = Responses.serverSentEvents(
        producer = ServerSentEventsProducer { writer ->
            writer.write(
                ServerSentEvent(
                    data = "ready".toByteArray(),
                    eventType = "state",
                    id = "1",
                    retryMillis = 1_000,
                ),
            )
            writer.write(ServerSentEvent(data = "done".toByteArray()))
        },
    )
    val socket = Responses.webSocket(
        handler = ServiceWebSocketHandler { session, event ->
            when (event.kind) {
                WebSocketEventKind.OPEN -> session.sendText("ready")
                WebSocketEventKind.TEXT -> {
                    val message = event.bytes().toString(Charsets.UTF_8)
                    session.sendText("echo: $message")
                }
                else -> Unit
            }
        },
        subprotocol = "coakka.demo",
    )

    val service = ServiceBuilder()
        .listen(host = "127.0.0.1", port = 0)
        .fileAuthority(
            FileAuthority(
                id = fileAuthorityId,
                rootPath = root.toString(),
                maxActiveFiles = 4,
                maxFileBytes = 1_024,
            ),
        )
        .get("/download", Handler {
            Responses.file(
                authorityId = fileAuthorityId,
                encodedPath = "/manual.txt",
            )
        })
        .get("/events", Handler { events })
        .webSocket("/socket", Handler { socket })
        .start()

    try {
        println("file: curl http://127.0.0.1:${service.port}/download")
        println("SSE:  curl -N http://127.0.0.1:${service.port}/events")
        println(
            "WS:   new WebSocket('ws://127.0.0.1:${service.port}/socket', 'coakka.demo')",
        )
        println("Press Enter to close")
        readlnOrNull()
    } finally {
        service.close()
        Files.deleteIfExists(manual)
        Files.deleteIfExists(root)
    }
}
Gradle
./gradlew runKotlinAdvanced -PcoakkaTarget=macos-aarch64
Maven
java -Djava.library.path=target/coakka-native/native \
  -cp "target/classes:$(cat target/classpath.txt)" study.KotlinAdvancedKt
JavaThree endpoints through the Java API.
JavaAdvanced.java
package study;

import coakka.http.FileAuthority;
import coakka.http.Responses;
import coakka.http.ServerSentEvent;
import coakka.http.Service;
import coakka.http.ServiceBuilder;
import coakka.http.WebSocketEventKind;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

public final class JavaAdvanced {
    private static final long FILE_AUTHORITY_ID = 1L;

    private JavaAdvanced() {}

    public static void main(String[] args) throws Exception {
        Path root = Files.createTempDirectory("coakka-http-advanced-");
        Path manual = root.resolve("manual.txt");
        Files.write(manual, "CoAkka file delivery\n".getBytes(StandardCharsets.UTF_8));

        Service service = new ServiceBuilder()
                .listen("127.0.0.1", 0)
                .fileAuthority(new FileAuthority(FILE_AUTHORITY_ID, root.toString(), 4, 1024))
                .get("/download", request ->
                        Responses.file(FILE_AUTHORITY_ID, "/manual.txt"))
                .get("/events", request -> Responses.serverSentEvents(writer -> {
                    writer.write(new ServerSentEvent(
                            "ready".getBytes(StandardCharsets.UTF_8), "state", "1", 1000L));
                    writer.write(new ServerSentEvent(
                            "done".getBytes(StandardCharsets.UTF_8)));
                }))
                .webSocket("/socket", request -> Responses.webSocket((session, event) -> {
                    if (event.getKind() == WebSocketEventKind.OPEN) {
                        session.sendText("ready");
                    } else if (event.getKind() == WebSocketEventKind.TEXT) {
                        String message = new String(event.bytes(), StandardCharsets.UTF_8);
                        session.sendText("echo: " + message);
                    }
                }, "coakka.demo"))
                .start();

        try {
            System.out.printf("file: curl http://127.0.0.1:%d/download%n", service.getPort());
            System.out.printf("SSE:  curl -N http://127.0.0.1:%d/events%n", service.getPort());
            System.out.printf(
                    "WS:   new WebSocket('ws://127.0.0.1:%d/socket', 'coakka.demo')%n",
                    service.getPort());
            System.out.println("Press Enter to close");
            System.in.read();
        } finally {
            service.close();
            Files.deleteIfExists(manual);
            Files.deleteIfExists(root);
        }
    }
}
Gradle
./gradlew runJavaAdvanced -PcoakkaTarget=macos-aarch64
Maven
java -Djava.library.path=target/coakka-native/native \
  -cp "target/classes:$(cat target/classpath.txt)" study.JavaAdvanced

Look up parameters, failures and monitoring.

Find all feature guides · Try gzip · Run the upload labs · Resume a large upload

Advanced · 06

Outbound and live control preserve typed truth

TaskJVM APIInvariant
OutboundsubmitOutbound, takeOutboundMatch call identity; reason/phase/retry/certainty differ from HTTP status.
Route snapshotservice.routes / getRoutes()A Core-issued coherent cut, not local declarations.
RebindprepareHandler, rebindHandlerExpected generation/revision; admitted requests retain the old handler.
PublishStructural route publicationA complete generation, never piecemeal local patches.

Outbound terminal · Live control

Run a language lab · Outbound HTTP →

Advanced · 07

Effective state, Monitor and the framework boundary

runtimeInfo()
Core-accepted protocol, provider and capability facts.
effectiveLimits()
Resolved limits, not builder-input echo.
Health/liveness
Direct health and a bounded fresh probe without enabling Monitor.
Monitor
Reserve before start; generation-checked policy, bounded events/snapshots and loss facts.
Spring Boot/Quarkus
The framework owns DI/config/app lifecycle; its adapter creates and closes exactly one Service without changing the Core contract.

Health, liveness and Monitor · Finite close

Advanced · 08

Failure, close and JVM quick reference

Startup
ServiceBuilder is single-use; unsupported providers and invalid config fail with typed facts, never partial ready.
Handler/stream
Asynchronous failures enter the bounded service error queue; consume pollError().
Low-level
HttpRuntimeException plus typed ResultCode; never parse message text.
Close
Service is AutoCloseable; timeout/interruption remains observable, and a live owner must be retained for retry.
Evidence
JAR/native ZIP hashes, loaded paths, JVM OS/arch, runtime info/limits, workload and terminal/loss facts.
  • Keep the JAR and native classifier at 2.3.2.
  • Match the classifier to the JVM process, not only the host OS.
  • Prefer Kotlin named args; Java uses public overloads, never synthetic defaults.
  • Keep one reader per low-level lane.
  • Never drop a service whose close has not completed.