1,261
社区成员
发帖
与我相关
我的任务
分享
package test
trait PartitionStrategy extends Serializable {
/** Returns the partition number for a given edge. */
def getPartition(key: Int): Int
}
object PartitionStrategy {
def fromString(s: String): PartitionStrategy = s match {
case "MetisPartition" => MetisPartition
case _ => throw new IllegalArgumentException("Invalid PartitionStrategy: " + s)
}
case object MetisPartition extends PartitionStrategy {
val metisMap =new scala.collection.mutable.HashMap[Int,Int]
def mockLoadFile() {
try {
var id = 1 ;
while(id < 10000)
{
var partition = 5 ;
metisMap.put(id, partition)
id = id +1
}
println("size: " + metisMap.size)
} catch {
case ex: Exception => { // Handle missing file
ex.printStackTrace()
}
}
}
override def getPartition(src: Int): Int = {
var s = metisMap.get(src)
if(!s.isEmpty)
return s.getOrElse(0)
else
throw new IllegalArgumentException("Metis can't find partition!")
}
}
}
package test
object TestPartition {
def main(args: Array[String]): Unit = {
try {
var mP = PartitionStrategy.fromString("MetisPartition")
println(mP.getPartition(110))
} catch {
case ex: Exception => {
ex.printStackTrace()
}
}
}
}