anchor.diff:  %    end,
   %    {noreply, State#state{pid_exchange_user_list_sub=NewPeul, refs_sub=NewRefs}}.
   %
  -%terminate(_Reason, _State) ->
  -%    ok.
  +terminate(_Reason, _State) ->
  +    ok.
  +
  +code_change(_OldVsn, State, _Extra) ->
  +    {ok, State}.
  +
  +presence(ExchangeName) ->
  +    gen_server:call(?MODULE, {presence, ExchangeName}).
   %
  -%code_change(_OldVsn, State, _Extra) ->
  -%    {ok, State}.
  -%
  -%presence(ExchangeName) ->
  -%    gen_server:call(?MODULE, {presence, ExchangeName}).
  -%
  -%get_exchanges(UserId) ->
  -%    gen_server:call(?MODULE, {get_exchanges, UserId}).
  +get_exchanges(UserId) ->
  +    gen_server:call(?MODULE, {get_exchanges, UserId}).
  
positive.code: 
  -export([start_link/0]).
  -export([stop/1]).
  %-export([presence/1, get_exchanges/1]).
  -export([init/1, terminate/2, code_change/3, handle_call/3,
           handle_cast/2, handle_info/2]).
  
  -record(state, {pid_exchange_user_list_pub, refs_pub, pid_exchange_user_list_sub, refs_sub}).
  -record(subscriber, {{node, pid}, exchange_name, user_id}).
  -record(publisher, {{node, pid}, exchange_name, user_id}).
  
  
  start_link() ->
  
negative.code:     {ok, State}.
  
  
  handle_info({'DOWN', _Ref, process, Pid, _}, State=#state{refs_pub=Refs, refs_sub=RefsSub}) ->
      NewRefs = case dict:find(Pid, Refs) of
                    error -> Refs;
                    {ok, Ref} -> erlang:demonitor(Ref, [flush]),
                                 dict:erase(Pid)
                end,
  
      mnesia:delete(publishers, #publisher{pid=Pid}),
      NewRefsSub = case dict:find(Pid, RefsSub) of
                    error -> Refs;
                       {ok, RefSub} -> erlang:demonitor(RefSub, [flush]),
                                       dict:erase(Pid)
                end,
  
      mnesia:delete(subscribers, #publisher{pid=Pid}),
  
      {noreply, State#state{refs_pub=NewRefs, refs_sub=NewRefsSub}};
  
  handle_info(shutdown, State) ->
      {stop, shutdown, State}.
  
  handle_call({presence, ExchangeName}, _From, State) ->
      PatternPub = #publisher{_ = '_', exchange_name = ExchangeName},
      F = fun() ->
                  Res = mnesia:match_object(PatternPub),
                  [UserId || #publisher{user_id=UserId} <- Res]
          end,
      UsersDupPub =mnesia:activity(transaction, F),
      UsersPub = sets:to_list(sets:from_list(UsersDupPub)),
      PatternSub = #subscriber{_ = '_', exchange_name = ExchangeName},
      FSub = fun() ->
                  Res = mnesia:match_object(PatternSub),
                  [UserId || #subscriber{user_id=UserId} <- Res]
          end,
      UsersDupSub =mnesia:activity(transaction, FSub),
      UsersSub = sets:to_list(sets:from_list(UsersDupSub)),
  
      {reply, {UsersPub, UsersSub}, State};
  
  handle_call({get_exchanges, UserId}, _From, State) ->
      PatternPub = #publisher{_ = '_', user_id = UserId},
      F = fun() ->
                  Res = mnesia:match_object(PatternPub),
                  [ExchangeName || #publisher{exchange_name=ExchangeName} <- Res]
          end,
      ExchangesDupPub =mnesia:activity(transaction, F),
      ExchangesPub = sets:to_list(sets:from_list(ExchangesDupPub)),
      PatternSub = #subscriber{_ = '_', user_id = UserId},
      FSub = fun() ->
                  Res = mnesia:match_object(PatternSub),
                  [ExchangeName || #subscriber{exchange_name=ExchangeName} <- Res]
          end,
      ExchangesDupSub =mnesia:activity(transaction, FSub),
      ExchangesSub = sets:to_list(sets:from_list(ExchangesDupSub)),
      {reply, {ExchangesPub, ExchangesSub}, State}.
   
  handle_cast({join_exchange, UserId, ExchangeName, From}, State=#state{refs_pub=Refs}) ->
      Ref = erlang:monitor(process, From),
      NewRefs = dict:store(From, Ref, Refs),
      F = fun() ->
                  mnesia:write(#publisher{ pid=From,
                                          exchange_name=ExchangeName,
                                          user_id=UserId})
          end,
      mnesia:activity(transaction, F),
      {noreply, State#state{refs_pub=NewRefs}};
  
  handle_cast({leave_exchange, UserId, ExchangeName, From}, State=#state{refs_pub=Refs}) ->
      mnesia:delete(publishers, #publisher{pid=From,
                                                     exchange_name=ExchangeName,
                                                     user_id=UserId}),
      NewRefs = case dict:find(From, Refs) of
          error -> Refs;
          {ok, Ref} -> erlang:demonitor(Ref, [flush]),
                       dict:erase(From, Refs)
      end,
      {noreply, State#state{refs_pub=NewRefs}}.
  
  %handle_cast({subscribe_exchange, UserId, ExchangeName, From}, State=#state{pid_exchange_user_list_sub=Peul, refs_sub=Refs}) ->
  %    Ref = erlang:monitor(process, From),
  %    NewRefs = dict:store(From, Ref, Refs),
  