Просмотр исходного кода

Add '{backoff, 1000, 1000, 10000}' to return of init/1

Feng 9 лет назад
Родитель
Сommit
239cf1b5fc
2 измененных файлов с 13 добавлено и 11 удалено
  1. 9 8
      src/emqttd_bridge.erl
  2. 4 3
      src/emqttd_pubsub.erl

+ 9 - 8
src/emqttd_bridge.erl

@@ -40,16 +40,16 @@
                 qos                = ?QOS_2,
                 topic_suffix       = <<>>,
                 topic_prefix       = <<>>,
-                mqueue            :: emqttd_mqueue:mqueue(),
+                mqueue             :: emqttd_mqueue:mqueue(),
                 max_queue_len      = 10000,
                 ping_down_interval = ?PING_DOWN_INTERVAL,
                 status             = up}).
 
--type(option()  :: {qos, mqtt_qos()} |
-                   {topic_suffix, binary()} |
-                   {topic_prefix, binary()} |
-                   {max_queue_len, pos_integer()} |
-                   {ping_down_interval, pos_integer()}).
+-type(option() :: {qos, mqtt_qos()} |
+                  {topic_suffix, binary()} |
+                  {topic_prefix, binary()} |
+                  {max_queue_len, pos_integer()} |
+                  {ping_down_interval, pos_integer()}).
 
 -export_type([option/0]).
 
@@ -79,9 +79,10 @@ init([Pool, Id, Node, Topic, Options]) ->
             MQueue = emqttd_mqueue:new(qname(Node, Topic),
                                        [{max_len, State#state.max_queue_len}],
                                        emqttd_alarm:alarm_fun()),
-            {ok, State#state{pool = Pool, id = Id, mqueue = MQueue}};
+            {ok, State#state{pool = Pool, id = Id, mqueue = MQueue}, hibernate,
+             {backoff, 1000, 1000, 10000}};
         false -> 
-            {stop, {cannot_connect, Node}}
+            {stop, {cannot_connect_node, Node}}
     end.
 
 parse_opts([], State) ->

+ 4 - 3
src/emqttd_pubsub.erl

@@ -164,11 +164,12 @@ pick(Subscriber) ->
 
 init([Pool, Id, Env]) ->
     ?GPROC_POOL(join, Pool, Id),
-    {ok, #state{pool = Pool, id = Id, env = Env}}.
+    {ok, #state{pool = Pool, id = Id, env = Env}, hibernate,
+     {backoff, 2000, 2000, 20000}}.
 
 handle_call({subscribe, Topic, Subscriber, Options}, _From, State) ->
     add_subscriber(Topic, Subscriber, Options),
-    {reply, ok, setstats(State)};
+    {reply, ok, setstats(State), hibernate};
 
 handle_call({unsubscribe, Topic, Subscriber, Options}, _From, State) ->
     del_subscriber(Topic, Subscriber, Options),
@@ -179,7 +180,7 @@ handle_call(Req, _From, State) ->
 
 handle_cast({subscribe, Topic, Subscriber, Options}, State) ->
     add_subscriber(Topic, Subscriber, Options),
-    {noreply, setstats(State)};
+    {noreply, setstats(State), hibernate};
 
 handle_cast({unsubscribe, Topic, Subscriber, Options}, State) ->
     del_subscriber(Topic, Subscriber, Options),