Skip to content

Commit

Permalink
Added init check to CMBlockTransferService.
Browse files Browse the repository at this point in the history
  • Loading branch information
rxin committed Sep 2, 2014
1 parent 98c668a commit 07ccf0d
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,18 @@ final class CMBlockTransferService(conf: SparkConf, securityManager: SecurityMan
/**
* Port number the service is listening on, available only after [[init]] is invoked.
*/
override def port: Int = cm.id.port
override def port: Int = {
checkInit()
cm.id.port
}

/**
* Host name the service is listening on, available only after [[init]] is invoked.
*/
override def hostName: String = cm.id.host
override def hostName: String = {
checkInit()
cm.id.host
}

/**
* Initialize the transfer service by giving it the BlockDataManager that can be used to fetch
Expand Down Expand Up @@ -76,6 +82,7 @@ final class CMBlockTransferService(conf: SparkConf, securityManager: SecurityMan
port: Int,
blockIds: Seq[String],
listener: BlockFetchingListener): Unit = {
checkInit()

val cmId = new ConnectionManagerId(hostName, port)
val blockMessageArray = new BlockMessageArray(blockIds.map { blockId =>
Expand Down Expand Up @@ -118,6 +125,7 @@ final class CMBlockTransferService(conf: SparkConf, securityManager: SecurityMan
blockId: String,
blockData: ManagedBuffer,
level: StorageLevel) {
checkInit()
val msg = PutBlock(BlockId(blockId), blockData.byteBuffer(), level)
val blockMessageArray = new BlockMessageArray(BlockMessage.fromPutBlock(msg))
val remoteCmId = new ConnectionManagerId(hostName, port)
Expand All @@ -127,6 +135,10 @@ final class CMBlockTransferService(conf: SparkConf, securityManager: SecurityMan
Duration.Inf)
}

private def checkInit(): Unit = if (cm == null) {
throw new IllegalStateException(getClass.getName + " has not been initialized")
}

private def onBlockMessageReceive(msg: Message, id: ConnectionManagerId): Option[Message] = {
logDebug("Handling message " + msg)
msg match {
Expand Down

0 comments on commit 07ccf0d

Please sign in to comment.