gproc_bcast.erl 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. %% ``The contents of this file are subject to the Erlang Public License,
  2. %% Version 1.1, (the "License"); you may not use this file except in
  3. %% compliance with the License. You should have received a copy of the
  4. %% Erlang Public License along with this software. If not, it can be
  5. %% retrieved via the world wide web at http://www.erlang.org/.
  6. %%
  7. %% Software distributed under the License is distributed on an "AS IS"
  8. %% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  9. %% the License for the specific language governing rights and limitations
  10. %% under the License.
  11. %%
  12. %% The Initial Developer of the Original Code is Ericsson Utvecklings AB.
  13. %% Portions created by Ericsson are Copyright 1999, Ericsson Utvecklings
  14. %% AB. All Rights Reserved.''
  15. %%
  16. %% @author Ulf Wiger <ulf@wiger.net>
  17. %%
  18. %% @doc Gproc message broadcast server
  19. %% This module is used to support gproc:bcast(Key, Msg).
  20. %%
  21. %% gproc:bcast/2 allows for e.g. distributed publish/subscribe, without
  22. %% having to resort to global property registration.
  23. %% To ensure that erlang's message ordering guarantees are kept, all sends
  24. %% are channeled through a broadcast server on each node.
  25. %% @end
  26. -module(gproc_bcast).
  27. -behaviour(gen_server).
  28. -export([start_link/0,
  29. init/1,
  30. handle_cast/2,
  31. handle_call/3,
  32. handle_info/2,
  33. terminate/2,
  34. code_change/3]).
  35. -include("gproc_int.hrl").
  36. start_link() ->
  37. gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
  38. init([]) ->
  39. {ok, []}.
  40. handle_call(_, _, S) ->
  41. {reply, {error, unknown_call}, S}.
  42. handle_cast({send, Key, Msg}, S) ->
  43. ?MAY_FAIL(gproc:send(Key, Msg)),
  44. {noreply, S};
  45. handle_cast(_, S) ->
  46. {noreply, S}.
  47. handle_info(_, S) ->
  48. {noreply, S}.
  49. terminate(_, _) ->
  50. ok.
  51. code_change(_, S, _) ->
  52. {ok, S}.