Thoughts about the Kernel API

0 views
Skip to first unread message

William la Forge

unread,
Dec 7, 2009, 10:43:36 PM12/7/09
to AgileWikiDevelopers
In the core layer, most of the heavy lifting --MUST-- be done within a journal entry, as this enables things like hot backups and data sharing via streams of journal entries. So the Kernel API should encourage this style of programming.

So the kernel should include two more traits, JournalEntry and JournalEntryFactory.

The JournalEntry trait would have an eval(TransactionContexts) method as well as a self declaration this:BlockElement =>. 

The JournalEntryFactory trait would have an exec(TransactionContexts) method and JournalEntryFactory instances would be passed as arguments to kernel.processTransaction. The exec method would call TransactionContexts.addJournalEntry(JournalEntry) to create a journal entry, initialize the journal entry, and then call TransactonContexts.evalJournalEntry(JournalEntry) to have the journal entry evaluated.

This is a bit more indirect that what we have at the moment, but it encourages the kind of programming which is mandatory in the core and application layers.

--b

William la Forge

unread,
Dec 7, 2009, 11:13:15 PM12/7/09
to AgileWikiDevelopers
Ah, the code has turned out to be quite a bit different, giving more control to the kernel.

The Journal Entry trait remains the same:

trait JournalEntry {  
  this:BlockElement =>
  def eval(context:TransactionContexts)
}

The big change is in the JournalEntryFactory, which now has 2 callback methods:

trait JournalEntryFactory {
  def createJournalEntry():JournalEntry
  def initializeJournalEntry(context:TransactionContexts,journalEntry:JournalEntry)
}

The factory now is responsible for creating and initializing a journal entry.

In the kernel, we have the following code in the processTransaction method:

          val journalEntry = journalEntryFactory.createJournalEntry()
          transactionContexts.addJournalEntry(journalEntry)
          journalEntryFactory.initializeJournalEntry(transactionContexts,journalEntry)
          journalEntry.eval(transactionContexts)

A typical invocation of kernel.processTransaction would now look like this:

          kernel.processTransaction(new SomeJournalEntryFactory(UIContext))

where UIContext supplies the journal entry factory with the particulars of a user request.

I'll check this code in once I've reworked the kernel root element test.

Bill

William la Forge

unread,
Dec 8, 2009, 12:23:51 AM12/8/09
to AgileWikiDevelopers
Leveraging on this new design, we can now block all updates made by the journal entry factory. Here's the revised code from Kernel.processTransaction:

          transactionContexts.setReadOnly(true)
          val journalEntry = journalEntryFactory.createJournalEntry()
          transactionContexts.setReadOnly(false)
          transactionContexts.addJournalEntry(journalEntry)
          transactionContexts.setReadOnly(true)
          journalEntryFactory.initializeJournalEntry(transactionContexts,journalEntry)
          transactionContexts.setReadOnly(false)
          journalEntry.eval(transactionContexts)

This is an important constraint that we were unable to implement in AW4.

Bill

William la Forge

unread,
Dec 10, 2009, 10:52:45 PM12/10/09
to AgileWikiDevelopers
Had another "ahh duh!" moment this morning and realized that the database needs to be updated when a journal entry factory is initializing a journal entry. So readOnly gets converted to a writeOnly to restrict updates to just the journal entry rolon.

Here's the revised code from processTransaction:

          transactionContexts.setWriteOnly(Timestamp.invert(startingTime))
          val journalEntry = journalEntryFactory.createJournalEntry()
          transactionContexts.addJournalEntry(journalEntry)
          journalEntryFactory.initializeJournalEntry(transactionContexts,journalEntry)
          transactionContexts.setWriteOnly(null)
          journalEntry.eval(transactionContexts)
          transactionContexts.setWriteOnly("")

Bill
Reply all
Reply to author
Forward
0 new messages