%% %% Copyright (c) 2016 SyncFree Consortium. All Rights Reserved. %% %% This file is provided to you under the Apache License, %% Version 2.0 (the "License"); you may not use this file %% except in compliance with the License. You may obtain %% a copy of the License at %% %% http://www.apache.org/licenses/LICENSE-2.0 %% %% Unless required by applicable law or agreed to in writing, %% software distributed under the License is distributed on an %% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY %% KIND, either express or implied. See the License for the %% specific language governing permissions and limitations %% under the License. %% %% ------------------------------------------------------------------- -module(ldb_sup). -author("Vitor Enes Duarte supervisor:start_link({local, ?MODULE}, ?MODULE, []). init([]) -> BaseSpecs = configure(), Backend = {ldb_backend, {ldb_backend, start_link, []}, permanent, 5000, worker, [ldb_backend]}, Whisperer = {ldb_whisperer, {ldb_whisperer, start_link, []}, permanent, 5000, worker, [ldb_whisperer]}, Listener = {ldb_listener, {ldb_listener, start_link, []}, permanent, 5000, worker, [ldb_listener]}, ReplicationSpecs = [Backend, Whisperer, Listener], SpaceSpecs = space_specs(), Children = BaseSpecs ++ ReplicationSpecs ++ SpaceSpecs, ?LOG("ldb_sup initialized!"), RestartStrategy = {one_for_one, 5, 10}, {ok, {RestartStrategy, Children}}. %% @private configure() -> %% configure mode configure_var("LDB_MODE", ldb_mode, ?DEFAULT_MODE), %% configure join decompositions configure_var("LDB_JOIN_DECOMPOSITIONS", ldb_join_decompositions, false), %% configure metrics Metrics = configure_var("LDB_METRICS", ldb_metrics, false), BaseSpecs = case Metrics of true -> [{ldb_metrics, {ldb_metrics, start_link, []}, permanent, 5000, worker, [ldb_metrics]}]; false -> [] end, BaseSpecs. %% @private space_specs() -> %% the space server is only started if LDB_SPACE_PORT is defined case list_to_integer(os:getenv("LDB_SPACE_PORT", "-1")) of -1 -> []; SpacePort -> [{ldb_space_server, {ldb_space_server, start_link, [SpacePort]}, permanent, 5000, worker, [ldb_space_server]}] end. %% @private configure_var(Env, Var, Default) -> To = fun(V) -> atom_to_list(V) end, From = fun(V) -> list_to_atom(V) end, Current = ldb_config:get(Var, Default), Val = From( os:getenv(Env, To(Current)) ), ldb_config:set(Var, Val), Val.