Permalink
Browse files

[cleanup] stdlib: Tidied up Cell code. Temporarily removed @abstract.

  • Loading branch information...
1 parent 9ba16ba commit b7e97b4520d2f3c7409bef2f8ab515ce75096a94 @nrs135 nrs135 committed Nov 10, 2011
@@ -71,7 +71,7 @@
* {b Warning: If this type is incorrectly cast then serious problems
* will result. SegFaults will be the least of your worries.}
**/
-@abstract
+//@abstract
type Mongo.collection('a) = {
db: Mongo.mongodb;
ty: OpaType.ty; // type of the collection
@@ -84,7 +84,7 @@ type Mongo.collection('a) = {
* additional information which enables run-time type checks upon
* data as it is received from the MongoDB server.
**/
-@abstract
+//@abstract
type Mongo.collection_cursor('a) = {
collection: Mongo.collection('a);
cursor: Mongo.cursor;
@@ -45,7 +45,7 @@
* of a MongoDB query built in.
**/
// TODO: Possibly arrange a map of address:port values to connections?
-
+//@abstract
type Mongo.mongodb = {
mongo: Mongo.db;
bufsize: int;
@@ -144,13 +144,12 @@ MongoConnection = {{
**/
close(db:Mongo.mongodb): void =
lc = db.link_count.get()
- //do println("close: lc={lc}")
if lc > 0
then
do db.link_count.set(lc-1)
if lc <= 1
then
- do ML.info("MongoConnection.close","closing mongo (close) {db.link_count.get()}",void)
+ do ML.info("MongoConnection.close","closing mongo (close) link_count={db.link_count.get()}",void)
_ = MongoDriver.close(db.mongo)
void
else void
@@ -61,8 +61,7 @@ type Mongo.mongo_host = (string, int)
@abstract
type Mongo.db = {
conn : Mutable.t(option(Socket.connection));
- conncell : Cell.cell(Mongo.rw,Mongo.rwr);
- conncell2 : Cell.cell(Mongo.sr,Mongo.srr);
+ conncell : Cell.cell(Mongo.sr,Mongo.srr);
lock : Mutable.t(bool);
mblock : Mutable.t(bool);
primary : Mutable.t(option(Mongo.mongo_host));
@@ -79,9 +78,6 @@ type Mongo.db = {
max_depth : int;
}
-type Mongo.rw = {read:(Mongo.db,Mongo.mailbox)} / {write:(Mongo.db,string,int)}
-type Mongo.rwr = {readresult:outcome(Mongo.reply,string)} / {writeresult:outcome(int,string)}
-
type Mongo.sr = {send:(Mongo.db,Mongo.mongo_buf,string)} / {sendrecv:(Mongo.db,Mongo.mongo_buf,string)} / {stop}
type Mongo.srr = {sendresult:bool} / {sndrcvresult:option(Mongo.reply)} / {stopresult}
@@ -510,42 +506,6 @@ MongoDriver = {{
ret(false)
@private
- rw(_, msg) =
- match msg with
- | {write=(m,s,len)} ->
- //do println("write")
- (match m.conn.get() with
- | {some=conn} ->
- {return={writeresult=Socket.write_len_with_err_cont(conn,m.comms_timeout,s,len)};
- instruction={unchanged}}
- | {none} ->
- do ML.error("Mongo.send","Unopened connection",void)
- {return={writeresult={failure="Write to unopened connection"}};
- instruction={unchanged}})
- | {read=(m,mailbox)} ->
- //do println("read")
- (match m.conn.get() with
- | {some=conn} ->
- {return={readresult=read_mongo_(conn,m.comms_timeout,mailbox)};
- instruction={unchanged}}
- | {none} ->
- do ML.error("Mongo.receive","Unopened connection",void)
- {return={readresult={failure="Read from unopened connection"}};
- instruction={unchanged}})
-
- @private
- write(m,s,len) =
- match (Cell.call(m.conncell,({write=((m,s,len))}:Mongo.rw)):Mongo.rwr) with
- | {~writeresult} -> writeresult
- | _ -> @fail
-
- @private
- read(m,mailbox) =
- match Cell.call(m.conncell,({read=(m,mailbox)}:Mongo.rw)):Mongo.rwr with
- | {~readresult} -> readresult
- | _ -> @fail
-
- @private
send_no_reply_(m,mbuf,name,reply_expected): bool =
match m.conn.get() with
| {some=conn} ->
@@ -609,45 +569,37 @@ MongoDriver = {{
sr(_, msg) =
match msg with
| {send=(m,mbuf,name)} ->
- //do println("send")
(match m.conn.get() with
| {some=_conn} ->
- {return={sendresult=send_no_reply(m,mbuf,name)};
- instruction={unchanged}}
+ {return={sendresult=send_no_reply(m,mbuf,name)}; instruction={unchanged}}
| {none} ->
do ML.error("Mongo.send","Unopened connection",void)
- {return={sendresult=false};
- instruction={unchanged}})
+ {return={sendresult=false}; instruction={unchanged}})
| {sendrecv=(m,mbuf,name)} ->
- //do println("sendrecv")
(match m.conn.get() with
| {some=_conn} ->
- {return={sndrcvresult=send_with_reply(m,mbuf,name)};
- instruction={unchanged}}
+ {return={sndrcvresult=send_with_reply(m,mbuf,name)}; instruction={unchanged}}
| {none} ->
do ML.error("Mongo.sendrecv","Unopened connection",void)
- {return={sndrcvresult={none}};
- instruction={unchanged}})
+ {return={sndrcvresult={none}}; instruction={unchanged}})
| {stop} ->
- //do println("stop")
- {return={stopresult};
- instruction={stop}}
+ {return={stopresult}; instruction={stop}}
@private
snd(m,mbuf,name) =
- match (Cell.call(m.conncell2,({send=((m,mbuf,name))}:Mongo.sr)):Mongo.srr) with
+ match (Cell.call(m.conncell,({send=((m,mbuf,name))}:Mongo.sr)):Mongo.srr) with
| {~sendresult} -> sendresult
| _ -> @fail
@private
sndrcv(m,mbuf,name) =
- match Cell.call(m.conncell2,({sendrecv=(m,mbuf,name)}:Mongo.sr)):Mongo.srr with
+ match Cell.call(m.conncell,({sendrecv=(m,mbuf,name)}:Mongo.sr)):Mongo.srr with
| {~sndrcvresult} -> sndrcvresult
| _ -> @fail
@private
stop(m) =
- match Cell.call(m.conncell2,({stop}:Mongo.sr)):Mongo.srr with
+ match Cell.call(m.conncell,({stop}:Mongo.sr)):Mongo.srr with
| {stopresult} -> void
| _ -> @fail
@@ -662,8 +614,7 @@ MongoDriver = {{
init(bufsize:int, log:bool): Mongo.db =
conn = Mutable.make({none})
{ ~conn;
- conncell=Cell.make(conn, rw);
- conncell2=(Cell.make(conn, sr):Cell.cell(Mongo.sr,Mongo.srr));
+ conncell=(Cell.make(conn, sr):Cell.cell(Mongo.sr,Mongo.srr));
lock=Mutable.make(false); mblock=Mutable.make(false); ~bufsize; ~log;
seeds=[]; hosts=Mutable.make([]); name="";
primary=Mutable.make({none}); reconnect=Mutable.make({none});
@@ -704,7 +655,6 @@ MongoDriver = {{
* Close mongo connection.
**/
close(m:Mongo.db): Mongo.db =
- //do println("MongoDriver.close")
do if Option.is_some(m.conn.get())
then
do stop(m)
@@ -196,7 +196,6 @@ MongoReplicaSet = {{
* In practice, this should never happen.
**/
connect(m:Mongo.db): outcome(Mongo.db,Mongo.failure) =
- m = {m with log=false}
do if m.seeds == [] then ML.fatal("MongoReplicaSet.connect","Tried to connect with no seeds",-1) else void
rec aux(m, seeds) =
match seeds with
@@ -205,8 +204,8 @@ MongoReplicaSet = {{
| {success=m} ->
m = check_seed(m)
if m.hosts.get() == []
- then aux(/*MongoDriver.close*/(m),rest)
- else {success=/*MongoDriver.close*/(m)}
+ then aux(m,rest)
+ else {success=m}
| {failure=_} ->
aux(m,rest))
| [] -> {failure={Error="MongoReplicaSet.connect: No connecting seeds"}}
@@ -230,10 +229,10 @@ MongoReplicaSet = {{
(match List.extract_p((host -> host == primary_host),rest) with
| ({some=p},rest) ->
do if m.log then ML.info("MongoReplicaSet.connect","jump to primary",void)
- aux2(/*MongoDriver.close*/(m),[p|rest])
- | ({none},rest) -> aux2(/*MongoDriver.close*/(m),rest))
- | {absent} -> aux2(/*MongoDriver.close*/(m),rest))
- | {failure=_} -> aux2(/*MongoDriver.close*/(m),rest))
+ aux2(m,[p|rest])
+ | ({none},rest) -> aux2(m,rest))
+ | {absent} -> aux2(m,rest))
+ | {failure=_} -> aux2(m,rest))
| {failure=_} -> aux2(m,rest))
| [] -> {failure={Error="MongoReplicaSet.connect: No master hosts"}})
aux2(m, m.hosts.get())

0 comments on commit b7e97b4

Please sign in to comment.