示例#1
0
文件: areas.go 项目: mysll/flynet
func (a *Areas) GetArea(mailbox rpc.Mailbox, id string) error {
	a.l.Lock()
	defer a.l.Unlock()

	log.LogMessage("GetArea")
	app := server.GetAppByName(mailbox.App)
	if app == nil {
		return server.ErrAppNotFound
	}

	if areainfo, exist := a.areas[id]; exist {
		if areainfo.Status == AREA_CREATED {
			return app.Call(&mailbox, "AreaBridge.GetAreaBak", areainfo.AppId)
		} else {
			a.pending[id].PushBack(mailbox)
			return nil
		}
	}

	a.lastareaid++
	appid := fmt.Sprintf("area_%d", a.lastareaid)
	data, err := share.CreateAppMsg("area",
		id,
		appid,
		fmt.Sprintf(`{ "id":"%s", "host":"127.0.0.1", "port":0, "areaid":"%s"}`,
			appid,
			id),
		App.Name,
	)
	if err != nil {
		log.LogError(err)
		return app.Call(&mailbox, "AreaBridge.GetAreaBak", "")
	}

	err = App.SendToMaster(data)
	if err != nil {
		log.LogError(err)
		return app.Call(&mailbox, "AreaBridge.GetAreaBak", "")
	}

	ar := &area{}
	ar.AppId = appid
	ar.Status = AREA_CREATING
	a.areas[id] = ar
	l := list.New()
	l.PushBack(mailbox)
	a.pending[id] = l

	log.LogMessage(a)
	return nil
}
示例#2
0
文件: agentlist.go 项目: mysll/flynet
func (a *AgentNode) CreateApp(reqid string, appid string, appuid int32, typ string, args string, callapp int32) error {
	data, err := share.CreateAppMsg(typ, reqid, appid, appuid, args, callapp)
	if err != nil {
		log.LogError(err)
		return err
	}

	_, err = a.rwc.Write(data)
	if err != nil {
		return err
	}

	a.load++
	return nil
}