com.r3corda.node.services.network / InMemoryMessagingNetwork / InMemoryMessaging

# InMemoryMessaging

`inner class InMemoryMessaging : SingletonSerializeAsToken, MessagingServiceInternal`

An InMemoryMessaging provides a MessagingService that isnt backed by any kind of network or disk storage system, but just uses regular queues on the heap instead. It is intended for unit testing and developer convenience when all entities on the network are being simulated in-process.

An instance can be obtained by creating a builder and then using the start method.

### Types

Handler | `inner class Handler : MessageHandlerRegistration`

### Constructors

<init> | `InMemoryMessaging(manuallyPumped: Boolean, handle: Handle)` An InMemoryMessaging provides a MessagingService that isnt backed by any kind of network or disk storage system, but just uses regular queues on the heap instead. It is intended for unit testing and developer convenience when all entities on the network are being simulated in-process.

### Properties

myAddress | `val myAddress: SingleMessageRecipient` Returns an address that refers to this node.

### Functions

addMessageHandler | `fun addMessageHandler(topic: String, sessionID: Long, executor: Executor?, callback: (Message, MessageHandlerRegistration) -> Unit): MessageHandlerRegistration` The provided function will be invoked for each received message whose topic matches the given string, on the given executor. `fun addMessageHandler(topicSession: TopicSession, executor: Executor?, callback: (Message, MessageHandlerRegistration) -> Unit): MessageHandlerRegistration` The provided function will be invoked for each received message whose topic and session matches, on the given executor.
createMessage | `fun createMessage(topic: String, sessionID: Long, data: ByteArray): Message` `fun createMessage(topicSession: TopicSession, data: ByteArray): Message` Returns the given (topic & session, data) pair as a newly created message object.
pumpReceive | `fun pumpReceive(block: Boolean): MessageTransfer?` Delivers a single message from the internal queue. If there are no messages waiting to be delivered and block is true, waits until one has been provided on a different thread via send. If block is false, the return result indicates whether a message was delivered or not.
removeMessageHandler | `fun removeMessageHandler(registration: MessageHandlerRegistration): Unit` Removes a handler given the object returned from addMessageHandler. The callback will no longer be invoked once this method has returned, although executions that are currently in flight will not be interrupted.
send | `fun send(message: Message, target: MessageRecipients): Unit` Sends a message to the given receiver. The details of how receivers are identified is up to the messaging implementation: the type system provides an opaque high level view, with more fine grained control being available via type casting. Once this function returns the message is queued for delivery but not necessarily delivered: if the recipients are offline then the message could be queued hours or days later.
stop | `fun stop(): Unit` Initiates shutdown: if called from a thread that isnt controlled by the executor passed to the constructor then this will block until all in-flight messages have finished being handled and acknowledged. If called from a thread thats a part of the AffinityExecutor given to the constructor, it returns immediately and shutdown is asynchronous.

### Inherited Functions

toToken | `open fun toToken(context: SerializeAsTokenContext): SerializationToken`