Skip to content

Commit

Permalink
Added support for configurable engine preferences (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolak-net committed Feb 11, 2018
1 parent 1d460d7 commit 90597f9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
6 changes: 5 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
= Travesty
:issueBaseUrl: https://github.com/mikolak-net/travesty/issues/
:repoBaseUrl: https://github.com/mikolak-net/travesty
:fileBrowseBaseUrl: {repoBaseUrl}/blob/master/
:issueBaseUrl: {repoBaseUrl}/issues/
:toc:

image:https://travis-ci.org/mikolak-net/travesty.svg?branch=master["Build Status", link="https://travis-ci.org/mikolak-net/travesty"]
Expand Down Expand Up @@ -139,6 +141,8 @@ The graph/diagram generated from the `Traversal` object does not correspond 1:1
by `travesty`, for maximum portability, is also the slowest one. While generating the graph is always fast,
rendering the diagram may take up to ~10 seconds.

If you would like to try switching to a faster engine, see {fileBrowseBaseUrl}src/main/resources/reference.conf[`reference.conf`] for more info.

=== Tight coupling with Akka Stream's internals

As mentioned before, `travesty` uses the internal API for graph/diagram generation. This is why the
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/reference.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
travesty {
cache.shape-cache-ttl = 5 minutes
#JDK is most platform-independent, but slowest. CommandLine is fastest, but requires external dependencies
engines = [JDK, V8, CommandLine]
}
16 changes: 10 additions & 6 deletions src/main/scala/net/mikolak/travesty/Api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ package net.mikolak.travesty
import java.awt.image.BufferedImage
import java.io.File

import akka.stream.{ClosedShape, Graph, StreamDeconstructorProxy}
import akka.stream.StreamDeconstructorProxy
import gremlin.scala._
import guru.nidi.graphviz.engine.{Graphviz, GraphvizCmdLineEngine, GraphvizJdkEngine, GraphvizV8Engine}
import net.mikolak.travesty._
import guru.nidi.graphviz.engine.Graphviz
import net.mikolak.travesty.render.TypeNameSimplifier
import net.mikolak.travesty.setup.GraphvizEngineType

import org.log4s._
import render.TypeNameSimplifier

import scala.reflect.runtime.universe._

private[travesty] class Api(deconstruct: StreamDeconstructorProxy,
typeNameSimplifier: TypeNameSimplifier,
lowLevelApi: VizGraphProcessor) {
lowLevelApi: VizGraphProcessor,
engines: List[GraphvizEngineType.Value]) {

private val logger = getLogger

Expand Down Expand Up @@ -49,6 +51,8 @@ private[travesty] class Api(deconstruct: StreamDeconstructorProxy,
}

{ //initialize GraphViz engine
Graphviz.useEngine(new GraphvizJdkEngine, new GraphvizV8Engine, new GraphvizCmdLineEngine())
import GraphvizEngineType._
val first :: rest = engines.map(_.instantiate())
Graphviz.useEngine(first, rest: _*)
}
}
14 changes: 14 additions & 0 deletions src/main/scala/net/mikolak/travesty/setup/GraphvizEngineType.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package net.mikolak.travesty.setup

import guru.nidi.graphviz.engine.{AbstractGraphvizEngine, GraphvizCmdLineEngine, GraphvizJdkEngine, GraphvizV8Engine}

object GraphvizEngineType extends Enumeration {

protected case class Val(instantiate: () => AbstractGraphvizEngine) extends super.Val
implicit def valueToPlanetVal(x: Value): Val = x.asInstanceOf[Val]

val CommandLine = Val(() => new GraphvizCmdLineEngine())
val JDK = Val(() => new GraphvizJdkEngine)
val V8 = Val(() => new GraphvizV8Engine)

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package net.mikolak.travesty.setup

import scala.concurrent.duration.FiniteDuration

private[travesty] case class TravestyConfig(cache: CacheConfig)
private[travesty] case class TravestyConfig(cache: CacheConfig, engines: List[GraphvizEngineType.Value])

private[travesty] case class CacheConfig(shapeCacheTtl: FiniteDuration)
2 changes: 2 additions & 0 deletions src/main/scala/net/mikolak/travesty/setup/Wiring.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import net.ceedubs.ficus.readers.ArbitraryTypeReader._
import net.mikolak.travesty.render.TypeNameSimplifier
import net.mikolak.travesty.{Api, Registry, VizGraphProcessor}
import net.ceedubs.ficus.readers.namemappers.implicits.hyphenCase
import net.ceedubs.ficus.readers.EnumerationReader._

private[travesty] object Wiring {

lazy val baseConfig = ConfigFactory.load()
lazy val config = baseConfig.as[TravestyConfig]("travesty")
import config.cache
import config.engines

lazy val registry = wire[Registry]
lazy val streamDeconstructorProxy = wire[StreamDeconstructorProxy]
Expand Down

0 comments on commit 90597f9

Please sign in to comment.