@@ -85,7 +85,7 @@ internal constructor(
8585 throw PoolAlreadyTerminatedException ()
8686 }
8787 val future = CompletableFuture <T >()
88- val offered = actor.offer (Take (future))
88+ val offered = actor.trySend (Take (future)).isSuccess
8989 if (! offered) {
9090 future.completeExceptionally(Exception (" could not offer to actor" ))
9191 }
@@ -94,7 +94,7 @@ internal constructor(
9494
9595 override fun giveBack (item : T ): CompletableFuture <AsyncObjectPool <T >> {
9696 val future = CompletableFuture <Unit >()
97- val offered = actor.offer (GiveBack (item, future))
97+ val offered = actor.trySend (GiveBack (item, future)).isSuccess
9898 if (! offered) {
9999 future.completeExceptionally(Exception (" could not offer to actor" ))
100100 }
@@ -108,7 +108,7 @@ internal constructor(
108108 logger.info { " closing the pool" }
109109 closed = true
110110 val future = CompletableFuture <Unit >()
111- val offered = actor.offer (Close (future))
111+ val offered = actor.trySend (Close (future)).isSuccess
112112 if (! offered) {
113113 future.completeExceptionally(Exception (" could not offer to actor" ))
114114 }
@@ -125,7 +125,7 @@ internal constructor(
125125 return
126126 }
127127 logger.trace { " testAvailableItems - starting" }
128- val offered = actor.offer (TestPoolItems ())
128+ val offered = actor.trySend (TestPoolItems ()).isSuccess
129129 if (! offered) {
130130 logger.warn { " failed to offer to actor - testAvailableItems()" }
131131 }
@@ -381,7 +381,7 @@ private class ObjectPoolActor<T : PooledObject>(
381381 }
382382
383383 private fun offerOrLog (message : ActorObjectPoolMessage <T >, logMessage : () -> String ) {
384- val offered = channel.offer (message)
384+ val offered = channel.trySend (message).isSuccess
385385 if (! offered) {
386386 logger.warn { " failed to offer on ${logMessage()} " }
387387 }
@@ -537,8 +537,9 @@ private class ObjectPoolActor<T : PooledObject>(
537537 }
538538
539539 private fun validate (item : T ) {
540- when (val tried = objectFactory.validate(item)) {
541- is Failure -> throw tried.exception
540+ val tried = objectFactory.validate(item)
541+ if (tried is Failure ) {
542+ throw tried.exception
542543 }
543544 }
544545}
0 commit comments