Skip to content

Commit

Permalink
Implemented stub support for loading the latest journal on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
djspiewak committed Aug 12, 2011
1 parent 1b186c0 commit cd9a8be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/main/scala/com/codecommit/dm/JournalComponent.scala
Expand Up @@ -12,6 +12,8 @@ trait JournalComponent {

def journal: Journal
def journalSerializer: JournalSerializer

def readInitialJournalState: JournalRep

trait Journal {
def journal: JournalRep
Expand All @@ -38,7 +40,7 @@ trait MutableJournalComponent extends JournalComponent {

override lazy val journal = new Journal {
private val lock = new AnyRef
private var _journal: JournalRep = Vector()
private var _journal: JournalRep = readInitialJournalState

def journal = _journal

Expand Down
@@ -1,7 +1,7 @@
package com.codecommit
package dm

import java.io.{OutputStream, FileOutputStream, BufferedOutputStream, IOException}
import java.io._

trait JournalPersistenceComponent extends JournalComponent {
def journalPersister: JournalPersister
Expand All @@ -23,6 +23,19 @@ trait ThreadedJournalPersistenceComponent extends JournalPersistenceComponent {
def JournalPersistenceDelay: Long

def makeJournalFilename: String
def latestJournalFilename: String

override def readInitialJournalState = {
var is: InputStream = null // gross!
try {
is = new BufferedInputStream(new FileInputStream(latestJournalFilename))
journalSerializer.read(is)
} finally {
if (is != null) {
is.close()
}
}
}

override lazy val journalPersister = new JournalPersister with AsyncWorker {
val Priority = 3
Expand Down

0 comments on commit cd9a8be

Please sign in to comment.