Пример #1
0
// Panic is called is an panic is caught by the framework
func (this *BaseController) Panic() revel.Result {
	defer func() {
		mongo.CloseSession(this.UserId, this.MongoSession)
		this.MongoSession = nil
	}()

	tracelog.TRACE(this.UserId, "Panic", this.Request.URL.Path)
	return nil
}
Пример #2
0
// After is called once the controller method completes
func (this *BaseController) After() revel.Result {
	defer func() {
		if this.MongoSession != nil {
			mongo.CloseSession(this.UserId, this.MongoSession)
			this.MongoSession = nil
		}
	}()

	tracelog.TRACE(this.UserId, "After", this.Request.URL.Path)
	return nil
}
Пример #3
0
// Before is called prior to the controller method
func (this *BaseController) Before() revel.Result {
	this.UserId = this.Session.Id()
	tracelog.TRACE(this.UserId, "Before", "UserId[%s] Path[%s]", this.Session.Id(), this.Request.URL.Path)

	var err error
	this.MongoSession, err = mongo.CopyMonotonicSession(this.UserId)
	if err != nil {
		tracelog.ERRORf(err, this.UserId, "Before", this.Request.URL.Path)
		return this.RenderError(err)
	}

	return nil
}
Пример #4
0
// Startup brings the manager to a running state
func Startup(sessionId string) (err error) {
	defer helper.CatchPanic(&err, sessionId, "Startup")

	tracelog.STARTED(sessionId, "Startup")

	// Create the Mongo Manager
	_This = &mongoManager{
		sessions: map[string]*mongoSession{},
	}

	// Log the mongodb connection straps
	tracelog.TRACE(sessionId, "Startup", "MongoDB : Addr[%s]", revel.Config.StringDefault("mgo.host", ""))
	tracelog.TRACE(sessionId, "Startup", "MongoDB : Database[%s]", revel.Config.StringDefault("mgo.database", ""))
	tracelog.TRACE(sessionId, "Startup", "MongoDB : Username[%s]", revel.Config.StringDefault("mgo.username", ""))

	hosts := strings.Split(revel.Config.StringDefault("mgo.host", ""), ",")

	// Create the strong and monotonic sessions
	err = CreateSession(sessionId, "strong", MASTER_SESSION, hosts, revel.Config.StringDefault("mgo.database", ""), revel.Config.StringDefault("mgo.username", ""), revel.Config.StringDefault("mgo.password", ""))
	err = CreateSession(sessionId, "monotonic", MONOTONIC_SESSION, hosts, revel.Config.StringDefault("mgo.database", ""), revel.Config.StringDefault("mgo.username", ""), revel.Config.StringDefault("mgo.password", ""))

	tracelog.COMPLETED(sessionId, "Startup")
	return err
}
Пример #5
0
// FindRegion retrieves the stations for the specified region
func FindRegion(service *services.Service, region string) (buoyStations []*buoyModel.BuoyStation, err error) {
	defer helper.CatchPanic(&err, service.UserId, "FindRegion")

	tracelog.STARTED(service.UserId, "FindRegion")

	// Find the specified region
	queryMap := bson.M{"region": region}
	tracelog.TRACE(helper.MAIN_GO_ROUTINE, "FindRegion", "Query : %s", mongo.ToString(queryMap))

	// Capture the specified buoy
	buoyStations = []*buoyModel.BuoyStation{}
	err = service.DBAction("buoy_stations",
		func(collection *mgo.Collection) error {
			return collection.Find(queryMap).All(&buoyStations)
		})

	if err != nil {
		tracelog.COMPLETED_ERROR(err, helper.MAIN_GO_ROUTINE, "FindRegion")
		return buoyStations, err
	}

	tracelog.COMPLETED(service.UserId, "FindRegion")
	return buoyStations, err
}
Пример #6
0
// FindStation retrieves the specified station
func FindStation(service *services.Service, stationId string) (buoyStation *buoyModel.BuoyStation, err error) {
	defer helper.CatchPanic(&err, service.UserId, "FindStation")

	tracelog.STARTED(service.UserId, "FindStation")

	// Find the specified station id
	queryMap := bson.M{"station_id": stationId}
	tracelog.TRACE(helper.MAIN_GO_ROUTINE, "FindStation", "Query : %s", mongo.ToString(queryMap))

	// Execute the query
	buoyStation = &buoyModel.BuoyStation{}
	err = service.DBAction("buoy_stations",
		func(collection *mgo.Collection) error {
			return collection.Find(queryMap).One(buoyStation)
		})

	if err != nil {
		tracelog.COMPLETED_ERROR(err, helper.MAIN_GO_ROUTINE, "FindStation")
		return buoyStation, err
	}

	tracelog.COMPLETED(service.UserId, "FindStation")
	return buoyStation, err
}