diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-03-27 12:48:51 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-27 12:48:51 +0100 |
| commit | bef2b2fc9ab97941613ec4537ebca1eb3fccdee6 (patch) | |
| tree | 4a4c1e0fb2de6aa0a0b9810f9c255e039a7ce47b /simulator/opendc-utils/src | |
| parent | 57ebc8a1c6779d7e7276754838e83f1c026cceb9 (diff) | |
| parent | 5b0eaf76ec00192c755b268b7655f6463c5bc62f (diff) | |
Integrate OpenTelemetry into OpenDC
This pull request resolves issue #91 by adopting the industry-standard OpenTelemetry standard
for collecting traces and metrics in OpenDC simulations:
* Metrics will now be exposed through OpenTelemetry's metrics API
* `opendc-telemetry` provides complementary code to support
gathering telemetry in OpenDC.
**Breaking API Changes**
* `opendc-tracer` has been removed.
* `EventFlow` and all usages of it have been removed.
* `opendc-experiments-sc18` has been removed for now, but a
suitable replacement will follow soon.
Diffstat (limited to 'simulator/opendc-utils/src')
| -rw-r--r-- | simulator/opendc-utils/src/main/kotlin/org/opendc/utils/flow/EventFlow.kt | 112 |
1 files changed, 0 insertions, 112 deletions
diff --git a/simulator/opendc-utils/src/main/kotlin/org/opendc/utils/flow/EventFlow.kt b/simulator/opendc-utils/src/main/kotlin/org/opendc/utils/flow/EventFlow.kt deleted file mode 100644 index 10f29f4e..00000000 --- a/simulator/opendc-utils/src/main/kotlin/org/opendc/utils/flow/EventFlow.kt +++ /dev/null @@ -1,112 +0,0 @@ -/* - * Copyright (c) 2020 AtLarge Research - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package org.opendc.utils.flow - -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.FlowPreview -import kotlinx.coroutines.InternalCoroutinesApi -import kotlinx.coroutines.channels.Channel -import kotlinx.coroutines.channels.SendChannel -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.FlowCollector -import kotlinx.coroutines.flow.consumeAsFlow - -/** - * A [Flow] that can be used to emit events. - */ -public interface EventFlow<T> : Flow<T> { - /** - * Emit the specified [event]. - */ - public fun emit(event: T) - - /** - * Close the flow. - */ - public fun close() -} - -/** - * Creates a new [EventFlow]. - */ -@Suppress("FunctionName") -public fun <T> EventFlow(): EventFlow<T> = EventFlowImpl() - -/** - * Internal implementation of the [EventFlow] class. - */ -@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) -private class EventFlowImpl<T> : EventFlow<T> { - private var closed: Boolean = false - private val subscribers = mutableListOf<SendChannel<T>>() - - override fun emit(event: T) { - if (closed) { - return - } - - val it = subscribers.iterator() - synchronized(this) { - while (it.hasNext()) { - val chan = it.next() - if (chan.isClosedForSend) { - it.remove() - } else { - chan.offer(event) - } - } - } - } - - override fun close() { - synchronized(this) { - closed = true - - for (chan in subscribers) { - chan.close() - } - - subscribers.clear() - } - } - - @InternalCoroutinesApi - override suspend fun collect(collector: FlowCollector<T>) { - val channel: Channel<T> - synchronized(this) { - if (closed) { - return - } - - channel = Channel(Channel.UNLIMITED) - subscribers.add(channel) - } - try { - channel.consumeAsFlow().collect(collector) - } finally { - channel.close() - } - } - - override fun toString(): String = "EventFlow" -} |
