Various experimental proposals and extensions to Javalin 4.x used in Reposilite 3.x

Overview

Javalin RFCs CI

Various experimental extensions to Javalin 4.x used in Reposilite 3.x. Provides basic support for Kotlin coroutines and async routes with a set of useful utilities.

repositories {
    maven { url 'https://repo.panda-lang.org/releases' }
}

dependencies {
    val version = "1.0.8"
    implementation "com.reposilite.javalin-rfcs:javalin-context:$version"
    implementation "com.reposilite.javalin-rfcs:javalin-reactive-routing:$version"
}

Project also includes panda-lang :: expressible library as a dependency. It's mainly used to provide Result<VALUE, ERROR> type and associated utilities.

Reactive Routing

Experimental router plugin that supports generic route registration with custom context and multiple routes within the same endpoints.

// Custom context
class AppContext(val context: Context)

// Some dependencies
class ExampleFacade

// Endpoint (domain router)
class ExampleEndpoint(private val exampleFacade: ExampleFacade) : AbstractRoutes<AppContext, Unit>() {

    private val sync = route("/sync", GET, async = false) { blockingDelay("Sync") }

    private val blockingAsync = route("/async-blocking", GET) { blockingDelay("Blocking Async") }

    private val nonBlockingAsync = route("/async", GET) { nonBlockingDelay("Non-blocking Async") }

    override val routes = setOf(sync, blockingAsync, nonBlockingAsync)

}

private suspend fun nonBlockingDelay(message: String): String = delay(100L).let { message }
@Suppress("BlockingMethodInNonBlockingContext")
private suspend fun blockingDelay(message: String): String =  sleep(100L).let { message }

fun main() {
    val exampleFacade = ExampleFacade()
    val exampleEndpoint = ExampleEndpoint(exampleFacade)

    val sharedThreadPool = QueuedThreadPool(4)
    val dispatcher = DispatcherWithShutdown(sharedThreadPool.asCoroutineDispatcher())
    sharedThreadPool.start()

    Javalin
        .create { config ->
            config.server { Server(sharedThreadPool) }

            ReactiveRoutingPlugin<AppContext, Unit>(
                errorConsumer = { name, throwable -> println("$name: ${throwable.message}") },
                dispatcher = dispatcher,
                syncHandler = { ctx, route -> route.handler(AppContext(ctx)) },
                asyncHandler = { ctx, route, _ -> route.handler(AppContext(ctx)) }
            )
            .registerRoutes(exampleEndpoint)
            .let { config.registerPlugin(it) }
        }
        .events {
            it.serverStopping { dispatcher.prepareShutdown() }
            it.serverStopped { dispatcher.completeShutdown() }
        }
        .start("127.0.0.1", 8080)
}

~ source: RoutingExample.kt

Context

Provides utility methods in io.javalin.http.Context class:

Context.error(ErrorResponse)
Context.contentLength(Long)
Context.encoding(Charset)
Context.encoding(String)
Context.contentDisposition(String)
Context.resultAttachment(Name, ContentType, ContentLength, InputStream)

Provides generic ErrorResponse that supports removal of exception based error handling within app:

ErrorResponse(Int httpCode, String message)
ErrorResponse(HttpCode httpCode, String message)
/* Methods */
errorResponse(HttpCode httpCode, String message) -> Result<*, ErrorResponse>
// [...]

OpenAPI

Reimplemented OpenAPI module:

To enable annotation processor, Swagger or ReDoc you have to add extra dependencies from repository listed above.

Used by

You might also like...
Kotlin MPP bindings for various clis

kommander Kotlin MPP bindings for various cli tools. The libraries only wrap around the clis and still require them to be natively available on the PA

This is a Kotlin multiplatform template project used to generate and deploy a natively compiled AWS lambda function using the custom runtime.
This is a Kotlin multiplatform template project used to generate and deploy a natively compiled AWS lambda function using the custom runtime.

Overview This is a Kotlin multiplatform template project used to generate and deploy a natively compiled AWS Lambda function using a custom runtime. U

Theia - A Kotlin program used to analyze and discover backdoors in Minecraft Java 1.12.2 forge mods

Theia A Kotlin program used to analyse and discover backdoors in Minecraft Java

This lib implements the most common CoroutineScopes used in Android apps.

AndroidCoroutineScopes Starting from 0.26.0 release we should define a scope for new coroutines (docs). To avoid this boilerplate code I've created th

A simple demo that shows how WebWorkers can be used in Kotlin/JS

Web Workers in KotlinJS This repo demonstrates how to set up a Web Worker in Kotlin/JS. It is a very simple demo that creates a new worker that sends

Most used extension methods for Kotlin

Extensify Most used extension methods for Kotlin Download Step 1. Add the JitPack repository to your build file allprojects { repositories {

Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android.
Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android.

Klimatic Klimatic is an android app built using Kotlin. It try to showcase all the latest technologies used in android. Built using Android Architectu

Kotools Types - a lightweight library that provides commonly used types for Kotlin

Kotools Types is a lightweight library that provides commonly used types for Kotlin

An android lib that provides most commonly used utility function

Awesome-Utility An android lib that provides most commonly used utility function. It can help Android developers with supporting common utility functi

Comments
  • Coroutines FastHttpLoader - 11.08.2021

    Coroutines FastHttpLoader - 11.08.2021

    Spec

    val sharedThreadPool = QueuedThreadPool(4)
    
    class ExampleEndpoint(private val exampleFacade: ExampleFacade) : AbstractRoutes<AppContext>() {
    
        private val sync = route("/sync", GET, async = false) { context.result(blockingDelay("Sync")) }
    
        private val blockingAsync = route("/asyncBlocking", GET) { blockingDelay("Blocking Async") }
    
        private val nonBlockingAsync = route("/async", GET) { nonBlockingDelay("Non-blocking Async") }
    
        override val routes = setOf(sync, blockingAsync, nonBlockingAsync)
    
    }
    
    private suspend fun nonBlockingDelay(message: String): String =
        delay(100L).let { message }
    
    @Suppress("BlockingMethodInNonBlockingContext")
    private suspend fun blockingDelay(message: String): String =
        sleep(100L).let { message }
    

    Results

    Requests done per route in Burst Throughput (10s), Adjustment test (30s) and Loading test (30s):

    /sync           - 192 / 491  / 335
    /asyncBlocking  - 96  / 251  / 172
    /async          - 785 / 7203 / 10499
    

    Details

    Tool: https://github.com/hagen1778/fasthttploader

    • Sync
    ------ Burst Throughput ------
    Elapsed time: 10.094717s
    Req done: 192; Success: 100.00 %
    QPS: 19.019849; Connections: 8
    Errors: 0; Timeouts: 0
    
    ------ Adjustment test ------
    Elapsed time: 30.001615s
    Req done: 491; Success: 100.00 %
    QPS: 16.365786; Connections: 102
    Errors: 0; Timeouts: 0
    
    ------ Loading test ------
    Elapsed time: 30.002567s
    Req done: 335; Success: 100.00 %
    QPS: 11.165711; Connections: 107
    Errors: 188; Timeouts: 188
    
    • Async (blocking)
    ------ Burst Throughput ------
    Elapsed time: 10.050572s
    Req done: 96; Success: 100.00 %
    QPS: 9.551695; Connections: 8
    Errors: 0; Timeouts: 0
    
    ------ Adjustment test ------
    Elapsed time: 30.003456s
    Req done: 251; Success: 100.00 %
    QPS: 8.365703; Connections: 86
    Errors: 0; Timeouts: 0
    
    ------ Loading test ------
    Elapsed time: 30.002243s
    Req done: 172; Success: 100.00 %
    QPS: 5.732905; Connections: 172
    Errors: 146; Timeouts: 146
    
    • Async (non-blocking)
    ------ Burst Throughput ------
    Elapsed time: 10.050354s
    Req done: 785; Success: 100.00 %
    QPS: 78.106699; Connections: 8
    Errors: 0; Timeouts: 0
    
    ------ Adjustment test ------
    Elapsed time: 30.001574s
    Req done: 7203; Success: 100.00 %
    QPS: 240.087406; Connections: 30
    Errors: 0; Timeouts: 0
    
    ------ Loading test ------
    Elapsed time: 30.004469s
    Req done: 10499; Success: 100.00 %
    QPS: 349.914540; Connections: 29
    Errors: 0; Timeouts: 0
    
    documentation 
    opened by dzikoysk 0
Owner
Reposilite Playground
Additional Reposilite repositories that explore experimental features and libraries in different areas
Reposilite Playground
An experimental tool for building console UI in Kotlin using the Jetpack Compose compiler/runtime

An experimental tool for building console UI in Kotlin using the Jetpack Compose compiler/runtime

Jake Wharton 1.4k Dec 28, 2022
🐅 Experimental Kotlin library for Revolt (API subject is to change)

Kairi ?? Experimental Kotlin library for Revolt

Noel 3 Jul 4, 2022
An experimental UI toolkit for generating PowerPoint presentation files using Compose

ComposePPT An experimental UI toolkit for generating PowerPoint presentation files(.pptx) using Compose. Inspired by Glance and Mosaic. Why? This proj

Fatih Giriş 252 Dec 28, 2022
Sync chat messages and various information on Telegram and Minecraft

Sync chat messages and various information on Telegram and Minecraft

雪沢 坊洛 6 Dec 1, 2022
Automatic CoroutineDispatcher injection and extensions for kotlinx.coroutines

Dispatch Utilities for kotlinx.coroutines which make them type-safe, easier to test, and more expressive. Use the predefined types and factories or de

Rick Busarow 132 Dec 9, 2022
A collection of hand-crafted extensions for your Kotlin projects.

Splitties Splitties is a collection of small Kotlin multiplatform libraries (with Android as first target). These libraries are intended to reduce the

Louis CAD 2.2k Dec 25, 2022
Android View Lifecycle Extensions

Android View Lifecycle Extensions Extensions for Android View class that let you access a view lifecycle without having to create a custom view (exten

Thomas Gorisse 22 Dec 6, 2022
Actions are things that run, with parameters. Serves as a common dependency for a variety of Cepi extensions.

Actions Actions that take in customizable paramaters, an optional target, and do things. Installation Download the jar from Releases OR compile it you

Cepi 1 Jan 9, 2022
Common Android/Kotlin extensions

Common Android/Kotlin extensions Gradle implementation "com.github.javokhirsavriev:common-extensions:1.0.1" License Copyright 2022 Javokhir Savriev L

Javokhir 0 Feb 15, 2022
Android app to test various cryptography algorithm.

This android app shows how cryptographic algorithm works. You can encrypt or decrypt messages and try different algorithms. Powered by Bouncy Castle this app supports AES, Serpent, Blowfish and many more :)

null 3 Mar 21, 2022