openedge-function模块进行函数运行源码浅析——百度BIE边缘侧openedge项目源码阅读(4)

前言

之前的一篇文章介绍了openedge-function模块(下面简称function模块)进行初始化的部分,下面整体过一下启动一个函数的流程。

接收到消息

之前介绍过,ruler是整个function模块的核心,其负责进行接收启动函数的命令以及向master模块请求启动模块,并将函数运行后的结果发送至hub模块中。
下面看一下接收到消息的代码:

func (rr *ruler) start() error {
	rr.fd.SetCallback(func(pkt *packet.Publish) {
		···
		if pkt.Message.Payload != nil {
			···
			err := rr.md.Send(pkt)
			···
		}
		···
	})
	h := mqtt.Handler{}
	h.ProcessPublish = func(p *packet.Publish) error {
		return rr.fd.Invoke(p)
	}
	···
	return rr.md.Start(h)
}

里面由两个重要点,一个是callback方法,另一个是ProcessPublish方法。其中,ProcessPublish就是接收到Publish的消息后的处理方法,我们接着看rr.fd.Invoke(p)方法:(fd我们就暂时称为Function Dispatcher好了)

// Invoke invokes a function
func (d *Dispatcher) Invoke(pkt *packet.Publish) error {
	select {
	case d.buffer <- struct{}{}:
	case <-d.tomb.Dying():
		return ErrDispatcherClosed
	}
	go func(pub *packet.Publish) {
		msg := &runtime.Message{
			QOS:     uint32(pub.Message.QOS),
			Topic:   pub.Message.Topic,
			Payload: pub.Message.Payload,
		}
		msg, err := d.function.Invoke(msg)
		if err != nil {
			pub.Message.Payload = utils.MakeErrorPayload(pub, err)
		} else {
			pub.Message.Payload = msg.Payload
		}
		if d.callback != nil {
			d.callback(pub)
		}
		<-d.buffer
	}(pkt)
	return nil
}

首先其使用function.Invoke(msg)方法,然后调用了callback方法,这个callback是函数模块执行完毕后返回的值,在讲返回的时候再讲这里。下面看看function.Invoke(msg)方法:

// Invoke call funtion to handle message and return result message
func (f *Function) Invoke(msg *runtime.Message) (*runtime.Message, error) {
	item, err := f.pool.BorrowObject(context.Background())
	···
	fl := item.(*funclet)
	res, err := fl.handle(msg)
	···
	f.pool.ReturnObject(context.Background(), item)
	return res, nil

}
</
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
QAD ERP专用数据库及程序开发语言手册 ABL Reference Preface This Preface contains the following sections: * Purpose * Audience * Organization * Using this manual * Typographical conventions * Examples of syntax descriptions * Example procedures * OpenEdge messages * Third party acknowledgements Purpose This book describes ABL (Advanced Business Language), which is the OpenEdge® programming language for building business applications. It covers all ABL statements, functions, phrases, operators, preprocessor directives, special symbols, widgets, handles, classes, interfaces, attributes, methods, properties, and events. Audience This book is intended for programmers who develop applications using ABL and for anyone who needs to read and understand ABL code. Organization This book consists of the following sections: * A dictionary of ABL statements, functions, phrases, operators, preprocessors, and special symbols. * A dictionary of ABL widgets. * A dictionary of ABL handles. * A dictionary of ABL attributes and methods (for handles). * A dictionary of ABL handle-based object events. * A dictionary of ABL classes and interfaces. * A dictionary of ABL properties and methods (for classes). * A dictionary of ABL class events and event methods * An index of ABL keywords. Using this manual OpenEdge provides a special purpose programming language for building business applications. In the documentation, the formal name for this language is ABL (Advanced Business Language). With few exceptions, all keywords of the language appear in all UPPERCASE, using a font that is appropriate to the context. All other alphabetic language content appears in mixed case. For the latest documentation updates see the OpenEdge Product Documentation Overview page on PSDN: http://communities.progress.com/pcom/docs/DOC-16074. References to ABL compiler and run-time features ABL is both a compiled and an interpreted language that executes in a run-time engine.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值