Angel \”Java\” Lopez on Blog

May 17, 2010

Distributed AjSharp: First steps

It was a great code kata this weekend. At Saturday afternoon, I started to play with serialization of commands in my AjSharp interpreter:

It was using Windows Communication Foundation, simple BasicHttpBindind and address. I choose to serialize commands and expressions in byte arrays using BinaryFormatter, and send them via basic WCF (I don’t like to struggle with WCF serialization).

Then, yesterday (sunday) I write an implementation using remoting. This is a better approach in this situation: remoting out-of-the-box support for graph serialization, and management of MarshalByRefObject, is good for my project.

My first attemps using remoting:

Note the use of new keywords expression and command. This sentence:

a = expression b+c;

assign a to-be-evaluate expression b+c to local variable a. You can evaluate with:

result = a.Evaluate(Machine.Environment);

(Machine is the current running machine, with its global .Environment, where there are the bindings for b and c).

The command:

a = command PrintLine(“Hello, world”);

doesn’t print a message. It store in local variable a command, to be execute with:

a.Execute(Machine.Environment);

In the above example, yYou can start a server programmatically. And you can create a client proxy to a server. Then, you can invoke commands, or evaluate expressions in the other server. After then, I added call functions, subs, in the other server, passing arguments from the local run. The main interface is IHost:

    public interface IHost
    {
        // Host Id
        Guid Id { get; }
        // Host Invocation
        void Execute(ICommand command);
        object Evaluate(IExpression expression);
        object Invoke(ICallable function, params object[] arguments);
        // Others... Work in progress... to review
    }

A host runs a machine, and expose access to invocation and evaluation via its interface. There are local host (class Host), or hosts that expose its functionality via remoting (RemotingHostServer) and the corresponding client proxy (RemotingHostClient). I'm working in WCF too: there is a WcfHostServer and WcfHostClient, but I should struggle with serialization issues, yet.

I should add passing stirng as command/expression (it could be an easier way to invoke the other part), so the server could parse them and execute/evaluate.

After mi initial successful attempts, I added syntax sugar, it's nice to have at as new keyword in AjSharp:

You can invoke a command in other server:

at <host> <command>;

or you can evaluate an expression in other server:

localvar = at <host> <expression>;

I should work more in serialization. I resolved part of the callback to the server. That is:

at host { adam = new DynamicObject(); adam.Name = “Adam”; adam.Age = 800; }

myadam = at host adam;

adam is created in the remote host. myadam, using remoting, is a transparent proxy to a DynamicObject still resident at host (My decision was that the dynamic objects are MarshalByRefObject; I could change this selection in the future: make dynamic objects serializable by default, and add obj.AsProxy() to generate a MarshalByRefObject explicitly). But the returned transparent proxy cannot be invoked directly: it has no associated communication channel. So, I added some wrapper to it at client side. If something is invoked in myadam, as in:

PrintLine(myadam.Name);

myadam.Name = “NewAdam”;

the server object is invoked, and the operation is executed at server.

As usual, you can download the code from:

http://code.google.com/p/ajcodekatas/source/browse/

under trunk/AjLanguage.

I'm proud of these advances in my interpreter. It was only an idea, but now, a distributed language was born. It's a baby, but it MY baby, and it was fun to code all this.

Keep tuned!

Angel “Java” Lopez

http://www.ajlopez.com

http://twitter.com/ajlopez

2 Comments »

  1. [...] Distributed AjSharp: First Steps [...]

    Pingback by Distributed AjSharp: a roadmap « Angel “Java” Lopez on Blog — May 22, 2010 @ 12:57 pm

  2. [...] Distributed AjSharp: First Steps AjSharp Distribuido: Primeros Pasos [...]

    Pingback by AjSharp Distribuido: un roadmap - Angel "Java" Lopez — May 23, 2010 @ 12:15 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Shocking Blue Green Theme Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 56 other followers

%d bloggers like this: