mirror of
https://github.com/corda/corda.git
synced 2024-12-21 22:07:55 +00:00
Minor: auto-format of module: client
This commit is contained in:
parent
d9391b3d29
commit
6f200562b3
@ -39,11 +39,13 @@ object JacksonSupport {
|
|||||||
override fun partyFromName(partyName: String): Party? = rpc.partyFromName(partyName)
|
override fun partyFromName(partyName: String): Party? = rpc.partyFromName(partyName)
|
||||||
override fun partyFromKey(owningKey: CompositeKey): Party? = rpc.partyFromKey(owningKey)
|
override fun partyFromKey(owningKey: CompositeKey): Party? = rpc.partyFromKey(owningKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
class IdentityObjectMapper(val identityService: IdentityService, factory: JsonFactory) : PartyObjectMapper, ObjectMapper(factory) {
|
class IdentityObjectMapper(val identityService: IdentityService, factory: JsonFactory) : PartyObjectMapper, ObjectMapper(factory) {
|
||||||
override fun partyFromName(partyName: String): Party? = identityService.partyFromName(partyName)
|
override fun partyFromName(partyName: String): Party? = identityService.partyFromName(partyName)
|
||||||
override fun partyFromKey(owningKey: CompositeKey): Party? = identityService.partyFromKey(owningKey)
|
override fun partyFromKey(owningKey: CompositeKey): Party? = identityService.partyFromKey(owningKey)
|
||||||
}
|
}
|
||||||
class NoPartyObjectMapper(factory: JsonFactory): PartyObjectMapper, ObjectMapper(factory) {
|
|
||||||
|
class NoPartyObjectMapper(factory: JsonFactory) : PartyObjectMapper, ObjectMapper(factory) {
|
||||||
override fun partyFromName(partyName: String): Party? = throw UnsupportedOperationException()
|
override fun partyFromName(partyName: String): Party? = throw UnsupportedOperationException()
|
||||||
override fun partyFromKey(owningKey: CompositeKey): Party? = throw UnsupportedOperationException()
|
override fun partyFromKey(owningKey: CompositeKey): Party? = throw UnsupportedOperationException()
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ class NodeMonitorModel {
|
|||||||
* TODO provide an unsubscribe mechanism
|
* TODO provide an unsubscribe mechanism
|
||||||
*/
|
*/
|
||||||
fun register(nodeHostAndPort: HostAndPort, username: String, password: String) {
|
fun register(nodeHostAndPort: HostAndPort, username: String, password: String) {
|
||||||
val client = CordaRPCClient(nodeHostAndPort){
|
val client = CordaRPCClient(nodeHostAndPort) {
|
||||||
maxRetryInterval = 10.seconds.toMillis()
|
maxRetryInterval = 10.seconds.toMillis()
|
||||||
}
|
}
|
||||||
client.start(username, password)
|
client.start(username, password)
|
||||||
|
@ -4,7 +4,6 @@ import javafx.collections.FXCollections
|
|||||||
import javafx.collections.ListChangeListener
|
import javafx.collections.ListChangeListener
|
||||||
import javafx.collections.ObservableList
|
import javafx.collections.ObservableList
|
||||||
import javafx.collections.transformation.TransformationList
|
import javafx.collections.transformation.TransformationList
|
||||||
import kotlin.comparisons.compareValues
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given an [ObservableList]<[E]> and a grouping key [K], [AggregatedList] groups the elements by the key into a fresh
|
* Given an [ObservableList]<[E]> and a grouping key [K], [AggregatedList] groups the elements by the key into a fresh
|
||||||
|
@ -13,7 +13,7 @@ import java.util.stream.Collectors
|
|||||||
* Utility bindings for the [Amount] type, similar in spirit to [Bindings]
|
* Utility bindings for the [Amount] type, similar in spirit to [Bindings]
|
||||||
*/
|
*/
|
||||||
object AmountBindings {
|
object AmountBindings {
|
||||||
fun <T: Any> sum(amounts: ObservableList<Amount<T>>, token: T) = EasyBind.map(
|
fun <T : Any> sum(amounts: ObservableList<Amount<T>>, token: T) = EasyBind.map(
|
||||||
Bindings.createLongBinding({
|
Bindings.createLongBinding({
|
||||||
amounts.stream().collect(Collectors.summingLong {
|
amounts.stream().collect(Collectors.summingLong {
|
||||||
require(it.token == token)
|
require(it.token == token)
|
||||||
|
@ -5,7 +5,6 @@ import javafx.collections.ListChangeListener
|
|||||||
import javafx.collections.ObservableList
|
import javafx.collections.ObservableList
|
||||||
import javafx.collections.transformation.TransformationList
|
import javafx.collections.transformation.TransformationList
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.comparisons.compareValues
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [ConcatenatedList] takes a list of lists and concatenates them. Any change to the underlying lists or the outer list
|
* [ConcatenatedList] takes a list of lists and concatenates them. Any change to the underlying lists or the outer list
|
||||||
|
@ -4,7 +4,6 @@ import javafx.collections.FXCollections
|
|||||||
import javafx.collections.MapChangeListener
|
import javafx.collections.MapChangeListener
|
||||||
import javafx.collections.ObservableList
|
import javafx.collections.ObservableList
|
||||||
import javafx.collections.ObservableMap
|
import javafx.collections.ObservableMap
|
||||||
import kotlin.comparisons.compareValues
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* [MapValuesList] takes an [ObservableMap] and returns its values as an [ObservableList].
|
* [MapValuesList] takes an [ObservableMap] and returns its values as an [ObservableList].
|
||||||
|
@ -25,8 +25,8 @@ import kotlin.test.assertTrue
|
|||||||
|
|
||||||
class CordaRPCClientTest : NodeBasedTest() {
|
class CordaRPCClientTest : NodeBasedTest() {
|
||||||
private val rpcUser = User("user1", "test", permissions = setOf(
|
private val rpcUser = User("user1", "test", permissions = setOf(
|
||||||
startFlowPermission<CashIssueFlow>(),
|
startFlowPermission<CashIssueFlow>(),
|
||||||
startFlowPermission<CashPaymentFlow>()
|
startFlowPermission<CashPaymentFlow>()
|
||||||
))
|
))
|
||||||
private lateinit var node: Node
|
private lateinit var node: Node
|
||||||
private lateinit var client: CordaRPCClient
|
private lateinit var client: CordaRPCClient
|
||||||
@ -100,8 +100,8 @@ class CordaRPCClientTest : NodeBasedTest() {
|
|||||||
assertTrue(startCash.isEmpty(), "Should not start with any cash")
|
assertTrue(startCash.isEmpty(), "Should not start with any cash")
|
||||||
|
|
||||||
val flowHandle = proxy.startFlow(::CashIssueFlow,
|
val flowHandle = proxy.startFlow(::CashIssueFlow,
|
||||||
123.DOLLARS, OpaqueBytes.of(0),
|
123.DOLLARS, OpaqueBytes.of(0),
|
||||||
node.info.legalIdentity, node.info.legalIdentity
|
node.info.legalIdentity, node.info.legalIdentity
|
||||||
)
|
)
|
||||||
println("Started issuing cash, waiting on result")
|
println("Started issuing cash, waiting on result")
|
||||||
flowHandle.progress.subscribe {
|
flowHandle.progress.subscribe {
|
||||||
|
@ -318,13 +318,13 @@ class CordaRPCClientImpl(private val session: ClientSession,
|
|||||||
* return observationsSubject
|
* return observationsSubject
|
||||||
*/
|
*/
|
||||||
private fun refCountUp() {
|
private fun refCountUp() {
|
||||||
if(referenceCount.andIncrement == 0) {
|
if (referenceCount.andIncrement == 0) {
|
||||||
hardReferencesToQueuedObservables.add(this)
|
hardReferencesToQueuedObservables.add(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun refCountDown() {
|
private fun refCountDown() {
|
||||||
if(referenceCount.decrementAndGet() == 0) {
|
if (referenceCount.decrementAndGet() == 0) {
|
||||||
hardReferencesToQueuedObservables.remove(this)
|
hardReferencesToQueuedObservables.remove(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -354,7 +354,9 @@ class CordaRPCClientImpl(private val session: ClientSession,
|
|||||||
private fun deliver(msg: ClientMessage) {
|
private fun deliver(msg: ClientMessage) {
|
||||||
sessionLock.withLock { msg.acknowledge() }
|
sessionLock.withLock { msg.acknowledge() }
|
||||||
val kryo = createRPCKryoForDeserialization(this@CordaRPCClientImpl, qName, rpcName, rpcLocation)
|
val kryo = createRPCKryoForDeserialization(this@CordaRPCClientImpl, qName, rpcName, rpcLocation)
|
||||||
val received: MarshalledObservation = try { msg.deserialize(kryo) } finally {
|
val received: MarshalledObservation = try {
|
||||||
|
msg.deserialize(kryo)
|
||||||
|
} finally {
|
||||||
releaseRPCKryoForDeserialization(kryo)
|
releaseRPCKryoForDeserialization(kryo)
|
||||||
}
|
}
|
||||||
rpcLog.debug { "<- Observable [$rpcName] <- Received $received" }
|
rpcLog.debug { "<- Observable [$rpcName] <- Received $received" }
|
||||||
|
@ -68,7 +68,7 @@ abstract class AbstractClientRPC {
|
|||||||
serverThread.shutdownNow()
|
serverThread.shutdownNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T: RPCOps> rpcProxyFor(rpcUser: User, rpcImpl: T, type: Class<T>): T {
|
fun <T : RPCOps> rpcProxyFor(rpcUser: User, rpcImpl: T, type: Class<T>): T {
|
||||||
val userService = object : RPCUserService {
|
val userService = object : RPCUserService {
|
||||||
override fun getUser(username: String): User? = if (username == rpcUser.username) rpcUser else null
|
override fun getUser(username: String): User? = if (username == rpcUser.username) rpcUser else null
|
||||||
override val users: List<User> get() = listOf(rpcUser)
|
override val users: List<User> get() = listOf(rpcUser)
|
||||||
@ -93,5 +93,8 @@ abstract class AbstractClientRPC {
|
|||||||
return CordaRPCClientImpl(clientSession, ReentrantLock(), rpcUser.username).proxyFor(type)
|
return CordaRPCClientImpl(clientSession, ReentrantLock(), rpcUser.username).proxyFor(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun safeClose(obj: Any) = try { (obj as AutoCloseable).close() } catch (e: Exception) {}
|
fun safeClose(obj: Any) = try {
|
||||||
|
(obj as AutoCloseable).close()
|
||||||
|
} catch (e: Exception) {
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,12 @@
|
|||||||
package net.corda.client.rpc
|
package net.corda.client.rpc
|
||||||
|
|
||||||
import net.corda.core.messaging.RPCOps
|
import net.corda.core.messaging.RPCOps
|
||||||
import net.corda.node.services.messaging.*
|
import net.corda.node.services.messaging.requirePermission
|
||||||
import net.corda.nodeapi.PermissionException
|
import net.corda.nodeapi.PermissionException
|
||||||
import net.corda.nodeapi.User
|
import net.corda.nodeapi.User
|
||||||
import org.junit.After
|
import org.junit.After
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import kotlin.test.*
|
import kotlin.test.assertFailsWith
|
||||||
|
|
||||||
class RPCPermissionsTest : AbstractClientRPC() {
|
class RPCPermissionsTest : AbstractClientRPC() {
|
||||||
companion object {
|
companion object {
|
||||||
@ -74,7 +74,7 @@ class RPCPermissionsTest : AbstractClientRPC() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check ALL is implemented the correct way round` () {
|
fun `check ALL is implemented the correct way round`() {
|
||||||
val joeUser = userOf("joe", setOf(DUMMY_FLOW))
|
val joeUser = userOf("joe", setOf(DUMMY_FLOW))
|
||||||
proxy = proxyFor(joeUser)
|
proxy = proxyFor(joeUser)
|
||||||
assertFailsWith(PermissionException::class,
|
assertFailsWith(PermissionException::class,
|
||||||
|
Loading…
Reference in New Issue
Block a user