Skip to content
Browse files

make remote hashes work

  • Loading branch information...
1 parent e2268ec commit 97a89ea844d3aa61714fa135dfa990bab33c3896 @cloudshift committed
Showing with 53 additions and 15 deletions.
  1. +7 −1 cloudshift/Data.hx
  2. +29 −8 cloudshift/data/RemoteSqlite3Client.hx
  3. +11 −3 usage/data/RemoteClient.hx
  4. +6 −3 usage/data/RemoteSource.hx
View
8 cloudshift/Data.hx
@@ -6,6 +6,7 @@ import cloudshift.Core;
import cloudshift.Http;
import cloudshift.Remote;
import cloudshift.data.RemoteBucketProxy;
+import cloudshift.data.RemoteHashProxy;
typedef Serializer = {
var serialize:Dynamic->String;
@@ -71,11 +72,16 @@ class Data {
return p;
}
- public static function serve<T>(http:HttpServer,bucket:Bucket<T>,url:String) {
+ public static function serveBucket<T>(http:HttpServer,bucket:Bucket<T>,url:String) {
var rem = Remote.provider("Store",new RemoteBucketProxy(bucket));
http.handler(new EReg(url,""),rem.httpHandler);
}
+ public static function serveHash<T>(http:HttpServer,hash:BHash<T>,url:String) {
+ var rem = Remote.provider("Hash",new RemoteHashProxy(hash));
+ http.handler(new EReg(url,""),rem.httpHandler);
+ }
+
public static function jsonSerializer():Serializer {
return { serialize:Core.stringify,deSerialize:Core.parse};
}
View
37 cloudshift/data/RemoteSqlite3Client.hx
@@ -10,27 +10,27 @@ import cloudshift.Data;
using cloudshift.Mixin;
private class BucketProxy extends haxe.remoting.AsyncProxy<cloudshift.data.RemoteBucketProxy> { }
+private class HashProxy extends haxe.remoting.AsyncProxy<cloudshift.data.RemoteHashProxy> { }
class RemoteSqlite3Client implements Store {
var _url:String;
var _ready:Outcome<String,Store>;
- var _proxy:BucketProxy;
public function new(ready:Outcome<String,Store>,url:String) {
- _url = url;
+ _url = (url.endsWith("/")) ? url : url + "/" ;
_ready = ready;
ready.resolve(Right(cast this));
}
public function bucket<T>(bucketName:String,?serialize:Serializer):Outcome<String,Bucket<T>> {
var p = Core.outcome();
- new RemoteBucket(p,bucketName,_url);
+ new RemoteBucket(p,bucketName,_url+bucketName);
return p;
}
- public function hash<T>(bucketName:String,?serialize:Serializer):Outcome<String,BHash<T>> {
+ public function hash<T>(hashName:String,?serialize:Serializer):Outcome<String,BHash<T>> {
var prm = Core.outcome();
- new RemoteHash(prm,bucketName,_proxy);
+ new RemoteHash(prm,hashName,_url+hashName);
return prm;
}
@@ -167,35 +167,56 @@ private class RemoteHash<T> implements BHash<T> {
var _ready:Outcome<String,BHash<T>>;
var _name:String;
- var _proxy:BucketProxy;
+ var _proxy:HashProxy;
- public function new(ready:Outcome<String,BHash<T>>,name:String,proxy:BucketProxy) {
+ public function new(ready:Outcome<String,BHash<T>>,name:String,url:String) {
_ready = ready;
_name = name;
- _proxy = proxy;
+
+ var cnx = haxe.remoting.HttpAsyncConnection.urlConnect(url);
+ cnx.setErrorHandler( function(err) Core.error(Std.string(err)) );
+ _proxy = new HashProxy(cnx.Hash);
+ var forTyper:BHash<T> = this;
+ ready.resolve(Right(forTyper));
}
+
public function get(key:String):Outcome<String,T> {
var prm = Core.outcome();
+ _proxy.get(key,function(either) {
+ prm.resolve(either);
+ });
return prm;
}
public function set(key:String,val:T):Outcome<String,T> {
var prm = Core.outcome();
+ _proxy.set(key,val,function(either) {
+ prm.resolve(either);
+ });
return prm;
}
public function remove(key:String):Outcome<String,String> {
var prm = Core.outcome();
+ _proxy.remove(key,function(either) {
+ prm.resolve(either);
+ });
return prm;
}
public function keys(?like:String):Outcome<String,Array<String>> {
var prm = Core.outcome();
+ _proxy.keys(like,function(either) {
+ prm.resolve(either);
+ });
return prm;
}
public function values(?like:String):Outcome<String,Array<T>> {
var prm = Core.outcome();
+ _proxy.keys(like,function(either) {
+ prm.resolve(cast either);
+ });
return prm;
}
View
14 usage/data/RemoteClient.hx
@@ -8,7 +8,7 @@ using cloudshift.Mixin;
class RemoteClient {
public static function main(){
- Data.store(REMOTESQLITE("http://localhost:8082/data/woot")).deliver(function(store) {
+ Data.store(REMOTESQLITE("http://localhost:8082/data")).deliver(function(store) {
store.bucket("woot").deliver(function(woot) {
woot.where('name="lore"').deliver(function(recs) {
@@ -20,8 +20,16 @@ class RemoteClient {
trace("lore's id = "+Data.oid(u));
});
});
- });
+ store.hash("peeps").deliver(function(peeps) {
+ peeps.set("me",{email:"lorena@ritchie.com",name:"lore",passwd:"and why not"})
+ .deliver(function(p) {
+ peeps.get("me").deliver(function(me) {
+ if (me.name == "lore")
+ trace("yep got it");
+ });
+ });
+ });
+ });
}
-
}
View
9 usage/data/RemoteSource.hx
@@ -8,14 +8,17 @@ using cloudshift.Mixin;
class RemoteSource {
public static function main(){
- Http.server().root("www").start({host:"localhost",port:8082}).deliver(function(server) {
+ Http.server().root("www").start({host:"localhost",port:8082}).deliver(function(http) {
Data.store(SQLITE("test.db")).deliver(function(store) {
store.bucket("woot").deliver(function(woot) {
woot.indexer("name",function(o:Dynamic) {
return o.name;
}).deliver(function(el) {
- Data.serve(server,woot,"/data/woot");
- });
+ Data.serveBucket(http,woot,"/data/woot");
+ });
+ });
+ store.hash("peeps").deliver(function(peeps) {
+ Data.serveHash(http,peeps,"/data/peeps");
});
});
});

0 comments on commit 97a89ea

Please sign in to comment.
Something went wrong with that request. Please try again.