Source

fantomongo / fan / Mongo.fan

Full commit
////////////////////////////////////////////////////////////////////////////////
//
//  Copyright 2010 Liam Staskawicz
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

using concurrent

**
** Mongo Service.
**
const class Mongo : Service
{
  const Int port
  const Str address
  internal const Connection connection
  internal const ActorPool processorPool := ActorPool()
  internal static const Log log := Log.get("mongo")
  
  // op values
  static const Int OP_INVALID                  := -1
  static const Int OP_REPLY                    := 1
  static const Int OP_QUERY_SLAVE_OK           := 4
  static const Int OP_QUERY_NO_CURSOR_TIMEOUT  := 16
  static const Int OP_MSG                      := 1000
  static const Int OP_UPDATE                   := 2001
  static const Int OP_INSERT                   := 2002
  static const Int OP_GET_BY_OID               := 2003
  static const Int OP_QUERY                    := 2004
  static const Int OP_GET_MORE                 := 2005
  static const Int OP_DELETE                   := 2006
  static const Int OP_KILL_CURSORS             := 2007
  
  // for indexes and sorting
  static const Int ASCENDING := 1
  static const Int DESCENDING := -1

  new make(Str address := "127.0.0.1", Int port := 27017)
  { 
    this.address = address
    this.port    = port
    this.connection = Connection(this)
  }

  override Void onStart()
  {
    log.info("Mongo started on port ${port}")
    // Actor(listenerPool, |,| { listen }).send(null)
  }

  override Void onStop()
  {
    processorPool.stop
  }
  
  DB db(Str name)
  {
    return DB(name, this)
  }
  
}