Created
March 12, 2018 22:48
-
-
Save vhutov/ec70838f8408d6c7db1c0d95c162658f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GenericActionBuilder[V <: Message]( | |
attributes: Attributes[V], | |
requestActionBuilder: RequestActionBuilder[V], | |
responseActionBuilder: ResponseActionBuilder | |
) extends ActionBuilder with LazyLogging { | |
override def build(ctx: ScenarioContext, next: Action): Action = { | |
import ctx._ | |
val requestProtocolComponents = protocolComponentsRegistry.components(requestActionBuilder.key) | |
val responseProtocolComponents = protocolComponentsRegistry.components(responseActionBuilder.key) | |
val publisher = requestActionBuilder.build(ctx, requestProtocolComponents) | |
logger.debug(s"Publisher ${publisher.name} has been instantiated") | |
val consumer = responseActionBuilder.build(ctx, responseProtocolComponents) | |
logger.debug(s"Consumer ${consumer.name} has been instantiated") | |
system.registerOnTermination { | |
safe(publisher.close()) | |
safe(consumer.close()) | |
} | |
new GenericAction[V]( | |
coreComponents, | |
attributes, | |
publisher, | |
consumer, | |
throttled, | |
next | |
) | |
} | |
private def safe(f: => Unit): Unit = { | |
var r: Unit = () //to prevent JIT from skipping execution of f | |
try { | |
r = f | |
} catch {case NonFatal(e) => e.printStackTrace()} | |
} | |
} | |
case class Attributes[V]( | |
requestName: Expression[String], | |
payload: Expression[V] | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment