Angel \”Java\” Lopez on Blog

October 23, 2010

Agents in AjTalk: Introduction

Filed under: Agents, AjTalk, Open Source Projects, Programming Languages, Smalltalk — ajlopez @ 11:04 am

I extended my AjTalk Smalltalk-like interpreted VM, written in C#, to support the ideas I have implemented for AjSharp:

Agents in AjSharp (Part 1)
Agents in AjSharp (Part 2)
Web Crawler using Agents in AjSharp

and in AjAgents:

AjAgents: a new implementation

Usually, you send a message (its symbol name, arguments) from a sender to a receiver:

The receiver got the message and processes it. Meanwhile, the sender is waiting a result, or the end of processing, at least. But I want to explore another way of doing things: send the message, and leaves it. The sender could continue with its own processing. This way is similar to living systems: a neuron sends a “message” to another neuron, and then this neuron could send or not more “messages” to another neurons. A parallel processing emerges from all this decoupled activity: it’s a form of message passing, a kind of “tell, don’t ask”, or “hey, this is my message, do something good with it, when you have time, but I don’t care of your answer, now”.

Then, I wrote an extension to AjTalk. You can define an agent subclass using:

Object agent: #MyAgent.

You can define methods for the new subclass MyAgent. But when you create and use once of its instances:

myAgent := MyAgent new.
myAgent doSomethingWith: par1 andWith: par2.

the message is sent to the agent, BUT it is not immediately processed. It is put in a queue. Agent process the message from that queue, using another thread (I could implement a message queue to be consumed by a thread pool of fixed size, in order to serve a large number of agents; actually, there is a thread/queue by agent):

Actually, the queue is a blocking one: if it is filled by messages to process, a new arrival message blocks the sender thread. I could implement other strategies for message throttling. The C# classes that implements all this behavior are BaseAgent (overriding the ExecuteMethod method):

public override object ExecuteMethod(IMethod method, object[] arguments)
    Message message = new Message(method, arguments);
    return null;    // TODO what to return?

and MessageQueue (a blocking queue implementation for message). You can download the current AjTalk source code from trunk at

My idea is to write a use case for this kind of agents: my classical web crawler, or something simpler. I have distributed objects, too. I could combine these two features: a distributed web crawler, maybe.

Keep tuned!

Angel “Java” Lopez

Create a free website or blog at