本文整理汇总了Golang中context.GetContext函数的典型用法代码示例。如果您正苦于以下问题:Golang GetContext函数的具体用法?Golang GetContext怎么用?Golang GetContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetContext函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
}
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:15,代码来源:server.go
示例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
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:29,代码来源:server.go
示例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()
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:9,代码来源:tcp_socket.go
示例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}
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:10,代码来源:channelRpcServer.go
示例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
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:42,代码来源:channelRpcServer.go
示例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
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:11,代码来源:coserver.go
示例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}
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:11,代码来源:sessionRpcServer.go
示例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)
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:12,代码来源:sessionRpcServer.go
示例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}
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:16,代码来源:channelService.go
示例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)
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:13,代码来源:channelRpcServer.go
示例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
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:13,代码来源:comonitor.go
示例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())
}
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:19,代码来源:backendSessionService.go
示例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}
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:17,代码来源:sessionService.go
示例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)
}
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:43,代码来源:channelService.go
示例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())
}
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:14,代码来源:backendSessionService.go
示例16: NewCoChannel
func NewCoChannel() *CoChannel {
ctx := context.GetContext()
coChan, ok := ctx.GetComponent("cochannel").(*CoChannel)
if ok == true {
return coChan
}
chanS := channelService.NewChannelService()
coChan = &CoChannel{chanS}
ctx.RegisteComponent("cochannel", coChan)
seelog.Info("CoChannel create successfully")
return coChan
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:14,代码来源:cochannel.go
示例17: NewCoBackendSession
func NewCoBackendSession() *CoBackendSession {
ctx := context.GetContext()
coBS, ok := ctx.GetComponent("cobackendsession").(*CoBackendSession)
if ok == true {
return coBS
}
bss := backendSessionService.NewBackendSessionService(ctx)
coBS = &CoBackendSession{bss}
ctx.RegisteComponent("cobackendsession", coBS)
return coBS
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:14,代码来源:cobackendsession.go
示例18: NewCoConnection
func NewCoConnection() *CoConnection {
ctx := context.GetContext()
coconn, ok := ctx.GetComponent("coconnection").(*CoConnection)
if ok == true {
return coconn
}
cs := connectionService.NewConnectionService(ctx.GetServerID())
coconn = &CoConnection{cs, ctx}
ctx.RegisteComponent("coconnection", coconn)
seelog.Infof("CoConnetion create successfully")
return coconn
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:15,代码来源:coconnection.go
示例19: NewCoChannelRpcServer
func NewCoChannelRpcServer() *CoChannelRpcServer {
ctx := context.GetContext()
coChanRS, ok := ctx.GetComponent("cochannelrpcserver").(*CoChannelRpcServer)
if ok == false {
seelog.Infof("CoChannelRpcServer not found,create new...")
chanRpcS := channelRpcServer.NewChannelRpcServer()
coChanRS = &CoChannelRpcServer{chanRpcS}
ctx.RegisteComponent("cochannelrpcserver", coChanRS)
}
seelog.Infof("CoChannelRpcServer create successfully")
return coChanRS
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:15,代码来源:cochannelrpcserver.go
示例20: NewCoSession
/// 创建CoSession.
func NewCoSession() *CoSession {
ctx := context.GetContext()
cosess, ok := ctx.GetComponent("cosession").(*CoSession)
if ok == true {
return cosess
}
ss := sessionService.NewSessionService(ctx.AllOpts["cosession"])
cosess = &CoSession{ss}
ctx.RegisteComponent("cosession", cosess)
seelog.Info("CoSession create successufully")
return cosess
}
开发者ID:liweisheng,项目名称:server-framework,代码行数:16,代码来源:cosession.go
注:本文中的context.GetContext函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论