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
| /* | |
| * Topic Entity | |
| */ | |
| @Entity | |
| @Table(uniqueConstraints = Array(new UniqueConstraint(columnNames=Array("application_id", "name")))) | |
| @NamedQueries(Array( | |
| new NamedQuery(name="Topic.findAllByApplication", query="from Topic where application=:application"), | |
| new NamedQuery(name="Topic.findByApplicationAndName", query="from Topic where application=:application and name=:name") | |
| )) | |
| class Topic { |
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
| 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 |
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
| 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() |
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
| def rmdir(dir: File) { | |
| if (dir.isDirectory) { | |
| for (entry <- dir.listFiles()) { | |
| if (entry.isDirectory) { | |
| rmdir(entry) | |
| entry.delete() | |
| } | |
| entry.delete() | |
| } | |
| dir.delete() |
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
| 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 |
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
| /** | |
| * 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], |
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
| 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() |
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
| def startThread(name: String)(thunk: => Unit): Thread = { | |
| val t = new Thread(name) { | |
| override def run() { thunk } | |
| } | |
| t.setDaemon(true) | |
| t.start() | |
| t | |
| } |
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
| trait FutureCancelSupport { | |
| def cancellableFuture[T](fun: Future[T] => T)(implicit ex: ExecutionContext): (Future[T], () => Boolean) = { | |
| val p = Promise[T]() | |
| val f = p.future | |
| val funFuture = Future(fun(f)) | |
| funFuture.onComplete(p tryComplete(_)) // Akka 2.0 | |
| // p tryCompleteWith funFuture // Scala 2.10 | |
| (f, () => p.tryComplete(Left(new CancellationException))) // Akka 2.0 |
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
| /** | |
| * Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com> | |
| */ | |
| package akka.contrib.pattern | |
| import akka.actor._ | |
| import akka.remote.RemoteScope | |
| import scala.concurrent.duration._ | |
| import scala.util.Try |