From c775e8677cdbf69f2b1c1390d225329c658c0ee2 Mon Sep 17 00:00:00 2001 From: Piotr Jaszczyk Date: Wed, 3 Apr 2019 15:07:22 +0200 Subject: Get rid of arrow-effects usage Also clean-up dependencies + use Kotlin BOM to force single kotlin-stdlib on classpath. Issue-ID: DCAEGEN2-1392 Change-Id: I447c4686707de81f35f7734255ce0b13c997c4a4 Signed-off-by: Piotr Jaszczyk --- .../onap/dcae/collectors/veshv/utils/arrow/core.kt | 12 +--- .../dcae/collectors/veshv/utils/arrow/effects.kt | 79 ---------------------- .../dcae/collectors/veshv/utils/logging/Marker.kt | 3 +- .../dcae/collectors/veshv/utils/process/process.kt | 40 +++++++++++ .../org/onap/dcae/collectors/veshv/utils/rx/rx.kt | 33 +++++++++ .../dcae/collectors/veshv/utils/server_handle.kt | 9 +-- 6 files changed, 81 insertions(+), 95 deletions(-) delete mode 100644 sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/effects.kt create mode 100644 sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/process/process.kt create mode 100644 sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/rx/rx.kt (limited to 'sources/hv-collector-utils/src/main/kotlin/org/onap') diff --git a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt index 47b3d559..cfed7f32 100644 --- a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt +++ b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/core.kt @@ -23,16 +23,11 @@ import arrow.core.Either import arrow.core.ForOption import arrow.core.Option import arrow.core.Try +import arrow.core.extensions.option.monad.monad import arrow.core.fix import arrow.core.identity -import arrow.effects.ForIO -import arrow.effects.IO -import arrow.effects.fix -import arrow.effects.instances.io.monad.monad -import arrow.instances.option.monad.monad import arrow.syntax.collections.firstOption import arrow.typeclasses.MonadContinuation -import arrow.typeclasses.binding import reactor.core.publisher.Flux import reactor.core.publisher.Mono import java.util.concurrent.atomic.AtomicReference @@ -47,11 +42,6 @@ object OptionUtils { : Option = Option.monad().binding(c).fix() } -object IOUtils { - fun binding(c: suspend MonadContinuation.() -> A) - : IO = IO.monad().binding(c).fix() -} - fun Either.flatten() = fold(::identity, ::identity) fun Either.rightOrThrow() = fold({ throw it }, ::identity) diff --git a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/effects.kt b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/effects.kt deleted file mode 100644 index 56825221..00000000 --- a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/arrow/effects.kt +++ /dev/null @@ -1,79 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * dcaegen2-collectors-veshv - * ================================================================================ - * Copyright (C) 2018 NOKIA - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.dcae.collectors.veshv.utils.arrow - -import arrow.core.Either -import arrow.core.Left -import arrow.core.Right -import arrow.effects.IO -import org.reactivestreams.Publisher -import reactor.core.publisher.Flux -import reactor.core.publisher.Mono -import reactor.core.publisher.toMono -import kotlin.system.exitProcess - -/** - * @author Piotr Jaszczyk - * @since June 2018 - */ - -sealed class ExitCode { - abstract val code: Int - - fun io() = IO { - exitProcess(code) - } -} - -object ExitSuccess : ExitCode() { - override val code = 0 -} - -data class ExitFailure(override val code: Int) : ExitCode() - -inline fun Either, IO>.unsafeRunEitherSync(onError: (Throwable) -> ExitCode, onSuccess: () -> Unit) = - flatten().attempt().unsafeRunSync().fold({ onError(it).io().unsafeRunSync() }, { onSuccess() }) - -fun IO.unit() = map { Unit } - -fun Mono.asIo() = IO.async { callback -> - subscribe({ - callback(Right(it)) - }, { - callback(Left(it)) - }) -} - -fun Publisher.then(callback: () -> Unit): Mono = - toMono().then(Mono.fromCallable(callback)) - -fun Flux>.evaluateIo(): Flux = - flatMap { io -> - io.attempt().unsafeRunSync().fold( - { Flux.error(it) }, - { Flux.just(it) } - ) - } - -inline fun IO.then(crossinline block: (T) -> Unit): IO = - map { - block(it) - it - } diff --git a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Marker.kt b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Marker.kt index 9023528e..ac39100d 100644 --- a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Marker.kt +++ b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/logging/Marker.kt @@ -28,7 +28,8 @@ sealed class Marker(internal val slf4jMarker: org.slf4j.Marker, val mdc: Map + * @since June 2018 + */ + +sealed class ExitCode { + abstract val code: Int + + fun doExit(): Nothing = exitProcess(code) + +} + +object ExitSuccess : ExitCode() { + override val code = 0 +} + +data class ExitFailure(override val code: Int) : ExitCode() diff --git a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/rx/rx.kt b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/rx/rx.kt new file mode 100644 index 00000000..ceccbcba --- /dev/null +++ b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/rx/rx.kt @@ -0,0 +1,33 @@ +/* + * ============LICENSE_START======================================================= + * dcaegen2-collectors-veshv + * ================================================================================ + * Copyright (C) 2018-2019 NOKIA + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +/** + * @author Piotr Jaszczyk + * @since June 2018 + */ +package org.onap.dcae.collectors.veshv.utils.rx + +import org.reactivestreams.Publisher +import reactor.core.publisher.Mono +import reactor.core.publisher.toMono + +fun Publisher.then(callback: () -> Unit): Mono = + toMono().then(Mono.fromCallable(callback)) diff --git a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/server_handle.kt b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/server_handle.kt index 670ab4ac..728d62bb 100644 --- a/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/server_handle.kt +++ b/sources/hv-collector-utils/src/main/kotlin/org/onap/dcae/collectors/veshv/utils/server_handle.kt @@ -19,7 +19,6 @@ */ package org.onap.dcae.collectors.veshv.utils -import arrow.effects.IO import org.onap.dcae.collectors.veshv.utils.logging.Logger import reactor.core.publisher.Mono import reactor.netty.DisposableServer @@ -29,7 +28,7 @@ import reactor.netty.DisposableServer * @since August 2018 */ abstract class ServerHandle(val host: String, val port: Int) : Closeable { - abstract fun await(): IO + abstract fun await(): Mono } /** @@ -58,8 +57,10 @@ class NettyServerHandle(private val ctx: DisposableServer, } } - override fun await() = IO { - ctx.channel().closeFuture().sync() + override fun await(): Mono = Mono.create { callback -> + ctx.channel().closeFuture().addListener { + callback.success() + } } companion object { -- cgit 1.2.3-korg