Commits

Liam Staskawicz committed 870ac9d

* Actors moved to concurrent pod
* use new AtomicInt class for ObjectID

  • Participants
  • Parent commits 0b1f1d6

Comments (0)

Files changed (4)

   {
     podName = "mongo"
     summary = "Interface to MongoDB (http://www.mongodb.com)"
-    depends = ["sys 1.0", "inet 1.0"]
+    depends = ["sys 1.0", "inet 1.0", "concurrent 1.0"]
     srcDirs = [`fan/`, `fan/bson/`, `fan/gridfs/`, `test/`]
     docSrc  = true
-    version = Version([0, 1])
   }
-}
+}

File fan/Connection.fan

 
 
 using inet
+using concurrent
 
 **
 ** Connection

File fan/Mongo.fan

 //
 ////////////////////////////////////////////////////////////////////////////////
 
+using concurrent
+
 **
 ** Mongo Service.
 **

File fan/ObjectID.fan

 //
 ////////////////////////////////////////////////////////////////////////////////
 
-
 using inet
+using concurrent
 
 **
 **  ObjectID
 const class ObjectID 
 {
   static const Int SIZE := 12
+  private static const AtomicInt counter := AtomicInt(0)
   private const Int inc
   private const Int time
   private const Int machine
-  private static const Actor idInc := Actor(ActorPool()) |msg->Int|
-  {
-    Int count := Actor.locals["count"] ?: 1
-    Actor.locals["count"] = count + 1
-    return count
-  }
   
   new make()
   { 
-    this.inc = (idInc.send(null).get(null) as Int).and(0xFFFFFFFF)
+    this.inc = counter.incrementAndGet().and(0xFFFFFFFF)
     this.time = DateTime.nowUnique.and(0xFFFFFFFF)
     this.machine = IpAddr.local.bytes.toDigest("MD5").readS4.and(0xFFFFFFFF)
   }
   
   new fromStr(Str s)
   {
-    if(!isValid(s)) throw Err("invalid ObjectID format")
+    if (!isValid(s)) throw Err("invalid ObjectID format")
       
     this.time = s[0..7].toInt(16).and(0xFFFFFFFF)
     this.machine = s[8..15].toInt(16).and(0xFFFFFFFF)
   
   override Bool equals(Obj? o)
   {
-    if(o isnot ObjectID)
+    if (o isnot ObjectID)
       return false
     
     return ((o as ObjectID).inc == this.inc && 
   
   static Bool isValid(Str s)
   {
-    if ( s.size != 24 )
+    if (s.size != 24)
       return false;
     
     // make sure it's all hex digits so we can convert to Ints
     valid := true
     s.each |Int c| {
-      if ( c >= '0' && c <= '9' )
-        return
-      if ( c >= 'a' && c <= 'f' )
-        return
-      if ( c >= 'A' && c <= 'F' )
+      if (c >= '0' && c <= '9')
+        return                 
+      if (c >= 'a' && c <= 'f')
+        return                 
+      if (c >= 'A' && c <= 'F')
         return
       valid = false
     }