Permalink
Browse files

reformated

  • Loading branch information...
leonlee committed Feb 9, 2014
1 parent ecce7ba commit c8d762551c0471a470fd4e20a680ae3d8be032da
@@ -1,16 +1,16 @@
{application, flake,
- [
- {description, "flake"},
- {vsn, "0.7"},
- {modules, []},
- {registered, []},
- {applications, [
- kernel,
- stdlib,
- sasl,
- inets,
- crypto
- ]},
- {mod, {flake_app, []}},
- {env, [{cfg_node, 'cfg_node@localhost'}]}
- ]}.
+ [
+ {description, "flake"},
+ {vsn, "0.7"},
+ {modules, []},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib,
+ sasl,
+ inets,
+ crypto
+ ]},
+ {mod, {flake_app, []}},
+ {env, [{cfg_node, 'cfg_node@localhost'}]}
+ ]}.
View
@@ -33,13 +33,13 @@
%% @spec start() -> ok
%% @doc Start the snowflake server.
start() ->
- appstart:start(flake, permanent).
+ appstart:start(flake, permanent).
%% @spec stop() -> ok
%% @doc Stop the snowflake server.
stop() ->
- Res = application:stop(flake),
- Res.
+ Res = application:stop(flake),
+ Res.
get_config_id() ->
- "flake." ++ atom_to_list(node()).
+ "flake." ++ atom_to_list(node()).
View
@@ -5,11 +5,11 @@
-define(LOG_ERROR_FORMAT(F, A), _ = [F, A]).
-else.
-define(LOG_INFO(F),
- error_logger:info_msg(F)).
+ error_logger:info_msg(F)).
-define(LOG_ERROR(F),
- error_logger:error_msg(F)).
+ error_logger:error_msg(F)).
-define(LOG_INFO_FORMAT(F, A),
- error_logger:info_msg(F, A)).
+ error_logger:info_msg(F, A)).
-define(LOG_ERROR_FORMAT(F, A),
- error_logger:error_msg(F, A)).
+ error_logger:error_msg(F, A)).
-endif.
@@ -22,19 +22,19 @@
-behaviour(application).
-export([
- start/2,
- stop/1
+ start/2,
+ stop/1
]).
-include_lib("eunit/include/eunit.hrl").
%% @spec start(_Type, _StartArgs) -> ServerRet
%% @doc application start callback for snowflake.
start(_Type, _StartArgs) ->
- ok = xor_util:connect_cfg_node(flake, cfg_node),
- flake_sup:start_link().
+ ok = xor_util:connect_cfg_node(flake, cfg_node),
+ flake_sup:start_link().
%% @spec stop(_State) -> ServerRet
%% @doc application stop callback for snowflake.
stop(_State) ->
- ok.
+ ok.
@@ -14,37 +14,37 @@
%%% limitations under the License.
%%%
--module (flake_harness).
--author ('Dietrich Featherston <d@boundary.com>').
+-module(flake_harness).
+-author('Dietrich Featherston <d@boundary.com>').
--export ([
- generate/1,
- generate/2,
- timed_generate/1,
- timed_generate/2
- ]).
+-export([
+ generate/1,
+ generate/2,
+ timed_generate/1,
+ timed_generate/2
+]).
-include_lib("eunit/include/eunit.hrl").
generate(N) ->
- generate_ids(N, undefined, []).
+ generate_ids(N, undefined, []).
timed_generate(N) ->
- ?debugTime("generating ids", generate(N)).
+ ?debugTime("generating ids", generate(N)).
generate(N, Base) ->
- generate_ids(N, Base, []).
+ generate_ids(N, Base, []).
timed_generate(N, Base) ->
- ?debugTime("generating ids", generate(N, Base)).
+ ?debugTime("generating ids", generate(N, Base)).
generate_ids(0, _Base, Acc) ->
- Acc;
+ Acc;
generate_ids(N, Base, Acc) ->
- {ok, Flake} = case Base of
- undefined ->
- flake_server:id();
- _ ->
- flake_server:id(Base)
- end,
- generate_ids(N-1, Base, [Flake|Acc]).
+ {ok, Flake} = case Base of
+ undefined ->
+ flake_server:id();
+ _ ->
+ flake_server:id(Base)
+ end,
+ generate_ids(N - 1, Base, [Flake | Acc]).
@@ -21,19 +21,19 @@
%% API
-export([
- start_link/1,
- id/0,
- id/1,
- id_in/2, id_in/1]).
+ start_link/1,
+ id/0,
+ id/1,
+ id_in/2, id_in/1]).
%% gen_server callbacks
-export([
- init/1,
- handle_call/3,
- handle_cast/2,
- handle_info/2,
- terminate/2,
- code_change/3
+ init/1,
+ handle_call/3,
+ handle_cast/2,
+ handle_info/2,
+ terminate/2,
+ code_change/3
]).
-include_lib("eunit/include/eunit.hrl").
@@ -46,50 +46,50 @@
% start and link to a new flake id generator
start_link(Config) ->
- Name = xor_pl:read(name, Config),
- gen_server:start_link({local, Name}, ?MODULE, Config, []).
+ Name = xor_pl:read(name, Config),
+ gen_server:start_link({local, Name}, ?MODULE, Config, []).
% generate a new snowflake id
id() ->
- id(0).
+ id(0).
id(ZoneId) ->
- respond(gen_server:call(flake, {get, ZoneId})).
+ respond(gen_server:call(flake, {get, ZoneId})).
id_in(Base) ->
- id_in(0, Base).
+ id_in(0, Base).
id_in(ZoneId, Base) ->
- respond(gen_server:call(flake, {get, ZoneId, Base})).
+ respond(gen_server:call(flake, {get, ZoneId, Base})).
respond({ok, Flake}) ->
- {ok, Flake};
+ {ok, Flake};
respond(X) ->
- X.
+ X.
%% ----------------------------------------------------------
%% gen_server callbacks
%% ----------------------------------------------------------
init(Config) ->
- WorkerId = xor_pl:read(worker_id, Config),
- {ok, #state{max_time = flake_util:curr_time_millis(), worker_id = WorkerId, sequence = 0}}.
+ WorkerId = xor_pl:read(worker_id, Config),
+ {ok, #state{max_time = flake_util:curr_time_millis(), worker_id = WorkerId, sequence = 0}}.
handle_call({get, ZoneId}, _From, State = #state{max_time = MaxTime, worker_id = WorkerId, sequence = Sequence}) ->
- {Resp, S0} = get(flake_util:curr_time_millis(), MaxTime, ZoneId, WorkerId, Sequence, State),
- {reply, Resp, S0};
+ {Resp, S0} = get(flake_util:curr_time_millis(), MaxTime, ZoneId, WorkerId, Sequence, State),
+ {reply, Resp, S0};
handle_call({get, ZoneId, Base}, _From,
- State = #state{max_time = MaxTime, worker_id = WorkerId, sequence = Sequence}) ->
- {Resp, S0} = get(flake_util:curr_time_millis(), MaxTime, ZoneId, WorkerId, Sequence, State),
- case Resp of
- {ok, Id} ->
- {reply, {ok, xor_util:to_base(Id, Base)}, S0};
- E ->
- {reply, E, S0}
- end;
+ State = #state{max_time = MaxTime, worker_id = WorkerId, sequence = Sequence}) ->
+ {Resp, S0} = get(flake_util:curr_time_millis(), MaxTime, ZoneId, WorkerId, Sequence, State),
+ case Resp of
+ {ok, Id} ->
+ {reply, {ok, xor_util:to_base(Id, Base)}, S0};
+ E ->
+ {reply, E, S0}
+ end;
handle_call(X, _From, State) ->
- error_logger:error_msg("unrecognized msg in ~p:handle_call -> ~p~n", [?MODULE, X]),
- {reply, ok, State}.
+ error_logger:error_msg("unrecognized msg in ~p:handle_call -> ~p~n", [?MODULE, X]),
+ {reply, ok, State}.
handle_cast(_, State) -> {noreply, State}.
@@ -101,11 +101,11 @@ code_change(_, State, _) -> {ok, State}.
%% clock hasn't moved, increment sequence
get(Time, Time, ZoneId, WorkerId, Seq0, State) ->
- Sequence = Seq0 + 1,
- {{ok, flake_util:gen_id(Time, ZoneId, WorkerId, Sequence)}, State#state{sequence = Sequence}};
+ Sequence = Seq0 + 1,
+ {{ok, flake_util:gen_id(Time, ZoneId, WorkerId, Sequence)}, State#state{sequence = Sequence}};
%% clock has progressed, reset sequence
get(CurrTime, MaxTime, ZoneId, WorkerId, _, State) when CurrTime > MaxTime ->
- {{ok, flake_util:gen_id(CurrTime, ZoneId, WorkerId, 0)}, State#state{max_time = CurrTime, sequence = 0}};
+ {{ok, flake_util:gen_id(CurrTime, ZoneId, WorkerId, 0)}, State#state{max_time = CurrTime, sequence = 0}};
%% clock is running backwards
get(CurrTime, MaxTime, _ZoneId, _WorkerId, _Sequence, State) when MaxTime > CurrTime ->
- {{error, clock_running_backwards}, State}.
+ {{error, clock_running_backwards}, State}.
Oops, something went wrong.

0 comments on commit c8d7625

Please sign in to comment.