本文整理匯總了Golang中github.com/gsrpc/gorpc.Context.Pipeline方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Pipeline方法的具體用法?Golang Context.Pipeline怎麽用?Golang Context.Pipeline使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/gsrpc/gorpc.Context
的用法示例。
在下文中一共展示了Context.Pipeline方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Active
func (handler *_TunnelClient) Active(context gorpc.Context) error {
handler.agents = make(map[string]*_Agent)
handler.system.addTunnel(handler.name, handler, context.Pipeline())
// send TunnelWhoAmI
whoAmI := gorpc.NewTunnelWhoAmI()
whoAmI.Services = handler.system.system.AgentServices()
var buff bytes.Buffer
gorpc.WriteTunnelWhoAmI(&buff, whoAmI)
message := gorpc.NewMessage()
message.Code = gorpc.CodeTunnelWhoAmI
message.Content = buff.Bytes()
context.Send(message)
return nil
}
示例2: timeoutLoop
func (handler *_HeartbeatHandler) timeoutLoop(context gorpc.Context, exitflag chan bool) {
wheel := context.Pipeline().TimeWheel()
ticker := wheel.NewTicker(handler.timeout)
defer ticker.Stop()
for {
select {
case <-ticker.C:
if time.Now().Sub(handler.timestamp) > handler.timeout*2 {
handler.context.Close()
handler.W("heartbeat timeout(%s), close current pipeline(%s)", handler.timeout*2, handler.context.Pipeline())
return
}
message := gorpc.NewMessage()
message.Code = gorpc.CodeHeartbeat
handler.context.Send(message)
handler.V("%s send heartbeat message", handler.context.Pipeline())
case <-exitflag:
handler.V("exit heartbeat loop .....................")
return
}
}
}
示例3: Inactive
func (handler *_TunnelClient) Inactive(context gorpc.Context) {
for _, agent := range handler.agents {
handler.system.system.UnbindAgent(agent)
}
handler.system.removeTunnel(handler.name, handler, context.Pipeline())
}
示例4: Active
func (handler *_TransProxyHandler) Active(context gorpc.Context) error {
dh, _ := context.Pipeline().Handler(dhHandler)
handler.device = dh.(gorpcHandler.CryptoServer).GetDevice()
return nil
}
示例5: Active
func (client *_Client) Active(context gorpc.Context) error {
dh, _ := context.Pipeline().Handler(dhHandler)
device := dh.(handler.CryptoServer).GetDevice()
client.pipeline = context.Pipeline()
client.device = device
client.context.addClient(client)
return nil
}
示例6: MessageReceived
func (handler *_TunnelServerHandler) MessageReceived(context gorpc.Context, message *gorpc.Message) (*gorpc.Message, error) {
if message.Code == gorpc.CodeTunnelWhoAmI {
handler.I("tunnel handshake ......")
whoAmI, err := gorpc.ReadTunnelWhoAmI(bytes.NewBuffer(message.Content))
if err != nil {
return nil, err
}
handler.proxy.proxy.BindServices(handler.proxy, context.Pipeline(), whoAmI.Services)
context.FireActive()
return nil, nil
}
if message.Code != gorpc.CodeTunnel {
return message, nil
}
handler.V("backward tunnel message")
tunnel, err := gorpc.ReadTunnel(bytes.NewBuffer(message.Content))
if err != nil {
handler.E("backward tunnel(%s) message -- failed\n%s", tunnel.ID, err)
return nil, err
}
if device, ok := handler.proxy.client(tunnel.ID); ok {
tunnel.Message.Agent = handler.id
err := device.SendMessage(tunnel.Message)
if err == nil {
handler.V("backward tunnel message -- success")
return nil, nil
}
return nil, err
}
handler.E("backward tunnel(%s) message -- failed,device not found", tunnel.ID)
return nil, nil
}
示例7: MessageReceived
func (handler *_HeartbeatHandler) MessageReceived(context gorpc.Context, message *gorpc.Message) (*gorpc.Message, error) {
if message.Code == gorpc.CodeHeartbeat {
handler.V("%s recv heartbeat message", context.Pipeline())
if handler.timeout != 0 {
handler.timestamp = time.Now()
}
return nil, nil
}
return message, nil
}
示例8: newAgent
func newAgent(ctx gorpc.Context, handler *_TunnelClient, device *gorpc.Device) (*_Agent, error) {
context := &_Agent{
handler: handler,
id: device,
}
context.Sink = gorpc.NewSink(device.String(), context, ctx.Pipeline().TimeWheel(), handler.timeout)
var err error
err = handler.system.system.BindAgent(context)
if err != nil {
return nil, err
}
return context, nil
}
示例9: Inactive
func (handler *_StateHandler) Inactive(context gorpc.Context) {
handler.f(context.Pipeline(), gorpc.StateDisconnect)
}
示例10: Unregister
func (handler *_StateHandler) Unregister(context gorpc.Context) {
handler.f(context.Pipeline(), gorpc.StateClosed)
}
示例11: Active
func (handler *_StateHandler) Active(context gorpc.Context) error {
handler.f(context.Pipeline(), gorpc.StateConnected)
return nil
}
示例12: Inactive
func (handler *_TunnelServerHandler) Inactive(context gorpc.Context) {
go handler.proxy.proxy.UnbindServices(handler.proxy, context.Pipeline())
}