Kotlin mode

 
1
package org.wasabi.http
2
3
import java.util.concurrent.Executors
4
import java.net.InetSocketAddress
5
import org.wasabi.app.AppConfiguration
6
import io.netty.bootstrap.ServerBootstrap
7
import io.netty.channel.nio.NioEventLoopGroup
8
import io.netty.channel.socket.nio.NioServerSocketChannel
9
import org.wasabi.app.AppServer
10
11
public class HttpServer(private val appServer: AppServer) {
12
13
    val bootstrap: ServerBootstrap
14
    val primaryGroup: NioEventLoopGroup
15
    val workerGroup:  NioEventLoopGroup
16
17
    {
18
        // Define worker groups
19
        primaryGroup = NioEventLoopGroup()
20
        workerGroup = NioEventLoopGroup()
21
22
        // Initialize bootstrap of server
23
        bootstrap = ServerBootstrap()
24
25
        bootstrap.group(primaryGroup, workerGroup)
26
        bootstrap.channel(javaClass<NioServerSocketChannel>())
27
        bootstrap.childHandler(NettyPipelineInitializer(appServer))
28
    }
29
30
    public fun start(wait: Boolean = true) {
31
        val channel = bootstrap.bind(appServer.configuration.port)?.sync()?.channel()
32
33
        if (wait) {
34
            channel?.closeFuture()?.sync()
35
        }
36
    }
37
38
    public fun stop() {
39
        // Shutdown all event loops
40
        primaryGroup.shutdownGracefully()
41
        workerGroup.shutdownGracefully()
42
43
        // Wait till all threads are terminated
44
        primaryGroup.terminationFuture().sync()
45
        workerGroup.terminationFuture().sync()
46
    }
47
}
48

Mode for Kotlin (http://kotlin.jetbrains.org/)

Developed by Hadi Hariri (https://github.com/hhariri).

MIME type defined: text/x-kotlin.