-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Romain Slootmaekers
committed
Jun 5, 2012
1 parent
3197e52
commit 225e4ee
Showing
8 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
true: package(lwt) | ||
true: package(arakoon) | ||
true: thread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
open Lwt | ||
open Arakoon_remote_client | ||
open Arakoon_client | ||
|
||
let make_address ip port = | ||
let ha = Unix.inet_addr_of_string ip in | ||
Unix.ADDR_INET (ha,port) | ||
|
||
let with_client cluster_id (ip,port) f = | ||
let sa = make_address ip port in | ||
let do_it connection = | ||
make_remote_client cluster_id connection >>= fun client -> | ||
f client | ||
in | ||
Lwt_io.with_connection sa do_it | ||
|
||
let find_master cluster_id cfgs = | ||
let rec loop = function | ||
| [] -> Lwt.fail (Failure "too many nodes down") | ||
| cfg :: rest -> | ||
begin | ||
let _,(ip, port) = cfg in | ||
let sa = make_address ip port in | ||
Lwt.catch | ||
(fun () -> | ||
Lwt_io.with_connection sa | ||
(fun connection -> | ||
make_remote_client cluster_id connection | ||
>>= fun client -> | ||
client # who_master ()) >>= function | ||
| None -> Lwt.fail (Failure "No Master") | ||
| Some m -> Lwt.return m) | ||
(function | ||
| Unix.Unix_error(Unix.ECONNREFUSED,_,_ ) -> loop rest | ||
| exn -> Lwt.fail exn | ||
) | ||
end | ||
in loop cfgs | ||
|
||
|
||
let with_master_client cluster_id cfgs f = | ||
find_master cluster_id cfgs >>= fun master_name -> | ||
let master_cfg = List.assoc master_name cfgs in | ||
with_client cluster_id master_cfg f | ||
|
||
|
||
let demo (client:Arakoon_client.client) = | ||
client # set "foo" "bar" >>= fun () -> | ||
client # get "foo" >>= fun v -> | ||
Lwt_io.printlf "foo=%s" v >>= fun () -> | ||
client # delete "foo" >>= fun () -> | ||
client # exists "foo" >>= fun e -> | ||
Lwt_io.printlf "have foo? %b" e | ||
|
||
let _ = | ||
let cluster_id = "ricky" in | ||
let cfgs = [ | ||
("arakoon_0",("127.0.0.1",4000)); | ||
("arakoon_1",("127.0.0.1",4001)); | ||
("arakoon_2",("127.0.0.1",4002)) | ||
] | ||
in | ||
Lwt_main.run (with_master_client cluster_id cfgs demo) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
you need an installed arakoon lib for this |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.