Message-Passing
为了使前面的例子更有意思一些,我们将引入channel的概念并实现一个agent发送一个消息到channel的端口。
前面我们说过Agent是对数据处理的组件,而数据则通过Channel进入Agent或从Agent中输出。为适应不同类型的数据,一个Channel有一个或多个端口。
后面我们会详细谈论Agent并讲述如何定义一个Channel。现在我们先来看看如何使用Channel来发送和接收数据。
using System;
agent Program : channel Microsoft.Axum.Application
{
public Program()
{
// Receive command line arguments from port CommandLine
String [] args = receive(PrimaryChannel::CommandLine);
// Send a message to port ExitCode:
PrimaryChannel::ExitCode <—0;
}
}
在这个例子中,我们使用了一个叫Program的Agent,实现了一个Microsoft.Axum.Application的Channel。