本文整理汇总了Scala中java.io.ObjectOutput类的典型用法代码示例。如果您正苦于以下问题:Scala ObjectOutput类的具体用法?Scala ObjectOutput怎么用?Scala ObjectOutput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObjectOutput类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: close
//设置package包名称以及导入依赖的类
package com.hindog.grid
package hadoop
import java.io.{Externalizable, ObjectInput, ObjectOutput}
import java.net.URI
import java.util.Date
import com.hindog.grid.repo.{Repository, Resource}
import org.apache.commons.io.IOUtils
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.fs._
import scala.concurrent.duration._
import scala.language.postfixOps
override def close(): Unit = {
if (fs.exists(cleanupTimestampFile)) {
try {
val timestamp = IOUtils.toString(fs.open(cleanupTimestampFile)).toLong
logger.info(s"Last jar cache auto-clean: ${new Date(timestamp)}")
if (System.currentTimeMillis() - timestamp > cleanInterval) {
cleanup()
}
} catch {
case ex: Exception => logger.warn(s"Exception while attempting to clean repository cache directory $path. ${cleanupTimestampFile.toString} possibly corrupt and needs to be removed?", ex)
}
} else {
cleanup()
}
fs.close()
}
}
object HDFSRepository {
private val defaultPath = ".jar-cache"
import HadoopEnvironment._
case class SerializableConfiguration(var conf: Configuration) extends Configuration(conf) with Externalizable {
def this() = this(new Configuration(true))
override def writeExternal(out: ObjectOutput): Unit = write(out)
override def readExternal(in: ObjectInput): Unit = readFields(in)
}
def apply(): HDFSRepository = new HDFSRepository(defaultPath, () => loadConfiguration())
def apply(path: String) = new HDFSRepository(path, () => loadConfiguration())
def apply(conf: Configuration) = new HDFSRepository(defaultPath, {
val serializable = SerializableConfiguration(conf)
() => serializable
})
}