Distributed Objects in AjTalk

I added distributed objects to my AjTalk project (Smalltalk-like VM written in C#). I’m using .NET Remoting to serialize objects from one process to another, and to have proxies to remote objects. You can download the source code and tests from:


First, there is a new method for objects:

nil subclass: #Object
!Object methods!
^@AjTalk.Hosting.RemoteObject new: self
! !

(I’m using AjTalk notation to access .NET types and methods, see AjTalk: Accessing .NET Types And Objects)

The RemoteObject class is a decorator around an IObject (objects in AjTalk), that inherits from MarshalByRefObject. In .NET, such objects are not serialized: instead, a reference is send to the other process. Every call in that proxy, sends the invoke to the original object, still residing in its process:

    public class RemoteObject : MarshalByRefObject, IObject
        private IObject obj;
        private Machine machine;
        public RemoteObject(IObject obj)
            this.obj = obj;
            this.machine = Machine.Current;
    // ...    

There is a host, that can receive calls from other process. Launch a host in process A:

Object subclass: #Host nativeType: @AjTalk.Hosting.RemotingHostServer


host := Host new: @AjTalk.Machine !!current with: 20000 with: 'Server2000'


From other process, you can connect to this host. Executing in process B:

Object subclass: #RemoteHost nativeType: @AjTalk.Hosting.RemotingHostClient

!RemoteHost methods!

export: aClass
self execute: (aClass !!toOutputString)
! !

remote := RemoteHost new: 'localhost' with: 20000 with: 'Server2000'


Now, remote is an object in process B that can be used to communicate with remote process/machine A.

The export method serialize the string definition of a class. So, if you have a new class in this process, you can send its definition to the remote host. After then, you can create objects in the remote host. Let’s define a new class in process B:

Object subclass: #Rectangle instanceVariableNames: 'width height'

!Rectangle methods!



width: newWidth
width := newWidth

height: newHeight

height := newHeight

! !

Then, you can export the class to process A:

remote export: Rectangle


Now, create a new Rectangle, in process A, executing the following code in process B:

remote execute: 'rect := Rectangle new. rect width: 100. rect height: 20'


The execute method sends an string, that is executed in the remote machine. You can receive serialized objects. Again, executing in process B:

rect := remote evaluate: 'rect'.

rect width: 200.
rect height: 30

The evaluate method sends an string to process A, evaluate it, and the result (the Rectangle object) is serialized and reified (a copy) in process B. Then, the changes in size are evaluate in the copy at process B. But you have other choice: retrieves a proxy to the rect, that still resides in Process A:

rect2 := remote evaluate: 'rect asRemote'.
rect2 width: 300.
rect2 height: 40

asRemote is the key: instead of returning the serialized object, it returns a reference to the remote object residing in process A. The changes to rect2 size are sent and executed in the remote object environment.

Summary, with these classes and methods,  you can:

– Create a host, and connect to it via from other process/machine.

– Send a string to be executed by the remote host

– Export a local class definition to remote host

– Evaluate an expression at remote host and retrieved its serialized result

– Evaluate an expression at remote host and retrieve its result as a remote object accesible via a proxy

I should write a use case of this functionality.

Keep tuned!

Angel “Java” Lopez


3 thoughts on “Distributed Objects in AjTalk

  1. Pingback: Experimentos Distribuidos - Angel "Java" Lopez

  2. Pingback: Programming Languages, Distributed Computing and Artificial Intelligence « Angel ”Java” Lopez on Blog

  3. Pingback: Lenguajes de Programación, Computación Distribuida, Inteligencia Artificial - Angel "Java" Lopez

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