Commits

Liam Staskawicz committed c3e83c6

* replace Actor with AtomicInt in Connection

Comments (0)

Files changed (1)

fan/Connection.fan

   private const Mongo mongo
   private const Str id
   private static const Log log := Log.get("mongo")
-  private static const Actor idInc := Actor(ActorPool()) |msg->Int|
-  {
-    Int count := Actor.locals["count"] ?: 1
-    Actor.locals["count"] = count + 1
-    return count
-  }
+  private static const AtomicInt idCounter := AtomicInt(0)
   
   new make(Mongo m)
   {
   TcpSocket getSocket()
   {
     TcpSocket? s := Actor.locals[id]
-    if(s == null) {
+    if (s == null) {
       s = TcpSocket()
       Actor.locals[id] = s
     }
-    if(!s.isConnected()) {
+    if (!s.isConnected) {
       s.connect(IpAddr(mongo.address), mongo.port)
       s.in.endian = s.out.endian = Endian.little
     }
   
   Int sendMsg(OutStream os, Buf b, Int op)
   {
-    reqId := idInc.send(null).get as Int
+    reqId := idCounter.incrementAndGet
     // header - len, reqID, reserved, opcode
     os.writeI4(b.size + 16).writeI4(reqId).writeI4(0).writeI4(op)
     os.writeBuf(b).flush
   Void close()
   {
     TcpSocket? s := Actor.locals[id]
-    if(s != null)
+    if (s != null)
       s.close
   }
 }