db4o
[ bamboo ] 16:41, Tuesday, 20 May 2008

When I joined Db4objects a few years ago my first assignment was to research and implement a decent solution for getting db4o to work on the .net platform.

There was already some investigation going on on using the Eclipse JDT API as the basis for a source to source translator which proved to be a wise choice in the long run.

Eventually sharpen was born and after a lot of love we finally reached a point where the translated c# code would look really good.

People would get really interested every time sharpen was mentioned but for several reasons it wasn't publicly available.

Until now. Hooray!

I'm really looking forward to what people will build on top of that.


[ bamboo ] 17:19, Thursday, 20 December 2007

Gaiaware has just announced the Gaia Programming Contest. A contest "... about creating an Ajax Application that will serve as a meeting place for people dedicated to solving environmental issues...".

Very good but there's more: "... no Close Source dependencies can be used which means that the end product must be compilable on Mono ...". Great!

Of course people using boo and db4o have a huge headstart. So what are you waiting for?

[ bamboo ] 09:43, Tuesday, 4 December 2007

What a great experience.

A chance to interact live with a dear friend. Free Software, Hacking, Women, Futurama, McDonalds, love spreading, Militant Atheism, Monty Python, Douglas Adams and the French Way.

Had lots of interesting exchange of ideas with Massi, ranging from "extensible parsing through composeable PEGs with  optimal performance" to Carlos CastaƱeda, Jesus Christ, meta-physics, religion and Pink Floyd. The Cryptonomicon really got me.

Got to put a face on Joachim and see how really cool Unity is.

Jeroen IKVM Frijters is a funny guy!

On Thursday I got to talk about db4o which led me to meet a few db4o users hanging around the conference.

Pedro Santos had an interesting question, how to monitor and control the usage of computational resources in a managed client/server application? In other words, how a sysadmin can make sure a specific client won't DOS the application?

For .NET servers running on Windows there are performance counters, what about Mono servers running on Linux?

I've also got to spread the gospel about boo for which I got a hugely positive response.

Thomas "Gaia" Hansen seemed to really get it and so we had lots of interesting discussions on how to take over the world boo style.

Jackson wants to hack on better nullable type support for boo!

Mark wants an extensible language where NullReferenceExceptions are impossible.

Miguel reassured me once again mcs won't be rewritten on top of the boo compiler infrastructure :)

The presentation material is here.

Looking forward to the next one.

[ bamboo ] 14:54, Tuesday, 13 November 2007

So it's official now, I'll be speaking at the Mono Summit 2007.

It will be great to see you there!

Many thanks to the great folks at db4o for sponsoring my trip.

[ bamboo ] 14:40, Tuesday, 7 August 2007

It all really started when Bob Pasker asked me if db4o worked with scala. That kind of subtext is usually all I need to start exploring another programming language. Specially one of such a tasty functional flavor.

My experiment was to port a simple time tracking application I wrote for myself some time ago from .net/boo to jvm/scala.

The application works as a tray icon that lets you right-click your way through projects and tasks. There's no reporting interface other than a REPL window that allows you to execute arbitrary code against the app's object model :)

It actually took me only a week to get it up and running on the three major platforms I work with (windows, linux and macosx) thanks to scala, db4o and swt.

My impression so far is pretty darn good.

Scala is a beautiful language.

The tight integration with java means great tools such as db4o work out of the box.

And the eclipse support goes as far as supporting eclipse plugins written in scala (niiiice).

If you do java you should really be giving scala a ride.

You can find the application at http://code.google.com/p/sttracker/.

There's a readme with instructions on how to get it running either through eclipse or ant.

Even if you dont care about the time tracking functionality at all I think the SWT REPL window should give you some fun :)

[ bamboo ] 21:58, Wednesday, 16 May 2007

Life looks good so let's consider a very simple data structure. A linked list:

   1:import System.Collections
   2:
   3:class LinkedList(IEnumerable):
   4:    
   5:    _head as Node
   6:    
   7:    def constructor(*values):
   8:        for value in values:
   9:            Add(value)
  10:    
  11:    def Add(value):
  12:        _head = Node(value, _head)
  13:        
  14:    def GetEnumerator():
  15:        node = _head
  16:        while node is not null:
  17:            yield node.Value
  18:            node = node.Next
  19:            
  20:    class Node:
  21:    
  22:        _value as object    
  23:        _next as Node
  24:        
  25:        def constructor(value, next as Node):
  26:            _value = value
  27:            _next = next
  28:
  29:        Value:
  30:            get:
  31:                return _value
  32:            
  33:        Next:
  34:            get:
  35:                return _next

Our LinkedList class can be used like this:

   1:list = LinkedList("Eric Idle",
   2:                "John Cleese",
   3:                "Graham Chapman",
   4:                "Terry Gilliam",
   5:                "Terry Jones",
   6:                "Michael Palim")
   7:for item in list:
   8:    print item

Which unsurprisingly gives the following output:

Michael Palim
Terry Jones
Terry Gilliam
Graham Chapman
John Cleese
Eric Idle

Now let's move on and store our beautifully crafted LinkedList instance with Db4o:

   1:
   2:using container = Db4oFactory.OpenFile(fname):
   3:    container.Set(list)
   4:

Some time later:

   1:
   2:using container = Db4oFactory.OpenFile(fname):
   3:    list = container.Query(LinkedList).Next()
   4:    for item in list:
   5:        print item or "<null>"
   6:

Which gives:

Michael Palim
Terry Jones
Terry Gilliam
Graham Chapman
<null>

Uh, oh... What's going on?

Activation is going on, that's what it is.

Activation is the process of populating the attributes of an object with previously stored data.

Db4o activates an object the first time it is retrieved from the database and whenever instructed to do so by the application through IObjectContainer.Activate.

During activation Db4o will also follow the references in the object graph activating any referenced objects until a configured activation depth is reached.

We can make sense of the output if we consider that Db4o has its default activation depth set to 5.

When activating the list Db4o will follow the LinkedList._head reference and activate the first node, then follow the Node._next reference and so on until it reaches the 5th node which it's not activated further and has its members set to null.

Now that we can understand the output has life gotten any easier?

Well, we can ask Db4o to activate the list to the depth of 7:

   1:
   2:using container = Db4oFactory.OpenFile(configuration, fname):
   3:    list = container.Query(LinkedList).Next()
   4:    container.Activate(list, 7)
   5:    for item in list:
   6:        print item or "<null>"

Which gives us the correct output but smells funny.

Application logic shouldn't have to worry about activation depth and all that. And how are we supposed to track the required activation depth for these dynamic object graphs?

Enter Transparent Activation.

Transparent Activation works by giving the objects in the system the responsibility of activating themselves before accessing any attribute. The activation must happen through a provided activator object which keeps track of everything needed for activation to work. The activator object is made available to any object that implements the IActivatable interface:

   1:
   2:class LinkedList(IEnumerable , IActivatable):
   3:    
   4:    _head as Node
   5:    
   6:    transient _activator as IActivator
   7:    
   8:    def constructor(*values):
   9:        for value in values:
  10:            Add(value)
  11:    
  12:    def Add(value):
  13:        Activate()
  14:        _head = Node(value, _head)
  15:        
  16:    def GetEnumerator():
  17:        Activate()
  18:        node = _head
  19:        while node is not null:
  20:            yield node.Value
  21:            node = node.Next
  22:  

  23:    def IActivatable.Bind(activator as IActivator):
  24:        _activator = activator
  25:        
  26:    def Activate():
  27:        if _activator is null: return
  28:        _activator.Activate()
  29:        

  30:    class Node(IActivatable):
  31:
  32:        _value as object
  33:
  34:        _next as Node
  35:        
  36:        transient _activator as IActivator
  37:        
  38:        def constructor(value, next as Node):
  39:            _value = value
  40:            _next = next
  41:
  42:        Value:
  43:            get:
  44:                Activate()
  45:                return _value
  46:            
  47:        Next:
  48:            get:
  49:                Activate()
  50:                return _next
  51:        

  52:        def IActivatable.Bind(activator as IActivator):
  53:            _activator = activator
  54:            
  55:        private def Activate():
  56:            if _activator is null: return
  57:            _activator.Activate()

  58:            

The application just needs to enable Transparent Activation once and then everything should work as expected (no more explicit Activate calls from the application):

   1:                    
   2:configuration = Db4oFactory.NewConfiguration()
   3:configuration.Add(TransparentActivationSupport())
   4:
   5:using container = Db4oFactory.OpenFile(configuration, fname):
   6:    list = container.Query(LinkedList).Next()
   7:    for item in list:
   8:        print item or "<null>"

Life looks better but what about all that boilerplate code that must go into the object model?

The next Db4o release will ship with an instrumentation tool capable of injecting the right IL instructions into an object model to make it Transparent Activation ready.

If you are curious to see this code in action grab it here.

In a next blog entry I'll go into how to encapsulate this logic behind a smart boo attribute.