Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Wrap getting the hflush in a method.
  • Loading branch information
harishreedharan committed Oct 3, 2014
commit a2457e4ede56a8025c8a1c4c08d3513bd4eea2c6
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.spark.streaming.storage

import java.io.Closeable
import java.lang.reflect.Method
import java.nio.ByteBuffer

import org.apache.hadoop.conf.Configuration
Expand All @@ -26,13 +27,7 @@ private[streaming] class WriteAheadLogWriter(path: String, conf: Configuration)
private val stream = HdfsUtils.getOutputStream(path, conf)
private var nextOffset = stream.getPos
private var closed = false
private val hflushMethod = {
try {
Some(classOf[FSDataOutputStream].getMethod("hflush"))
} catch {
case e: Exception => None
}
}
private val hflushMethod = getHflushMethod()

// Data is always written as:
// - Length - Long
Expand Down Expand Up @@ -65,6 +60,14 @@ private[streaming] class WriteAheadLogWriter(path: String, conf: Configuration)
hflushMethod.foreach(_.invoke(stream))
}

private def getHflushMethod(): Option[Method] = {
try {
Some(classOf[FSDataOutputStream].getMethod("hflush"))
} catch {
case e: Exception => None
}
}

private def assertOpen() {
HdfsUtils.checkState(!closed, "Stream is closed. Create a new Writer to write to file.")
}
Expand Down