Skip to content

Commit

Permalink
Example stat handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin committed Jan 4, 2010
1 parent 939ad25 commit 165ad4c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/mc_connection.erl
@@ -1,6 +1,7 @@
-module (mc_connection).

-export([loop/2]).
-export([respond/4]).

-include("mc_constants.hrl").

Expand Down Expand Up @@ -32,6 +33,19 @@ read_data(Socket, N, ForWhat) ->
{ok, Data} = gen_tcp:recv(Socket, N),
Data.

process_message(Socket, StorageServer, {ok, <<?REQ_MAGIC:8, ?STAT:8, KeyLen:16,
ExtraLen:8, 0:8, 0:16,
BodyLen:32,
Opaque:32,
CAS:64>>}) ->
error_logger:info_msg("Got a stat request for ~p.~n", [StorageServer]),

Extra = read_data(Socket, ExtraLen, extra),
Key = read_data(Socket, KeyLen, key),
Body = read_data(Socket, BodyLen - (KeyLen + ExtraLen), body),

% Hand the request off to the server.
gen_server:cast(StorageServer, {?STAT, Extra, Key, Body, CAS, Socket, Opaque});
process_message(Socket, StorageServer, {ok, <<?REQ_MAGIC:8, OpCode:8, KeyLen:16,
ExtraLen:8, 0:8, 0:16,
BodyLen:32,
Expand Down
13 changes: 10 additions & 3 deletions src/mc_handler_hashtable.erl
Expand Up @@ -47,9 +47,16 @@ handle_info(X, State) ->
error_logger:info_msg("Someone asked for info ~p~n", [X]),
{noreply, State}.

handle_cast(X, Locks) ->
error_logger:info_msg("Someone casted ~p~n", [X]),
{noreply, Locks}.
mk_stat(K, V) ->
#mc_response{key=K, body=V}.

handle_cast({?STAT, _Extra, _Key, _Body, _CAS, Socket, Opaque}, State) ->
error_logger:info_msg("Handling stats.", []),
% Perhaps should do something special depending on key here.
mc_connection:respond(Socket, ?STAT, Opaque, mk_stat("stat1", "val1")),
mc_connection:respond(Socket, ?STAT, Opaque, mk_stat("stat2", "val2")),
mc_connection:respond(Socket, ?STAT, Opaque, mk_stat("", "")),
{noreply, State}.

% Utility stuff

Expand Down

0 comments on commit 165ad4c

Please sign in to comment.