| Source-side implementation of
SimpleRelay , which creates
the
SimpleRelayTarget on the target's blackboard.
Note that this class,
SimpleRelaySource , and the
target-side implementation,
SimpleRelayTarget , could be
easily merged into a single "SimpleRelayImpl" class. However,
in practice this tends to cause implementation bugs in similar
relays, due to aliasing and confusion over the ownership of the
instance fields. In particular, developers often incorrectly
attempt to share fields between the source and target, or allow the
source to modify the target's "reply" field or vice versa, which
leads to tricky race condition bugs. Also, note that two agents
within the same node will share (alias) the same "SimpleRelayImpl"
if the relay itself is used as the content and the factory is
either null or simply casts the content back into the
"SimpleRelayImpl". Lastly, there are known bugs for relays that
implement both source and target, specificially if they use ABA
targets or attempt to "chain" multiple relays together across many
agents. For the purposes of this example and most relay
implementations, it's best to separate the source and target relay
class implementations and not implement both APIs in a single
class.
|