Observable.subscribe().unsubscribe() and ListenableFuture.cancel() (#397)

Observable.subscribe().unsubscribe() dance to free up the MQ resources server-side.

* remove an unused import

* implement a FlowHandle<Transaction>.finalize method

* Rename finalize() to discard() - remove the collection and run discard individually

* Remove unused imports

* Observable.notUsed helper function

* Tweaks to comments

* FlowHandle implements AutoClosable

* Resolving conflicts and move notUsed to RPC module

* Copy Observable.notUsed in core module.

* delete discard method
This commit is contained in:
Konstantinos Chalkias
2017-03-31 10:08:12 +01:00
committed by GitHub
parent b62f901892
commit d72b75caa4
3 changed files with 55 additions and 9 deletions

View File

@ -0,0 +1,19 @@
package net.corda.client.rpc
import rx.Observable
/**
* This function should be invoked on any unwanted Observables returned from RPC to release the server resources.
*
* subscribe({}, {}) was used instead of simply calling subscribe()
* because if an {@code onError} emission arrives (eg. due to an non-correct transaction, such as 'Not sufficient funds')
* then {@link OnErrorNotImplementedException} is thrown. As we won't handle exceptions from unused Observables,
* empty inputs are used to subscribe({}, {}).
*/
fun <T> Observable<T>.notUsed() {
try {
this.subscribe({}, {}).unsubscribe()
} catch (e: Exception) {
// Swallow any other exceptions as well.
}
}