anchor.diff: -%% @doc This is a utility module that is used to expose an arbitrary function
  -%% via an asynchronous RPC over AMQP mechanism. It frees the implementor of
  -%% a simple function from having to plumb this into AMQP. Note that the 
  -%% RPC server does not handle any data encoding, so it is up to the callback
  -%% function to marshall and unmarshall message payloads accordingly.
  +%% @doc This module implements the Smart Proxy pattern as explained here:
  +%% http://www.eaipatterns.com/SmartProxy.html
   -module(amqp_smart_proxy).
   
   -behaviour(gen_server).
  
positive.code: %% specified queue and dispatches them to a specified handler function. This
  %% function returns the pid of the RPC server that can be used to stop the
  %% server.
  start(Connection, ProxyEx, RpcExchange, Fun, Opts) ->
      {ok, Pid} = gen_server:start(?MODULE, [Connection, ProxyEx, RpcExchange, Fun], Opts),
      Pid.
  
  %% @spec (RpcServer) -> ok
  
negative.code: stats(Pid) ->
      gen_server:call(Pid, stats).
  
  clear_stats(Pid) ->
      gen_server:call(Pid, clear_stats).
  
  %%--------------------------------------------------------------------------
  %% gen_server callbacks
  %%--------------------------------------------------------------------------
  
  %% @private
  init([Connection, ProxyEx, RpcExchange, ControlExchange, Interval]) ->
      {ok, Channel} = amqp_connection:open_channel(Connection),
      
      %%setup reply queue to get messages from RPC Server.
      #'queue.declare_ok'{queue = ReplyQ} 
          = amqp_channel:call(Channel, #'queue.declare'{exclusive = true, auto_delete = true}),
      amqp_channel:subscribe(Channel, #'basic.consume'{queue = ReplyQ, no_ack = true}, self()),
      
      %%setup proxy exchange
      ExDeclare = #'exchange.declare'{exchange=ProxyEx, durable = true},
  