I wonder if, rather than using ThreadLocals, what might be better is to
have Requestor and Responder support plugins that can manipulate the
call and response metadata. Default plugins could be statically
configured, and per-proxy plugins could be passed to
ReflectRequestor#getClient().
Doug
Doug Cutting wrote:
George Porter wrote:
If (as I expect) it is possible for a thread to have multiple
Requestors open (but Requestors could not be shared to more than one
thread), then the ThreadLocal could be a Map<Requestor, metadata>.
This way you could set per-call metadata on a per-requestor basis even
if multiple requestors are open. We could provide some static methods
as you mentioned to facilitate this.
Perhaps the ThreadLocal need not be static, but rather per-Requestor.
The setters and getters would be implicitly per-thread and explicitly
per-requestor. Could that work?
So that I understand, in this case the call format for the request
would then become:
- the message name, an avro string, followed by the message parameters
- the per-call metadata, which is a map. By default the map is null
My intuition would be to transmit the metadata before the message name
and parameters. Also, a map would always be transmitted, but it would
be empty by default. The analogy is with HTTP headers, which are
transmitted before request and response payloads. It should be easy to
implement an HTTP-based Transceiver.
and the call response would become
- a one byte error flag boolean (with either a message response or
error)
- the per-call metadata, which is a map. By default the map is null
Again, I would transmit metadata before the response data and always
transmit a map, empty by default.
Before you had mentioned that the metadata could be sent in
Transceiver.transceive. But couldn't it also be sent in
Requestor.request() (approximately at the writeRequset() call)?
Yes, if it is part of the Avro spec, it would be sent by Requestor and
Responder. If added by an application, it could be in
Transceiver#transceive().
What do people think of proceeding with Doug's recommendation of using
ThreadLocals, and including the map in the call request and response?
+1 from me.
Doug