Permalink
Browse files

Handling issue 2 but with no visual indication

  • Loading branch information...
1 parent 87ddcd5 commit be4c824644c70e24851dab1f71b64f0cb897cb7c Mazen Harake committed Sep 7, 2010
Showing with 72 additions and 16 deletions.
  1. +1 −1 ebin/entop.app
  2. +1 −1 src/entop.erl
  3. +4 −4 src/entop.hrl
  4. +39 −0 src/entop_net.erl
  5. +27 −10 src/entop_view.erl
View
2 ebin/entop.app
@@ -1,6 +1,6 @@
{application, entop,
[{description, "A top-like tool for monitoring an erlang node"},
{vsn, "0.0.1"},
- {modules, [entop, entop_collector, entop_format, entop_view]},
+ {modules, [entop, entop_collector, entop_format, entop_view, entop_net]},
{applications, []},
{env, []}]}.
View
2 src/entop.erl
@@ -30,7 +30,7 @@ start(Node) ->
State = #state{ node = Node },
case net_kernel:connect(Node) of
true ->
- ViewPid = entop_view:start(State),
+ ViewPid = entop_view:start(State#state{ connected = true }),
control(ViewPid);
false ->
halt(101)
View
8 src/entop.hrl
@@ -14,7 +14,7 @@
%% limitations under the License.
%%==============================================================================
%% Records
--record(state, { callback = entop_format, remote_module =
- entop_collector, columns, cbstate, node, otp_version,
- erts_version, os_fam, os, os_version, node_flags,
- interval = 1000, reverse_sort = true, sort = 1 }).
+-record(state, { callback = entop_format, remote_module = entop_collector,
+ columns, cbstate, node, otp_version, erts_version, os_fam, os,
+ os_version, node_flags, interval = 1000, reverse_sort = true,
+ sort = 1, connected = false }).
View
39 src/entop_net.erl
@@ -0,0 +1,39 @@
+%%==============================================================================
+%% Copyright 2010 Erlang Solutions Ltd.
+%%
+%% Licensed 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(entop_net).
+
+-author('mazen.harake@erlang-solutions.com').
+
+-include("entop.hrl").
+
+%% Module API
+-export([fetch_data/2, reconnect/2]).
+
+%% =============================================================================
+%% Module API
+%% =============================================================================
+fetch_data(Node, Module) ->
+ timer:tc(rpc, call, [Node, Module, get_data, []]).
+
+reconnect(Parent, Node) ->
+ case net_kernel:connect(Node) of
+ true ->
+ Parent ! {nodeup, Node};
+ false ->
+ timer:sleep(1000),
+ reconnect(Parent, Node)
+ end.
+
View
37 src/entop_view.erl
@@ -106,15 +106,21 @@ flags2str([{kpoll, true}|Rest]) ->
flags2str([_|Rest]) ->
flags2str(Rest).
+loop(Parent, #state{ connected = false } = State) ->
+ receive
+ {nodeup, Node} when Node == State#state.node ->
+ remote_load_code(State#state.remote_module, State#state.node),
+ loop(Parent, fetch_and_update(State#state{ connected = true }, false));
+ _ ->
+ loop(Parent, State)
+ end;
loop(Parent, State) ->
receive
time_update ->
- State2 = update_screen(State),
- erlang:send_after(State2#state.interval, self(), time_update),
- loop(Parent, State2);
+
+ loop(Parent, fetch_and_update(State, false));
force_update ->
- State2 = update_screen(State),
- loop(Parent, State2);
+ loop(Parent, fetch_and_update(State, true));
{sort, N} when is_integer(N) ->
State2 = update_sort_screen(State, N),
loop(Parent, State2);
@@ -125,23 +131,34 @@ loop(Parent, State) ->
end,
loop(Parent, State2);
reverse_sort ->
- State2 = update_screen(State#state{ reverse_sort = (not State#state.reverse_sort) }),
+ State2 = fetch_and_update(State#state{ reverse_sort = (not State#state.reverse_sort) }, true),
loop(Parent, State2);
{'EXIT', Parent, _} ->
ok
end.
+fetch_and_update(State, IsForced) ->
+ case entop_net:fetch_data(State#state.node, State#state.remote_module) of
+ {_Time, {badrpc, nodedown}} ->
+ erlang:spawn_link(entop_net, reconnect, [self(), State#state.node]),
+ State#state{ connected = false };
+ {Time, {ok, HeaderData, RowDataList}} ->
+ State2 = update_screen(Time, HeaderData, RowDataList, State),
+ if not IsForced -> erlang:send_after(State2#state.interval, self(), time_update);
+ true -> ok
+ end,
+ State2
+ end.
+
update_sort_screen(State, N) ->
if N >= 1 andalso N =< length(State#state.columns) ->
- update_screen(State#state{ sort = N });
+ fetch_and_update(State#state{ sort = N }, true);
true -> State
end.
-update_screen(State) ->
+update_screen(Time, HeaderData, RowDataList, State) ->
print_nodeinfo(State),
draw_title_bar(State),
- {Time, {ok, HeaderData, RowDataList}} =
- timer:tc(rpc, call, [State#state.node, State#state.remote_module, get_data, []]),
print_showinfo(State, Time),
{Headers, State1} = process_header_data(HeaderData, State),
lists:foldl(fun(Header, Y) -> cecho:mvaddstr(Y, 0, Header), Y + 1 end, 1, Headers),

0 comments on commit be4c824

Please sign in to comment.