otp

Erlang/OTP How to notify parent process that child processes are idle and no messages in their mailbox

为君一笑 提交于 2019-12-08 14:00:01
问题 I would like to design a process hierarchy where there is a a parent process P which acts like a gatekeeper and delegates the work(messages/events from its client processes) to it's children processes C1,C2..Cn which collaborate with each other and may send the result back to P. The children processes cannot talk to any process outside, only P. The challenge is that though P may have multiple messages from its clients, it should accept only one message, delegate the work to C1..Cn and ONLY

Is handle_info guaranteed to be executed immediately after init with timeout 0?

Deadly 提交于 2019-12-07 12:39:19
问题 I am getting a strange error report that makes me think some calls are being executed before the gen_server initialization. Here is the init code: init([ResourceId]) -> process_flag(trap_exit, true), {ok, {not_initialized, ResourceId}, 0}. Here is the handle_info that should initialize the resource. handle_info(timeout, {not_initialized, ResourceId}) -> Resource = data_store:get_resource(ResourceId), {noreply, Resource, ?CACHE_TIMEOUT}; the return value of data_store:get_resource(ResourceId)

Erlang - Starting a child from the supervisor module

白昼怎懂夜的黑 提交于 2019-12-07 08:17:15
问题 I'm trying to create a supervisor which handles adding dynamic gen_servers. for a reason something is failing and I'm not really sure what. -module(supervisor_mod). -behaviour(supervisor). -export([start_link/0, add_child/1]). -export([init/1]). start_link() -> Pid=supervisor:start_link({local, ?MODULE} , ?MODULE, []), {ok,Pid}. init(_Args) -> {ok, {{simple_one_for_one, 10, 60}, [{example_proc, {example_proc, start_link, []}, permanent, brutal_kill, worker, [example_proc]}]}}. add_child(Name)

Will data in gen_server be kept after restarted by its supervisor?

孤街浪徒 提交于 2019-12-07 04:21:49
问题 I have a supervisor which starts many gen_server. Each gen_server has a lot of data load which takes a lot of time. I want to know when error happens, will the data stored in gen_server's state and its process dict be kept for next start so I don't need to init them again? 回答1: The current state of an Erlang behavior is not saved anywhere. You would have to take care of that yourself. Either you save the state regurlarly somewhere externally (in another process, in an ETS table, a database

Why Supervisor.start_child dont work

筅森魡賤 提交于 2019-12-07 00:18:24
I'm beginner in Elixir. I have one application that initiate one custom supervisor in application.ex. Code: defmodule MyApp do use Application def start(_type, _args) do import Supervisor.Spec children = [ supervisor(MyApp.Web.Endpoint, []), supervisor(MyApp.Repo, []), #my notifier MyApp.MyNotifier.Supervisor ] opts = [strategy: :one_for_one, name: MyApp.Supervisor] Supervisor.start_link(children, opts) end end And the code of supervisor is something like this: defmodule MyApp.MyNotifier.Supervisor do use Supervisor def start_link(_options), do: Supervisor.start_link(__MODULE__, :ok, name: _

Proper Elixir OTP way to structure a recurring task

拥有回忆 提交于 2019-12-06 18:19:57
问题 I've got a workflow that involves waking up every 30 seconds or so and polling a database for updates, taking action on that, then going back to sleep. Setting aside that database polling doesn't scale and other similar concerns, what is the best way to structure this workflow using Supervisors, workers, Tasks, and so forth? I'll lay out a few ideas I've had and my thoughts for/against. Please help me figure out the most Elixir-y approach. (I'm still very new to Elixir, btw.) 1. Infinite Loop

extending ejabberd with modules for custom mysql schema?

…衆ロ難τιáo~ 提交于 2019-12-06 07:52:55
Instead of ejabberd.sql ,I am using a custom MySQL schema(because of legacy reasons). I will be doing some DB operations on certain activities like Ping,Pong,Msg deliverd,Msg read and most importantly getting/setting roster list and announcing presence(all of these on my own schema). However,ejabberd seems to use ejabberd.sql all throughout and its source code is pretty much dependent on it.Fiddling with the source code is the last thing I would do since I am not aware of its dependencies. Possible ideas : Lets say if I extend ejabberd by writing my own modules,then what use will mod_roster

When to use erlang application:start or included_applications and a supervisor?

。_饼干妹妹 提交于 2019-12-06 04:50:42
问题 I have an Erlang application which has a dependency in its deps directory on another application. From what I understand I can either; a) start my dependent application from my including application by calling application:start(some_other_app) which starts the application and shows it running standalone within Observer. b) include my dependent application in my .app file with {included_applications, [some_other_app]} so that the application is loaded and not started and then start the

ERROR: Could not find 'wxe_driver.so'

…衆ロ難τιáo~ 提交于 2019-12-06 04:32:34
问题 I got this error on my ubuntu when I run debugger:start(). Erlang R14B02 (erts-5.8.3) [source] [smp:4:4] [rq:4] [async-threads:0] [kernel-poll:false] Eshell V5.8.3 (abort with ^G) 1> debugger:start(). =ERROR REPORT==== 14-Feb-2012::17:57:27 === ERROR: Could not find 'wxe_driver.so' in: /usr/local/lib/erlang/lib/wx-0.98.9/priv {ok,<0.36.0>} I want to know how to fix the error in order to use debugger ? 回答1: Are you running the default erlang running on ubuntu? Unfortunately there is no longer

Why does io:format support ~n when \n does the same thing?

别说谁变了你拦得住时间么 提交于 2019-12-06 01:04:12
问题 These two give identical output: 1> io:format("Hello, world!~n"). Hello, world! ok 2> io:format("Hello, world!\n"). Hello, world! ok Why does io:format support ~n when \n does the same thing? Are there any differences? 回答1: According to "Programming Erlang", ~n outputs the platform-specific new line sequence ( \n on Unix, \r\n on Windows, etc.). I think \n just writes the \n character, but am not sure. 回答2: According to io document, The general format of a control sequence is ~F.P.PadModC .