anchor.diff:  %%% Author  : Todd Lipcon <todd@amiestreet.com>
   %%% Description : Write-only Thrift transport outputting to disk_log
   %%% Created : 22 Apr 2008 by Todd Lipcon <todd@lipcon.org>
  +%%%
  +%%% Todo: this might be better off as a gen_server type of transport
  +%%%       that handles stuff like group commit, similar to TFileTransport
  +%%%       in cpp land
   %%%-------------------------------------------------------------------
   -module(thrift_disk_log_transport).
   
   -behaviour(thrift_transport).
   
   %% API
  --export([new/2, new_transport_factory/2]).
  +-export([new/2, new_transport_factory/2, new_transport_factory/3]).
   
   %% thrift_transport callbacks
  --export([read/2, write/2, flush/1, close/1]).
  +-export([read/2, write/2, force_flush/1, flush/1, close/1]).
   
   %% state
   -record(dl_transport, {log,
  
positive.code: %% when the transport is closed, pass a {close_on_close, true} tuple in the
  %% Opts list.
  new(LogName, Opts) when is_atom(LogName), is_list(Opts) ->
      State = #dl_transport{log = LogName},
  
      State2 =
          case State#dl_transport.sync_every of
              N when is_integer(N), N > 0 ->
                  {ok, TRef} = timer:apply_interval(N, ?MODULE, flush, State),
                  State#dl_transport{sync_tref = TRef};
              _ -> State
          end,
  
      thrift_transport:new(?MODULE, parse_opts(Opts, State2)).
  
  
  parse_opts([], State) ->
  
negative.code: write(#dl_transport{log = Log}, Data) ->
      disk_log:balog(Log, erlang:iolist_to_binary(Data)).
  
  force_flush(#dl_transport{log = Log}) ->
      error_logger:info_msg("~p syncing~n", [?MODULE]),
      disk_log:sync(Log).
  
  flush(#dl_transport{log = Log, sync_every = SE}) ->
      case SE of
          undefined -> % no time-based sync
              disk_log:sync(Log);
          _Else ->     % sync will happen automagically
              ok
      end.
  
  
  %% On close, close the underlying log if we're configured to do so.
  close(#dl_transport{close_on_close = false}) ->
  