本文整理匯總了Golang中context.GetContext函數的典型用法代碼示例。如果您正苦於以下問題:Golang GetContext函數的具體用法?Golang GetContext怎麽用?Golang GetContext使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了GetContext函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: RegisteAsLocalService
func (s *Server) RegisteAsLocalService(recv interface{}) {
t := reflect.TypeOf(recv)
v := reflect.ValueOf(recv)
numMethod := t.NumMethod()
sName := v.Type().Name()
for index := 0; index < numMethod; index++ {
methodName := t.Method(index).Name
if handler, ok := v.Method(index).Interface().(func(*sessionService.SimpleSession, map[string]interface{}) map[string]interface{}); ok == true {
s.handlers[sName+"."+methodName] = handler
seelog.Infof("<%v> Registe local service<%v>'s method<%v>", context.GetContext().GetServerID(), v.Type().Name(), methodName)
} else {
seelog.Warnf("<%v> Registe local service <%v>'s method<%v> error", context.GetContext().GetServerID(), v.Type().Name(), methodName)
}
}
}
示例2: main
func main() {
if len(os.Args) < 3 {
fmt.Fprintf(os.Stderr, "too few args,args form: <host port>\n")
os.Exit(1)
}
host := os.Args[1]
port, err := strconv.Atoi(os.Args[2])
if err != nil {
fmt.Fprintf(os.Stderr, "invalid port,need integer type,your input port: <port>\n", os.Args[2])
os.Exit(1)
}
ctx := context.GetContext()
currentServer := make(map[string]interface{})
currentServer["id"] = "connector-1"
currentServer["serverType"] = "connector"
currentServer["host"] = "127.0.0.1"
currentServer["port"] = 8888
ctx.CurrentServer = currentServer
defer seelog.Flush()
tcp_cnct := tcp_connector.NewTcpConnector(host, port, nil)
tcp_cnct.RegistNewConnCB(NewConnCB)
tcp_cnct.RegistNewMsgCB(NewMsgCB)
tcp_cnct.Start()
ch := make(chan int)
<-ch
}
示例3: Disconnect
func (ts *TcpSocket) Disconnect() {
seelog.Debugf("<%v> Disconnect sid<%v>", context.GetContext().GetServerID(), ts.id)
if ts.status == connector.ST_CLOSED {
return
}
ts.status = connector.ST_CLOSED
ts.socket.Close()
}
示例4: NewChannelRpcServer
func NewChannelRpcServer() *ChannelRpcServer {
ctx := context.GetContext()
coCnct, ok := ctx.GetComponent("coconnector").(*coconnector.CoConnector)
if ok == false {
coCnct = coconnector.NewCoConnector(ctx)
}
return &ChannelRpcServer{coCnct}
}
示例5: PushMessage
func (crs *ChannelRpcServer) PushMessage(args map[string]interface{}, reply interface{}) error {
route, _ := args["route"].(string)
msg, ok1 := args["msg"].(map[string]interface{})
if ok1 == false {
seelog.Error("Invalid or empty message")
return errors.New("Invalid or empty message")
}
coSess, ok2 := context.GetContext().GetComponent("cosession").(*cosession.CoSession)
if ok2 == false {
seelog.Critical("Failed to get component<cosession>")
os.Exit(1)
}
uids, ok3 := args["uids"].([]string)
if ok3 == false {
seelog.Error("Failed to get uids")
return errors.New("Failed to get uids")
}
sids := make([]uint32, 0, 16)
for _, uid := range uids {
sessions := coSess.GetSessionsByUID(uid)
if sessions == nil {
seelog.Warnf("Failed to push message to uid<%v> because of nil sessions", uid)
continue
}
for _, session := range sessions {
sids = append(sids, session.Id)
}
}
seelog.Debugf("<%v> push messages<%v> to uids<%v> with sessions<%v>", context.GetContext().GetServerID(), msg, uids, sids)
//XXX:調用coconnector的send方法發送.
crs.coCnct.Send("", route, msg, sids)
return nil
}
示例6: NewCoServer
func NewCoServer() *CoServer {
ctx := context.GetContext()
coServ, ok := ctx.GetComponent("coserver").(*CoServer)
if ok == true {
return coServ
}
serv := server.NewServer()
coServ = &CoServer{serv}
seelog.Infof("<%v> component server created", ctx.GetServerID())
return coServ
}
示例7: NewSessionRpcServer
func NewSessionRpcServer() *SessionRpcServer {
ctx := context.GetContext()
sessionService, ok := ctx.GetComponent("cosession").(*cosession.CoSession)
if ok == false || sessionService == nil {
sessionService = cosession.NewCoSession()
}
return &SessionRpcServer{sessionService}
}
示例8: Start
func (srs *SessionRpcServer) Start() {
ctx := context.GetContext()
coRpcS, ok := ctx.GetComponent("corpcserver").(*corpcserver.CoRpcServer)
if ok == false {
coRpcS = corpcserver.NewCoRpcServer()
}
seelog.Infof("frontendserver<%v> SessionRpcServer start,registe service to rpc server", ctx.GetServerID())
// srs := NewSessionRpcServer()
coRpcS.RegisteService(srs)
}
示例9: NewChannelService
/// 創建新的ChannelService,ChannelService管理用戶創建的所有Channel,並代理用戶對Channel的操作,
/// 用戶發送給一個Channel裏所有session的消息會通過rpc調用發送給對應的前端服務器,並通過前端服務
/// 器推送給客戶端.
func NewChannelService() *ChannelService {
ctx := context.GetContext()
coRpcClient, ok := ctx.GetComponent("corpcclient").(*corpcclient.CoRpcClient)
if ok == false {
coRpcClient = corpcclient.NewCoRpcClient()
}
channels := make(map[string]*Channel)
return &ChannelService{ctx, coRpcClient, channels}
}
示例10: Start
func (crs *ChannelRpcServer) Start() {
ctx := context.GetContext()
coRpcS, ok := ctx.GetComponent("corpcserver").(*corpcserver.CoRpcServer)
if ok == false {
coRpcS = corpcserver.NewCoRpcServer()
}
seelog.Info("ChannelRpcServer start,registe service to rpcserver")
// srs := NewSessionRpcServer()
coRpcS.RegisteService(crs)
}
示例11: NewCoMonitor
func NewCoMonitor() *CoMonitor {
ctx := context.GetContext()
coMonitor, ok := ctx.GetComponent("comonitor").(*CoMonitor)
if ok == true {
return coMonitor
}
mcs := pomelo_admin.NewMonitorConsoleService(ctx)
coMonitor = &CoMonitor{mcs}
seelog.Infof("<%v> component CoMonitor created...", ctx.GetServerID())
ctx.RegisteComponent("comonitor", coMonitor)
return coMonitor
}
示例12: KickBySID
/// 通過session id從前端服務器踢除用戶連接,通過rpc調用前端服務器的同樣操作.
///
/// @param frontendid 前端服務器id
/// @param sid session id
/// @reason 作為踢除用戶連接時發送給用戶端的提示信息.
/// @return 無返回值
func (bss *BackendSessionService) KickBySID(frontendid string, sid uint32, reason string) {
seelog.Tracef("frontendid<%v>,sid<%v>", frontendid, sid)
method := "SessionRpcServer.KickBySID"
args := make([]interface{}, 2)
args[0] = sid
args[1] = reason
if err := bss.rpcCient.RpcCall(frontendid, method, args, nil); err != nil {
seelog.Errorf("<%v> KickBySID error<%v>", context.GetContext().GetServerID(), err.Error())
}
}
示例13: NewSessionService
/// 創建新的SessionService.
///
/// @param opts 指定創建SessionService的選項,選項是name:value的形式
/// @return *SessionService
func NewSessionService(opts map[string]interface{}) *SessionService {
if nil == opts {
opts = make(map[string]interface{})
}
sessions := make(map[uint32]*Session)
uidmap := make(map[string][]*Session)
multibind := opts["multiBind"] != nil && (opts["multiBind"].(string) != "")
rwMutexS := new(sync.RWMutex)
rwMutexUM := new(sync.RWMutex)
seelog.Infof("frontendserver<%v> create sessionservice with opts<%v>", context.GetContext().GetServerID(), opts)
return &SessionService{sessions, uidmap, multibind, opts, rwMutexS, rwMutexUM}
}
示例14: sendMsgByGroup
/// 發送消息到groups中的所有用戶.
///
/// @route 路由
/// @param msg 發送的消息
/// @param groups frontendID-> uids的映射
func (cs *ChannelService) sendMsgByGroup(route string, msg map[string]interface{}, groups map[string][]string) {
seelog.Debugf("<%v> channelService sendMsgByGroup with route<%v> msg<%v> groups<%v>", cs.ctx.GetServerID(), route, msg, groups)
args := make(map[string]interface{})
args["route"] = route
args["msg"] = msg
coChanRpcS, ok := context.GetContext().GetComponent("cochannelrpcserver").(*cochannelrpcserver.CoChannelRpcServer)
if ok == false {
seelog.Error("Fail to get CoChannelRpcServer")
return
}
sendMsg := func(serverid string) {
if cs.ctx.GetServerID() == serverid {
//TODO:直接調用channelRpcServer相關方法,無需rpc
if err := coChanRpcS.PushMessage(args, nil); err != nil {
seelog.Errorf("Fail to invoke PushMessage to send msg,error<%v>", err.Error())
return
}
} else {
//TODO:發起rpc調用.
if err := cs.coRpcClient.RpcCall(serverid, "ChannelRpcServer.PushMessage", args, nil); err != nil {
seelog.Errorf("<%v> fail to invoke rpc PushMessage error<%v>", context.GetContext().GetServerID(), err.Error())
return
}
}
}
for frontendID, uids := range groups {
//TODO:逐個發送msg.
seelog.Infof("<%v> PushMessage to uids<%v> connected to frontend<%v>", context.GetContext().GetServerID(), uids, frontendID)
args["uid"] = uids
sendMsg(frontendID)
}
}
示例15: PushAllOpts
func (bss *BackendSessionService) PushAllOpts(frontendid string, sid uint32, settings map[string]interface{}) {
seelog.Tracef("Push all opts to <%v> with sid<%v>", frontendid, sid)
args := make(map[string]interface{})
args["sid"] = sid
args["settings"] = settings
method := "SessionRpcServer.PushAllOpts"
if err := bss.rpcCient.RpcCall(frontendid, method, &args, nil); err != nil {
seelog.Errorf("<%v> PushAllOpts with sid<%v> to frontend<%v> error<%v>", context.GetContext().GetServerID(), sid, frontendid, err.Error())
}
}