Created
June 23, 2017 08:48
-
-
Save jongiddy/286857e09f9881854a725634ca82b515 to your computer and use it in GitHub Desktop.
BroadcastMatcher modified to use HadoopMapReader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.admiral.barefoot_spark | |
import java.net.URI | |
import java.util.ArrayList | |
import java.util.{List => JavaList} | |
import java.util.Properties | |
import scala.collection.JavaConverters._ | |
import com.bmwcarit.barefoot.matcher.{Matcher, MatcherKState, MatcherSample} | |
import com.bmwcarit.barefoot.roadmap.{Road, RoadMap, RoadPoint, TimePriority} | |
import com.bmwcarit.barefoot.spatial.Geography | |
import com.bmwcarit.barefoot.topology.Dijkstra | |
import com.esri.core.geometry.Point | |
object BroadcastMatcher { | |
private var instance = null: Matcher | |
private def initialize(map_uri: String) { | |
// Barefoot page suggests code that uses a double-checked lock. See | |
// https://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html | |
// for why this was removed here. | |
this.synchronized { | |
if (instance == null) { | |
// initialize map matcher once per Executor (JVM process/cluster node) | |
val map = RoadMap.Load(new HadoopMapReader(new URI(map_uri))).construct() | |
val router = new Dijkstra[Road, RoadPoint]() | |
val cost = new TimePriority() | |
val spatial = new Geography() | |
instance = new Matcher(map, router, cost, spatial) | |
} | |
} | |
} | |
} | |
@SerialVersionUID(1L) | |
class BroadcastMatcher(map_uri: String) extends Serializable { | |
def mmatch(samples: JavaList[MatcherSample]): MatcherKState = { | |
mmatch(samples, 0, 0) | |
} | |
def mmatch(samples: JavaList[MatcherSample], minDistance: Double, minInterval: Int): MatcherKState = { | |
BroadcastMatcher.initialize(map_uri) | |
BroadcastMatcher.instance.mmatch(samples, minDistance, minInterval) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment