Connection Multiplexing
Assumptions:
- This is a Request/Reply protocol
- Each Request/Reply type is serialized as a message object
that contains header and body.
ConnectionMultiplexer
- sends the Request object's message
- whenever it receives the response related to this
message, then it informs the Request object with the
suitablestream to read the message body.
Note that Message object has two responsibility
- it has an identifier
- it can tell the size of its body.
- what happens if the Request object is waiting and
then is no response?
- Request object might be only one way and it does not
need a response.
- CM throws away the reply when there is nobody willing
to listen.
Request==CM
- service(Request,MessageIdentifier)
- write(Stream)
- handleReply(MessageHeader,StreamForMessageBody)
Request==CM
- service(Request)
- write(Stream)
ConnectionMultiplexer
- keeps a connection to the given address.
- a number of threads to handle the outgoing messages.
- a number of threads to handle the incoming replies.
- CM is an active object.
- When CM receives a service() message, it puts the
request object to the outbound queue.
- A thread process a request in the outbound queue
and it takes a thread from the pool and let it handle
the request.
This also requires that a socket is also available.
- Each socket's input is swept by a thread and the
result is moved to inbound queue where each reply
is properly handled.
- Inbound queue is also an active object that takes
the reply object and the package read from the stream.
Note that it encapsulates the Message Header and the body.
Message Header is already read from the wire but the
Message body still waits to be interpreted. Therefore
this object first checks whether the incoming reply
has a receiver. If not, then discards the message.
If it has a receiver waiting for the reply then it takes
a thread from the pool and let the do the upcall.