本文整理汇总了Scala中org.apache.zookeeper.CreateMode类的典型用法代码示例。如果您正苦于以下问题:Scala CreateMode类的具体用法?Scala CreateMode怎么用?Scala CreateMode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CreateMode类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ZookeeperServerStartup
//设置package包名称以及导入依赖的类
import java.util
import java.util.concurrent.TimeUnit
import org.apache.curator.framework.{CuratorFramework, CuratorFrameworkFactory}
import org.apache.curator.retry.ExponentialBackoffRetry
import org.apache.curator.test.TestingServer
import org.apache.zookeeper.CreateMode
import org.apache.zookeeper.ZooDefs.Ids
import org.apache.zookeeper.data.ACL
object ZookeeperServerStartup {
val port = 2181
val endpoints = s"127.0.0.1:$port"
def main(args: Array[String]): Unit = {
val zkServer = new TestingServer(port, true)
createNodes()
addShutdownHook(zkServer)
}
private def createNodes() = {
val zkClient: CuratorFramework = {
val connection = CuratorFrameworkFactory.builder()
.connectString(endpoints)
.sessionTimeoutMs(2000)
.connectionTimeoutMs(5000)
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
.build()
connection.start()
connection.blockUntilConnected(5000, TimeUnit.MILLISECONDS)
connection
}
zkClient.create()
.creatingParentsIfNeeded()
.withMode(CreateMode.PERSISTENT)
.withACL(new util.ArrayList[ACL](Ids.OPEN_ACL_UNSAFE))
.forPath(BookieServerStartup.zkLedgersRootPath)
zkClient.create()
.withMode(CreateMode.PERSISTENT)
.withACL(new util.ArrayList[ACL](Ids.OPEN_ACL_UNSAFE))
.forPath(BookieServerStartup.zkBookiesAvailablePath)
zkClient.close()
}
private def addShutdownHook(zkServer: TestingServer) = {
Runtime.getRuntime.addShutdownHook(new Thread() {
override def run(): Unit = {
zkServer.close()
}
})
}
}
示例2: SubscriberUtils
//设置package包名称以及导入依赖的类
package util
import org.apache.curator.framework.CuratorFramework
import org.apache.zookeeper.CreateMode
object SubscriberUtils {
def putSubscriberInStream(client: CuratorFramework,
path: String,
partition: Int,
subscriber: String
): Unit = {
client.create()
.creatingParentsIfNeeded()
.withMode(CreateMode.PERSISTENT)
.forPath(
s"$path/subscribers/$partition/$subscriber",
Array.emptyByteArray
)
}
def deleteSubscriberInStream(client: CuratorFramework,
path: String,
partition: Int,
subscriber: String
): Unit = {
client.delete()
.forPath(
s"$path/subscribers/$partition/$subscriber"
)
}
}
示例3: BootstrapProtocol
//设置package包名称以及导入依赖的类
package tanukkii.reactivezk.example.zookeeperbook
import akka.actor.{Props, ActorLogging, ActorRef, Actor}
import org.apache.zookeeper.CreateMode
import org.apache.zookeeper.KeeperException.Code
import org.apache.zookeeper.ZooDefs.Ids
import tanukkii.reactivezk.IdConversions
import tanukkii.reactivezk.ZKOperations.{CreateFailure, Created, Create}
import IdConversions._
object BootstrapProtocol {
case object CreateParents
case class CreateParent(path: String, data: Array[Byte])
case object ParentCreated
}
class Bootstrap(zooKeeperSession: ActorRef, supervisor: ActorRef) extends Actor with ActorLogging {
import BootstrapProtocol._
val paths = Set("/workers", "/assign", "/tasks", "/status")
var createdPaths: Set[String] = Set.empty
def receive: Receive = {
case CreateParents => {
context.become(createParent)
paths.foreach { path =>
self ! CreateParent(path, Array.empty)
}
}
}
def createParent: Receive = {
case CreateParent(path, data) => zooKeeperSession ! createParentMessage(path, Array.empty)
case Created(path, name, _) => {
createdPaths += path
log.info("Parent created at {}", path)
if (createdPaths == paths) supervisor ! ParentCreated
}
case CreateFailure(e, path, _) if e.code() == Code.CONNECTIONLOSS => self ! CreateParent(path, Array.empty)
case CreateFailure(e, path, _) if e.code() == Code.NODEEXISTS => {
createdPaths += path
log.warning("Parent already registered: {}", path)
if (createdPaths == paths) supervisor ! ParentCreated
}
case CreateFailure(e, _, _) => throw e
}
def createParentMessage(path: String, data: Array[Byte]) = Create(path, data, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT)
}
object Bootstrap {
def props(zooKeeperSession: ActorRef, supervisor: ActorRef) = Props(new Bootstrap(zooKeeperSession, supervisor))
}