Skip to content

Instantly share code, notes, and snippets.

Avatar

Some Dude ericacm

View GitHub Profile
View startThread.scala
def startThread(name: String)(thunk: => Unit): Thread = {
val t = new Thread(name) {
override def run() { thunk }
}
t.setDaemon(true)
t.start()
t
}
View startServer.scala
def startServer(serverStartFunc: () => Unit) {
val serverStarted = new Semaphore(0)
var serverStartException: Option[Exception] = None
startThread("startZookeeper") {
try {
log.info("Starting ZooKeeper server. clientPort=" + clientPort +
" class=" + zkServer.getClass.getName)
serverStartFunc()
serverStarted.release()
View genServerNames.scala
/**
* hosts(i) corresponds to serversKey(i) and serversVal(i)
*
* hosts are "hostname:port" (same as cluster nodeId).
* Note: port is the server's client port. port+1 and port+2 are used for serversVal.
*
* serversKey are "server.1" (see Zookeeper Admin Guide)
* serversVal are "hostname:nnnn:nnnn"
*/
case class ServerNames(hosts: IndexedSeq[String],
View rmdir.scala
def rmdir(dir: File) {
if (dir.isDirectory) {
for (entry <- dir.listFiles()) {
if (entry.isDirectory) {
rmdir(entry)
entry.delete()
}
entry.delete()
}
dir.delete()
View serverInitialize.scala
class ZookeeperService(hostInfo: HostInfo)
extends ClusterService with EmbeddedZookeeper with Logging {
// For Standalone use the hostname, eg. localhost
// For Replicated use hostname:port,hostname:port,...
@Value("${zookeeperService.hosts:localhost}")
var hosts: String = _
// This node's ZK server client port
def clientPort: Int = hostInfo.appBasePort + 1
View configureServer.scala
def configureServer(serverNames: ServerNames): () => Unit = {
// Recreate data directory
if (dataDir == null || dataDir == "") {
dataDir = "./zookeeper-" + nodeId
}
val dir = new File(dataDir)
log.info("(Re)creating data directory: " + dataDir)
rmdir(dir)
dir.mkdirs()
View EmbeddedZookeeper.scala
import org.apache.zookeeper.server.quorum.{QuorumPeerMain => ApacheQuorumPeerMain}
import org.apache.zookeeper.server.{ZooKeeperServerMain => ApacheZookeeperServerMain}
trait EmbeddedZookeeper {
this: ClusterService with Logging =>
@Value("${zookeeperService.server.enabled:false}")
var isServerEnabled: Boolean = _
// Location of server data directory
@ericacm
ericacm / Build.scala
Created Jan 27, 2013
Build.scala for ClusterSingletonManagerSpec testing
View Build.scala
import sbt._
import Keys._
import com.typesafe.sbt.SbtMultiJvm
import com.typesafe.sbt.SbtMultiJvm.MultiJvmKeys.{ MultiJvm }
object ExampleBuild extends Build {
lazy val buildSettings = Defaults.defaultSettings ++ multiJvmSettings ++ Seq(
organization := "example",
version := "1.0",
View ZookeeperService.scala
class ZookeeperService(hostInfo: HostInfo)
extends ClusterService with EmbeddedZookeeper {
def nodeId: String = hostInfo.hostname + ":" + hostInfo.basePort + 1
@Value("${zookeeperService.client.enabled:false}")
var enabled: Boolean = _
@Value("${zookeeperService.leaderPath:/ls}")
var leaderPath: String = _
@ericacm
ericacm / nodeToWorker.scala
Last active Dec 11, 2015
Node to worker example
View nodeToWorker.scala
val participants = clusterService.clusterStatus.participants
val workers = participants.map(nodeIdToActorRef(_))
workers.foreach(_ ! nextWork())
You can’t perform that action at this time.