diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-09-12 11:46:03 +0200 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-09-12 11:46:03 +0200 |
| commit | 992b65396f55c0e12b36823d191dea8e03dd45ba (patch) | |
| tree | dc9e2fba5ca4d19a90934a8b68dbb8110ee34bb7 /opendc-trace/opendc-trace-api/src/main/kotlin | |
| parent | 3fb1eac8290181638a6571e4d7a49e53b7f3d7d1 (diff) | |
feat(trace): Support dynamic resolving of trace formats
This change enables users to open traces of various trace formats by
dynamically specifying the format name. The trace API will use the
service loader to resolve the available trace formats on the classpath.
Diffstat (limited to 'opendc-trace/opendc-trace-api/src/main/kotlin')
| -rw-r--r-- | opendc-trace/opendc-trace-api/src/main/kotlin/org/opendc/trace/Trace.kt | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/opendc-trace/opendc-trace-api/src/main/kotlin/org/opendc/trace/Trace.kt b/opendc-trace/opendc-trace-api/src/main/kotlin/org/opendc/trace/Trace.kt index 36e93b52..0ae45e86 100644 --- a/opendc-trace/opendc-trace-api/src/main/kotlin/org/opendc/trace/Trace.kt +++ b/opendc-trace/opendc-trace-api/src/main/kotlin/org/opendc/trace/Trace.kt @@ -22,6 +22,11 @@ package org.opendc.trace +import org.opendc.trace.spi.TraceFormat +import java.io.File +import java.net.URL +import java.nio.file.Path + /** * A trace is a collection of related tables that characterize a workload. */ @@ -40,4 +45,34 @@ public interface Trace { * Obtain a [Table] with the specified [name]. */ public fun getTable(name: String): Table? + + public companion object { + /** + * Open a [Trace] at the specified [url] in the given [format]. + * + * @throws IllegalArgumentException if [format] is not supported. + */ + public fun open(url: URL, format: String): Trace { + val provider = requireNotNull(TraceFormat.byName(format)) { "Unknown format $format" } + return provider.open(url) + } + + /** + * Open a [Trace] at the specified [path] in the given [format]. + * + * @throws IllegalArgumentException if [format] is not supported. + */ + public fun open(path: File, format: String): Trace { + return open(path.toURI().toURL(), format) + } + + /** + * Open a [Trace] at the specified [path] in the given [format]. + * + * @throws IllegalArgumentException if [format] is not supported. + */ + public fun open(path: Path, format: String): Trace { + return open(path.toUri().toURL(), format) + } + } } |
