Code Monkey home page Code Monkey logo

sessionkotlin-template-gradle's Introduction

SessionKotlin

Multiparty Session Types in Kotlin: http://hdl.handle.net/10362/151147

master master coverage

val a = SKRole("ClientA")
val b = SKRole("ClientB")
val seller = SKRole("Seller")

globalProtocol("Protocol") {
    send<String>(a, seller, "id")

    send<Int>(seller, a, "valA")
    send<Int>(seller, b, "valB", "valA == valB")

    send<Int>(a, b, "proposal", "proposal <= valA")

    choice(b) {
        branch {
            send<Address>(b, seller, "buy")
            send<Date>(seller, b)
            send<Date>(b, a, "ok")
        }
        branch {
            send<Unit>(b, seller, "quit")
            send<Unit>(b, a, "quit")
        }
    }
}

Tip

If you'd like to see a more complex example, check our simplified SMTP implementation and the MPST definition.

Table of Contents

Getting started

Prerequisites

  • JDK 11

Project Templates

Gradle (recommended)

https://github.com/sessionkotlin/sessionkotlin-template-gradle

Maven

https://github.com/sessionkotlin/sessionkotlin-template-maven

Features

Reusable (and parametric) protocol definitions

val a = SKRole("A")
val b = SKRole("B")

fun subProtocol(x: SKRole, y: SKRole): GlobalProtocol = {
    send<Int>(x, y)
    send<Int>(y, x)
}

globalProtocol("ComplexProtocol") {
    choice(a) {
        branch {
            send<Int>(a, b, "branch1")
            subProtocol(a, b)()  // Proceed with subProtocol
        }
        branch {
            send<Int>(a, b, "branch2")
            subProtocol(b, a)()  // Proceed with subProtocol
        }
    }
}

Refinements

Basic arithmetic and logical operations supported by the Z3 theorem prover.

val a = SKRole("A")
val b = SKRole("B")

globalProtocol("RefinedProtocol") {
    send<Int>(a, b, "val1")
    send<Int>(b, a, "val2", "val2 >= val1")
}

Fluent and Callback-based local APIs

runBlocking {
    val chan = SKChannel()

    // Alice
    launch {
        SKMPEndpoint().use { e ->
            e.connect(Bob, chan)

            val buf = SKBuffer<Int>()

            ExampleProtocolAlice1(e)
                .sendToBob(1)
                .receiveFromBob(buf)
                .also { println("Alice received ${buf.value} from Bob") }
                .sendToBob("Hello")
        }
    }

    // Bob
    launch {
        var received = 0

        val callbacks = object : ExampleProtocolCallbacksBob {
            override fun onReceiveVal1FromAlice(value: Int) {
                received = value
            }
            override fun onSendVal2ToAlice(): Int = received * 2

            override fun onReceiveStringValueFromAlice(value: String) {
                println(value)
            }
        }

        ExampleProtocolCallbacksClassBob(callbacks).use { e ->
            e.connect(Alice, chan)
            e.start()
        }
    }
}

Communication through Sockets or Channels

val chanAB = SKChannel()

// Endpoint A
SKMPEndpoint().use { e ->
    e.connect(B, chanAB)
    // ...
}

// Endpoint B
SKMPEndpoint().use { e ->
    e.connect(A, chanAB)
    e.accept(C, 9999)
    // ...
}

// Endpoint C
SKMPEndpoint().use { e ->
    e.request(B, "localhost", 9999)
    // ...
}

Plugin configuration

To configure the plugin use the extension (default values shown):

sessionkotlin {
    cleanBeforeCopying = false //  always clean the solver dependencies before copying
}

Reference

@masterthesis { costa2022,
 author	= "Costa, David Maria Almeida Amorim da",
 title	= "Session Kotlin: A hybrid session type embedding in Kotlin",
 year	= "2022"
 url   = {http://hdl.handle.net/10362/151147}
}

sessionkotlin-template-gradle's People

Contributors

d-costa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.