Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/routing #647

Merged
merged 10 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ jobs:
- name: Build Project
run: ./gradlew --stacktrace nativeTest

jmh:
name: JMH Benchmark
uses: hexagonkt/.github/.github/workflows/graalvm_gradle.yml@master
with:
java: 20
ref: develop
tasks: jmh

build_site:
name: Build Site
uses: hexagonkt/hexagon/.github/workflows/site.yml@master
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ jobs:
java: 20
tasks: nativeTest

jmh:
name: JMH Benchmark
uses: hexagonkt/.github/.github/workflows/graalvm_gradle.yml@master
with:
java: 20
tasks: jmh

build_site:
name: Build Site
uses: hexagonkt/hexagon/.github/workflows/site.yml@develop
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ private val path: PathHandler = path {
get("/588") { send(HttpStatus(588)) }

// It is possible to execute a handler upon a given status code before returning
on(pattern = "*", status = HttpStatus(588)) {
before(pattern = "*", status = HttpStatus(588)) {
send(HttpStatus(578), "588 -> 578")
}
}
Expand Down
7 changes: 0 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,10 @@ apiValidation {

// Test modules
"http_test",
"http_test_async",
"serialization_test",
"templates_test",

// Experimental modules
"handlers_async",
"http_handlers_async",
"http_server_async",
"http_server_netty_async",
"http_server_netty_epoll_async",
"http_server_nima",
"rest",
"rest_tools",
"web",
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ org.gradle.warning.mode=all
org.gradle.console=plain

# Gradle
version=3.0.0-B10
version=3.0.0
group=com.hexagonkt
description=The atoms of your platform

Expand Down Expand Up @@ -36,10 +36,10 @@ dokkaVersion=1.8.20
mockkVersion=1.13.5
junitVersion=5.10.0
gatlingVersion=3.9.5
jmhVersion=1.36
jmhVersion=1.37
mkdocsMaterialVersion=9.1.21
mermaidDokkaVersion=0.4.4
nativeToolsVersion=0.9.23
nativeToolsVersion=0.9.24

# http_server_netty
nettyVersion=4.1.96.Final
Expand All @@ -58,7 +58,7 @@ swaggerParserVersion=2.1.16

# logging
slf4jVersion=2.0.7
logbackVersion=1.4.8
logbackVersion=1.4.11

# serialization
jacksonVersion=2.15.2
Expand Down
2 changes: 1 addition & 1 deletion gradle/jmh.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tasks.compileJmhKotlin.kotlinOptions.jvmTarget = tasks.compileKotlin.kotlinOptio
tasks.compileJmhKotlin.kotlinOptions.apiVersion = tasks.compileKotlin.kotlinOptions.apiVersion

jmh {
final String jhmVersion = findProperty("jhmVersion") ?: "1.36"
final String jhmVersion = findProperty("jhmVersion") ?: "1.37"

jmhVersion.set(jhmVersion)
benchmarkMode.set(["thrpt"])
Expand Down
4 changes: 2 additions & 2 deletions handlers/api/handlers.api
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ public abstract interface class com/hexagonkt/handlers/Context {
public abstract fun getNextHandlers ()Ljava/util/List;
public abstract fun getPredicate ()Lkotlin/jvm/functions/Function1;
public abstract fun next ()Lcom/hexagonkt/handlers/Context;
public abstract fun with (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Ljava/util/List;ILjava/lang/Exception;Ljava/util/Map;)Lcom/hexagonkt/handlers/Context;
public abstract fun with (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Ljava/util/List;ILjava/lang/Exception;Ljava/util/Map;Z)Lcom/hexagonkt/handlers/Context;
}

public final class com/hexagonkt/handlers/Context$DefaultImpls {
public static fun next (Lcom/hexagonkt/handlers/Context;)Lcom/hexagonkt/handlers/Context;
public static synthetic fun with$default (Lcom/hexagonkt/handlers/Context;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Ljava/util/List;ILjava/lang/Exception;Ljava/util/Map;ILjava/lang/Object;)Lcom/hexagonkt/handlers/Context;
public static synthetic fun with$default (Lcom/hexagonkt/handlers/Context;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;Ljava/util/List;ILjava/lang/Exception;Ljava/util/Map;ZILjava/lang/Object;)Lcom/hexagonkt/handlers/Context;
}

public final class com/hexagonkt/handlers/FilterHandler : com/hexagonkt/handlers/Handler {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.hexagonkt.handlers

import com.hexagonkt.handlers.*
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.State
Expand All @@ -26,6 +25,7 @@ open class JmhBenchmark {
nextHandler: Int,
exception: Exception?,
attributes: Map<*, *>,
handled: Boolean,
): EventContext<T> =
copy(
event = event,
Expand All @@ -34,6 +34,7 @@ open class JmhBenchmark {
nextHandler = nextHandler,
exception = exception,
attributes = attributes,
handled = handled,
)
}

Expand Down
12 changes: 9 additions & 3 deletions handlers/src/main/kotlin/com/hexagonkt/handlers/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface Context<T : Any> {
val exception: Exception?
val attributes: Map<*, *>
val handled: Boolean
// TODO Add 'handled' flag set on OnHandler and not in BeforeHandler

fun with(
event: T = this.event,
Expand All @@ -22,14 +21,21 @@ interface Context<T : Any> {
nextHandler: Int = this.nextHandler,
exception: Exception? = this.exception,
attributes: Map<*, *> = this.attributes,
handled: Boolean = this.handled,
): Context<T>

fun next(): Context<T> {
for (index in nextHandler until nextHandlers.size) {
val handler = nextHandlers[index]
val p = handler.predicate
if (p(this))
return handler.process(with(predicate = p, nextHandler = index + 1))
if (handler is OnHandler) {
if ((!handled) && p(this))
return handler.process(with(predicate = p, nextHandler = index + 1))
}
else {
if (p(this))
return handler.process(with(predicate = p, nextHandler = index + 1))
}
}

return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data class OnHandler<T : Any>(

override fun process(context: Context<T>): Context<T> =
try {
callback(context).next()
callback(context).with(handled = true).next()
}
catch (e: Exception) {
context.with(exception = e).next()
Expand Down
Loading