node-driver: Remove parameter and DriverHandle, expose waitForAllNodesToFinish to dsl

This commit is contained in:
Andras Slemmer 2016-08-08 18:27:40 +01:00
parent c9527a2cdd
commit d0385c420e

View File

@ -46,6 +46,7 @@ private val log: Logger = LoggerFactory.getLogger(DriverDSL::class.java)
*/ */
interface DriverDSLExposedInterface { interface DriverDSLExposedInterface {
fun startNode(providedName: String? = null, advertisedServices: Set<ServiceType> = setOf()): NodeInfo fun startNode(providedName: String? = null, advertisedServices: Set<ServiceType> = setOf()): NodeInfo
fun waitForAllNodesToFinish()
val messagingService: MessagingService val messagingService: MessagingService
val networkMapCache: NetworkMapCache val networkMapCache: NetworkMapCache
} }
@ -53,7 +54,6 @@ interface DriverDSLExposedInterface {
interface DriverDSLInternalInterface : DriverDSLExposedInterface { interface DriverDSLInternalInterface : DriverDSLExposedInterface {
fun start() fun start()
fun shutdown() fun shutdown()
fun waitForAllNodesToFinish()
} }
sealed class PortAllocation { sealed class PortAllocation {
@ -87,7 +87,6 @@ sealed class PortAllocation {
* @param quasarJarPath The path to quasar.jar, relative to cwd. Defaults to "lib/quasar.jar". TODO remove this once we can bundle quasar properly. * @param quasarJarPath The path to quasar.jar, relative to cwd. Defaults to "lib/quasar.jar". TODO remove this once we can bundle quasar properly.
* @param portAllocation The port allocation strategy to use for the messaging and the web server addresses. Defaults to incremental. * @param portAllocation The port allocation strategy to use for the messaging and the web server addresses. Defaults to incremental.
* @param debugPortAllocation The port allocation strategy to use for jvm debugging. Defaults to incremental. * @param debugPortAllocation The port allocation strategy to use for jvm debugging. Defaults to incremental.
* @param with A closure to be run once the nodes have started up. Defaults to empty closure.
* @param dsl The dsl itself * @param dsl The dsl itself
* @return The value returned in the [dsl] closure * @return The value returned in the [dsl] closure
*/ */
@ -97,7 +96,6 @@ fun <A> driver(
quasarJarPath: String = "lib/quasar.jar", quasarJarPath: String = "lib/quasar.jar",
portAllocation: PortAllocation = PortAllocation.Incremental(10000), portAllocation: PortAllocation = PortAllocation.Incremental(10000),
debugPortAllocation: PortAllocation = PortAllocation.Incremental(5005), debugPortAllocation: PortAllocation = PortAllocation.Incremental(5005),
with: (DriverHandle, A) -> Unit = {_driverHandle, _result -> },
dsl: DriverDSLExposedInterface.() -> A dsl: DriverDSLExposedInterface.() -> A
) = genericDriver( ) = genericDriver(
driverDsl = DriverDSL( driverDsl = DriverDSL(
@ -108,8 +106,7 @@ fun <A> driver(
quasarJarPath = quasarJarPath quasarJarPath = quasarJarPath
), ),
coerce = { it }, coerce = { it },
dsl = dsl, dsl = dsl
with = with
) )
@ -124,8 +121,7 @@ fun <A> driver(
fun <DI : DriverDSLExposedInterface, D : DriverDSLInternalInterface, A> genericDriver( fun <DI : DriverDSLExposedInterface, D : DriverDSLInternalInterface, A> genericDriver(
driverDsl: D, driverDsl: D,
coerce: (D) -> DI, coerce: (D) -> DI,
dsl: DI.() -> A, dsl: DI.() -> A
with: (DriverHandle, A) -> Unit
): A { ): A {
var shutdownHook: Thread? = null var shutdownHook: Thread? = null
try { try {
@ -135,7 +131,6 @@ fun <DI : DriverDSLExposedInterface, D : DriverDSLInternalInterface, A> genericD
driverDsl.shutdown() driverDsl.shutdown()
}) })
Runtime.getRuntime().addShutdownHook(shutdownHook) Runtime.getRuntime().addShutdownHook(shutdownHook)
with(DriverHandle(driverDsl), returnValue)
return returnValue return returnValue
} finally { } finally {
driverDsl.shutdown() driverDsl.shutdown()
@ -174,15 +169,6 @@ fun addressMustNotBeBound(hostAndPort: HostAndPort) {
} }
} }
class DriverHandle(private val driverDsl: DriverDSLInternalInterface) {
val messagingService = driverDsl.messagingService
val networkMapCache = driverDsl.networkMapCache
fun waitForAllNodesToFinish() {
driverDsl.waitForAllNodesToFinish()
}
}
fun <A> poll(f: () -> A?): A { fun <A> poll(f: () -> A?): A {
var counter = 0 var counter = 0
var result = f() var result = f()