@@ -56,45 +56,34 @@ class NatsContext(
5656 keyValue = getOrCreateBucket(conn)
5757 connection = conn
5858 } catch (e: Exception ) {
59- logger.error(" Failed to setup bucket" , e)
59+ logger.error(" Failed to setup the persistent context bucket" , e)
6060 } finally {
6161 connectedLatch.countDown()
6262 }
6363 }
64- logger.info(" (Re)connected to NATS for persistent context" )
64+ logger.info(" (Re)connected to the NATS server for persistent context" )
6565 }
6666
6767 ConnectionListener .Events .DISCONNECTED -> {
6868 synchronized(lock) {
6969 connection = null
7070 keyValue = null
7171 }
72- logger.warn(" NATS disconnected for persistent context" )
72+ logger.warn(" Disconnected from the NATS server for persistent context" )
7373 }
7474
7575 else -> {}
7676 }
7777 }
7878 }
7979 )
80- .errorListener(
81- object : ErrorListener {
82- override fun errorOccurred (conn : Connection ? , error : String? ) {
83- logger.error(" NATS error: $error " )
84- }
85-
86- override fun exceptionOccurred (conn : Connection ? , e : Exception ? ) {
87- logger.error(" NATS exception" , e)
88- }
89- }
90- )
9180 .build()
9281
9382 try {
9483 Nats .connectAsynchronously(options, true )
95- } catch (e : InterruptedException ) {
84+ } catch (_ : InterruptedException ) {
9685 Thread .currentThread().interrupt()
97- logger.error(" Interrupted while initiating NATS connection, will never connect" , e )
86+ logger.error(" Interrupted while initiating NATS connection, will never connect" )
9887 }
9988 }
10089
@@ -103,7 +92,7 @@ class NatsContext(
10392 runCatching {
10493 conn.keyValueManagement().apply {
10594 if (! bucketNames.contains(bucketName)) {
106- logger.warn(" Bucket '$bucketName ' does not exist, creating it" )
95+ logger.warn(" Persistent bucket '$bucketName ' does not exist, creating it" )
10796 create(KeyValueConfiguration .Builder ().name(bucketName).build())
10897 }
10998 }
@@ -128,7 +117,8 @@ class NatsContext(
128117 override fun get (name : String ): Any =
129118 synchronized(lock) {
130119 runCatching {
131- val kv = keyValue ? : throw IOException (" Not connected to NATS for persistent context" )
120+ val kv =
121+ keyValue ? : throw IOException (" Not connected to the NATS server for persistent context" )
132122 if (! kv.keys().contains(name)) {
133123 throw IOException (" A variable with the name '$name ' does not exist" )
134124 }
@@ -151,7 +141,8 @@ class NatsContext(
151141 override fun create (name : String , value : Any? ): Int =
152142 synchronized(lock) {
153143 runCatching {
154- val kv = keyValue ? : throw IOException (" Not connected to NATS for persistent context" )
144+ val kv =
145+ keyValue ? : throw IOException (" Not connected to the NATS server for persistent context" )
155146 if (kv.keys().contains(name)) {
156147 throw IOException (" A variable with the name '$name ' already exists" )
157148 }
@@ -175,7 +166,8 @@ class NatsContext(
175166 override fun assign (name : String , value : Any? ): Int =
176167 synchronized(lock) {
177168 runCatching {
178- val kv = keyValue ? : throw IOException (" Not connected to NATS for persistent context" )
169+ val kv =
170+ keyValue ? : throw IOException (" Not connected to the NATS server for persistent context" )
179171 if (! kv.keys().contains(name)) {
180172 throw IOException (" A variable with the name '$name ' does not exist" )
181173 }
@@ -197,7 +189,8 @@ class NatsContext(
197189 override fun delete (name : String ) {
198190 synchronized(lock) {
199191 runCatching {
200- val kv = keyValue ? : throw IOException (" Not connected to NATS for persistent context" )
192+ val kv =
193+ keyValue ? : throw IOException (" Not connected to the NATS server for persistent context" )
201194 if (! kv.keys().contains(name)) {
202195 throw IOException (" A variable with the name '$name ' does not exist" )
203196 }
@@ -212,7 +205,8 @@ class NatsContext(
212205 override fun getAll (): List <ContextVariable > =
213206 synchronized(lock) {
214207 runCatching {
215- val kv = keyValue ? : throw IOException (" Not connected to NATS for persistent context" )
208+ val kv =
209+ keyValue ? : throw IOException (" Not connected to the NATS server for persistent context" )
216210 kv.keys().map { key ->
217211 val entry = kv.get(key)
218212 ContextVariable (entry.key, entry.value)
@@ -231,7 +225,7 @@ class NatsContext(
231225 conn.close()
232226 }
233227 }
234- .onFailure { e -> throw IOException (" Failed to close NATS persistent context" , e) }
228+ .onFailure { e -> throw IOException (" Failed to close the NATS persistent context" , e) }
235229 }
236230 }
237231
0 commit comments