diff --git a/src/main/kotlin/core/ContractsDSL.kt b/src/main/kotlin/core/ContractsDSL.kt index 0225144f6e..48e66bc4f9 100644 --- a/src/main/kotlin/core/ContractsDSL.kt +++ b/src/main/kotlin/core/ContractsDSL.kt @@ -105,7 +105,8 @@ fun Iterable.sumOrZero(currency: Currency) = if (iterator().hasNext()) s //// Authenticated commands /////////////////////////////////////////////////////////////////////////////////////////// /** Filters the command list by type, party and public key all at once. */ -inline fun List>.select(signer: PublicKey? = null, party: Party? = null) = +inline fun List>.select(signer: PublicKey? = null, + party: Party? = null) = filter { it.value is T }. filter { if (signer == null) true else it.signers.contains(signer) }. filter { if (party == null) true else it.signingParties.contains(party) }. @@ -118,7 +119,8 @@ inline fun List>.requ } // For Java -fun List>.requireSingleCommand(klass: Class) = filter { klass.isInstance(it) }.single() +fun List>.requireSingleCommand(klass: Class) = + filter { klass.isInstance(it) }.single() /** Returns a timestamp that was signed by the given authority, or returns null if missing. */ fun List>.getTimestampBy(timestampingAuthority: Party): TimestampCommand? { diff --git a/src/main/kotlin/core/messaging/InMemoryNetwork.kt b/src/main/kotlin/core/messaging/InMemoryNetwork.kt index b8ebf04d3c..fd57f7ff82 100644 --- a/src/main/kotlin/core/messaging/InMemoryNetwork.kt +++ b/src/main/kotlin/core/messaging/InMemoryNetwork.kt @@ -142,7 +142,8 @@ public class InMemoryNetwork { * An instance can be obtained by creating a builder and then using the start method. */ inner class Node(private val manuallyPumped: Boolean, private val handle: Handle): MessagingService { - inner class Handler(val executor: Executor?, val topic: String, val callback: (Message, MessageHandlerRegistration) -> Unit) : MessageHandlerRegistration + inner class Handler(val executor: Executor?, val topic: String, + val callback: (Message, MessageHandlerRegistration) -> Unit) : MessageHandlerRegistration @GuardedBy("this") protected val handlers: MutableList = ArrayList() @GuardedBy("this") @@ -156,16 +157,17 @@ public class InMemoryNetwork { override val timestampingNodes = if (timestampingAdvert != null) listOf(timestampingAdvert!!) else emptyList() } - protected val backgroundThread = if (manuallyPumped) null else thread(isDaemon = true, name = "In-memory message dispatcher ") { - while (!currentThread.isInterrupted) { - try { - pumpInternal(true) - } catch(e: InterruptedException) { - if (synchronized(this) { running }) - throw e + protected val backgroundThread = if (manuallyPumped) null else + thread(isDaemon = true, name = "In-memory message dispatcher ") { + while (!currentThread.isInterrupted) { + try { + pumpInternal(true) + } catch(e: InterruptedException) { + if (synchronized(this) { running }) + throw e + } } } - } @Synchronized override fun addMessageHandler(topic: String, executor: Executor?, callback: (Message, MessageHandlerRegistration) -> Unit): MessageHandlerRegistration { @@ -264,4 +266,4 @@ public class InMemoryNetwork { return true } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/core/serialization/Kryo.kt b/src/main/kotlin/core/serialization/Kryo.kt index b267fd4b2a..49826067c4 100644 --- a/src/main/kotlin/core/serialization/Kryo.kt +++ b/src/main/kotlin/core/serialization/Kryo.kt @@ -72,8 +72,12 @@ class SerializedBytes(bits: ByteArray) : OpaqueBytes(bits) { } // Some extension functions that make deserialisation convenient and provide auto-casting of the result. -inline fun ByteArray.deserialize(kryo: Kryo = THREAD_LOCAL_KRYO.get()): T = kryo.readObject(Input(this), T::class.java) -inline fun OpaqueBytes.deserialize(kryo: Kryo = THREAD_LOCAL_KRYO.get()): T = kryo.readObject(Input(this.bits), T::class.java) +inline fun ByteArray.deserialize(kryo: Kryo = THREAD_LOCAL_KRYO.get()): T { + return kryo.readObject(Input(this), T::class.java) +} +inline fun OpaqueBytes.deserialize(kryo: Kryo = THREAD_LOCAL_KRYO.get()): T { + return kryo.readObject(Input(this.bits), T::class.java) +} inline fun SerializedBytes.deserialize(): T = bits.deserialize() /** @@ -132,7 +136,8 @@ class ImmutableClassSerializer(val klass: KClass) : Serializer() // A few quick checks for data evolution. Note that this is not guaranteed to catch every problem! But it's // good enough for a prototype. if (numFields != constructor.parameters.size) - throw KryoException("Mismatch between number of constructor parameters and number of serialised fields for ${klass.qualifiedName} ($numFields vs ${constructor.parameters.size})") + throw KryoException("Mismatch between number of constructor parameters and number of serialised fields " + + "for ${klass.qualifiedName} ($numFields vs ${constructor.parameters.size})") if (fieldTypeHash != constructor.parameters.hashCode()) throw KryoException("Hashcode mismatch for parameter types for ${klass.qualifiedName}: unsupported type evolution has happened.") @@ -195,4 +200,4 @@ fun createKryo(k: Kryo = Kryo()): Kryo { register(it.java, ImmutableClassSerializer(it)) } } -} \ No newline at end of file +}