node: stop() ClientFactory and ServerLocator when shutting down and ArtemisMessagingClient

This commit is contained in:
Andras Slemmer 2016-08-09 14:54:23 +01:00
parent d0385c420e
commit 9e3220671c

View File

@ -65,7 +65,8 @@ class ArtemisMessagingClient(directory: Path,
private val mutex = ThreadBox(InnerState()) private val mutex = ThreadBox(InnerState())
private val handlers = CopyOnWriteArrayList<Handler>() private val handlers = CopyOnWriteArrayList<Handler>()
private lateinit var clientFactory: ClientSessionFactory private var serverLocator: ServerLocator? = null
private var clientFactory: ClientSessionFactory? = null
private var session: ClientSession? = null private var session: ClientSession? = null
private var consumer: ClientConsumer? = null private var consumer: ClientConsumer? = null
@ -86,8 +87,11 @@ class ArtemisMessagingClient(directory: Path,
private fun configureAndStartClient() { private fun configureAndStartClient() {
log.info("Connecting to server: $serverHostPort") log.info("Connecting to server: $serverHostPort")
// Connect to our server. // Connect to our server.
clientFactory = ActiveMQClient.createServerLocatorWithoutHA( val serverLocator = ActiveMQClient.createServerLocatorWithoutHA(
tcpTransport(ConnectionDirection.OUTBOUND, serverHostPort.hostText, serverHostPort.port)).createSessionFactory() tcpTransport(ConnectionDirection.OUTBOUND, serverHostPort.hostText, serverHostPort.port))
this.serverLocator = serverLocator
val clientFactory = serverLocator.createSessionFactory()
this.clientFactory = clientFactory
// Create a queue on which to receive messages and set up the handler. // Create a queue on which to receive messages and set up the handler.
val session = clientFactory.createSession() val session = clientFactory.createSession()
@ -168,6 +172,8 @@ class ArtemisMessagingClient(directory: Path,
producers.clear() producers.clear()
consumer?.close() consumer?.close()
session?.close() session?.close()
clientFactory?.close()
serverLocator?.close()
// We expect to be garbage collected shortly after being stopped, so we don't null anything explicitly here. // We expect to be garbage collected shortly after being stopped, so we don't null anything explicitly here.
running = false running = false
} }