tuweni / org.apache.tuweni.hobbits / HobbitsTransport

HobbitsTransport

class HobbitsTransport : CoroutineScope (source)

Hobbits is a peer-to-peer transport stack specified at https://www.github.com/deltap2p/hobbits.

This class works as a transport mechanism that can leverage a variety of network transport protocols, such as TCP, HTTP, UDP and Web sockets.

It can be used to contact other Hobbits endpoints, or to expose endpoints to the network.

Parameters

vertx - Vert.x instance

incompleteMessageHandler - a handler to manage incomplete or invalid messages

coroutineContext - the co-routine context for the transport

Constructors

<init>

HobbitsTransport(vertx: Vertx, incompleteMessageHandler: (Bytes) -> Unit = {}, coroutineContext: CoroutineContext = Dispatchers.Default)

Hobbits is a peer-to-peer transport stack specified at https://www.github.com/deltap2p/hobbits.

Properties

coroutineContext

val coroutineContext: CoroutineContext

the co-routine context for the transport

Functions

createHTTPEndpoint

fun createHTTPEndpoint(id: String = "default", networkInterface: String = "0.0.0.0", port: Int = 9337, requestURI: String? = null, tls: Boolean = false, handler: (Message) -> Unit): Unit

Creates a new endpoint over http.

createTCPEndpoint

fun createTCPEndpoint(id: String = "default", networkInterface: String = "0.0.0.0", port: Int = 9237, tls: Boolean = false, handler: (Message) -> Unit): Unit

Creates a new endpoint over tcp persistent connections.

createUDPEndpoint

fun createUDPEndpoint(id: String = "default", networkInterface: String = "0.0.0.0", port: Int = 9137, handler: (Message) -> Unit): Unit

Creates a new endpoint over UDP connections.

createWSEndpoint

fun createWSEndpoint(id: String = "default", networkInterface: String = "0.0.0.0", port: Int = 9037, requestURI: String? = null, tls: Boolean = false, handler: (Message) -> Unit): Unit

Creates a new endpoint over websocket connections.

exceptionHandler

fun exceptionHandler(handler: (Throwable) -> Unit): Unit

Sets an exception handler that will be called whenever an exception occurs during transport.

sendMessage

suspend fun sendMessage(message: Message, transport: Transport, host: String, port: Int, requestURI: String = ""): Unit

Sends a message using the transport specified.

start

suspend fun start(): Unit

Starts the hobbits transport.

stop

fun stop(): Unit

Stops the hobbits transport.

Extension Functions

asyncCompletion

fun CoroutineScope.asyncCompletion(context: CoroutineContext = Dispatchers.Default, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> Unit): AsyncCompletion

Starts new co-routine and returns its result as an implementation of AsyncCompletion. The running co-routine is cancelled when the resulting future is cancelled or otherwise completed.

asyncResult

fun <T> CoroutineScope.asyncResult(context: CoroutineContext = Dispatchers.Default, start: CoroutineStart = CoroutineStart.DEFAULT, block: suspend CoroutineScope.() -> T): AsyncResult<T>

Starts new co-routine and returns its result as an implementation of AsyncResult. The running co-outine is cancelled when the resulting future is cancelled or otherwise completed.

retry

suspend fun <R> CoroutineScope.retry(retryDelay: Long, block: suspend (Int) -> R?): R
suspend fun <R> CoroutineScope.retry(retryDelay: Long, maxRetries: Int, block: suspend (Int) -> R?): R?
suspend fun <R> CoroutineScope.retry(retryDelay: (Int) -> Long?, block: suspend (Int) -> R?): R?

Retry a suspending block until a non-null result is obtained.