本文整理汇总了Scala中org.apache.curator.retry.ExponentialBackoffRetry类的典型用法代码示例。如果您正苦于以下问题:Scala ExponentialBackoffRetry类的具体用法?Scala ExponentialBackoffRetry怎么用?Scala ExponentialBackoffRetry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExponentialBackoffRetry类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: CastleZookeeperConfig
//设置package包名称以及导入依赖的类
package com.box.castle.core.config
import java.util.concurrent.TimeUnit.SECONDS
import com.box.castle.core.config.CastleZookeeperConfig.{DefaultConnectionTimeout,
DefaultInitialConnectTimeout, DefaultRetryPolicy, DefaultRoot, DefaultSessionTimeout}
import com.box.castle.common.Require
import org.apache.curator.RetryPolicy
import org.apache.curator.retry.ExponentialBackoffRetry
import scala.concurrent.duration.{Duration, FiniteDuration}
case class CastleZookeeperConfig(connect: String,
root: String = DefaultRoot,
sessionTimeout: Duration = DefaultSessionTimeout,
connectionTimeout: Duration = DefaultConnectionTimeout,
initialConnectTimeout: Duration = DefaultInitialConnectTimeout,
retryPolicy: RetryPolicy = DefaultRetryPolicy) {
Require.positiveDuration(sessionTimeout, "sessionTimeout")
Require.positiveDuration(connectionTimeout, "connectionTimeout")
Require.positiveDuration(initialConnectTimeout, "initialConnectTimeout")
}
object CastleZookeeperConfig {
val DefaultRoot = "castle"
val DefaultSessionTimeout = FiniteDuration(60, SECONDS)
val DefaultConnectionTimeout = FiniteDuration(15, SECONDS)
val DefaultInitialConnectTimeout = FiniteDuration(30, SECONDS)
val DefaultExponentialBackoffBaseSleepTime = FiniteDuration(1, SECONDS)
val DefaultExponentialBackoffMaxRetries: Int = 10
val DefaultExponentialBackoffMaxSleepTime = FiniteDuration(60, SECONDS)
val DefaultRetryPolicyType = "exponentialBackoff"
val DefaultRetryPolicy = new ExponentialBackoffRetry(
DefaultExponentialBackoffBaseSleepTime.toMillis.toInt,
DefaultExponentialBackoffMaxRetries,
DefaultExponentialBackoffMaxSleepTime.toMillis.toInt)
}
示例2: CuratorTests
//设置package包名称以及导入依赖的类
package com.bwsw.cloudstack.common.curator
import com.bwsw.cloudstack.imp.dao.zookeeper.ZookeeperTestServer
import com.google.common.io.Files
import org.apache.curator.framework.{CuratorFramework, CuratorFrameworkFactory}
import org.apache.curator.retry.ExponentialBackoffRetry
import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers}
class CuratorTests extends FlatSpec with Matchers with BeforeAndAfterAll {
System.getProperty("java.io.tmpdir", "./target/")
val ZOOKEEPER_PORT = 21810
var zk: ZookeeperTestServer = null
implicit var curator: CuratorFramework = null
override def beforeAll() = {
zk = new ZookeeperTestServer(ZOOKEEPER_PORT, Files.createTempDir().toString)
curator = CuratorFrameworkFactory.builder()
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
.namespace("tests")
.connectString(s"127.0.0.1:$ZOOKEEPER_PORT").build()
curator.start()
}
override def afterAll() = {
curator.close()
zk.stop
}
}
示例3: ZKDrlManager
//设置package包名称以及导入依赖的类
package com.muziyuchen.drule.zk
import org.apache.curator.framework.{CuratorFramework, CuratorFrameworkFactory}
import org.apache.curator.framework.recipes.cache.{PathChildrenCache, PathChildrenCacheEvent, PathChildrenCacheListener}
import org.apache.curator.retry.ExponentialBackoffRetry
import scala.collection.mutable
import scala.collection.JavaConversions._
private[zk] class ZKDrlManager(connectString: String, path: String) {
private var client: CuratorFramework = _
private var cache: PathChildrenCache = _
def start: Unit = {
client = CuratorFrameworkFactory.newClient(connectString, new ExponentialBackoffRetry(1000, 3))
client.start
client.blockUntilConnected
cache = new PathChildrenCache(client, path, true)
cache.start(PathChildrenCache.StartMode.BUILD_INITIAL_CACHE)
}
def getDrls: mutable.MutableList[String] = {
var drls = new mutable.MutableList[String]()
for (childData <- cache.getCurrentData) {
val drl = new String(childData.getData(), "UTF-8")
drls += drl
}
drls
}
def drlChanged(callback: () => Unit): Unit = {
cache.getListenable.addListener(new PathChildrenCacheListener {
override def childEvent(client: CuratorFramework, event: PathChildrenCacheEvent): Unit = {
callback
}
})
}
def close:Unit = {
cache.close
client.close
}
}
示例4: 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()
}
})
}
}
示例5: ZookeeperOffsetMetadataManagerFactory
//设置package包名称以及导入依赖的类
package com.box.castle.consumer.offsetmetadatamanager
import java.nio.file.Path
import java.util.concurrent.TimeUnit._
import kafka.consumer.SimpleConsumer
import org.apache.curator.RetryPolicy
import org.apache.curator.retry.ExponentialBackoffRetry
import scala.concurrent.duration.{FiniteDuration, Duration}
class ZookeeperOffsetMetadataManagerFactory(rootNameSpace: Path,
connectionEndpoint: String,
retryPolicy: RetryPolicy = new ExponentialBackoffRetry(1500, 3),
initialConnectionTimeout: Duration = FiniteDuration(10, SECONDS),
connectionTimeout: Duration = FiniteDuration(10, SECONDS),
sessionTimeout: Duration = FiniteDuration(30, SECONDS))
extends OffsetMetadataManagerFactory {
def create(consumer: SimpleConsumer): ZookeeperOffsetMetadataManager = {
new ZookeeperOffsetMetadataManager(rootNameSpace, connectionEndpoint, retryPolicy,
initialConnectionTimeout, connectionTimeout, sessionTimeout)
}
}
示例6: CuratorTests
//设置package包名称以及导入依赖的类
package com.bwsw.imp.curator
import org.apache.curator.framework.{CuratorFramework, CuratorFrameworkFactory}
import org.apache.curator.retry.ExponentialBackoffRetry
import org.apache.curator.test.TestingServer
import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers}
class CuratorTests extends FlatSpec with Matchers with BeforeAndAfterAll {
val ZOOKEEPER_PORT = 21810
var testingServer = new TestingServer(ZOOKEEPER_PORT)
implicit var curator: CuratorFramework = _
override def beforeAll() = {
testingServer.start()
curator = CuratorFrameworkFactory.builder()
.retryPolicy(new ExponentialBackoffRetry(1000, 3))
.namespace("tests")
.connectString(s"127.0.0.1:$ZOOKEEPER_PORT").build()
curator.start()
}
it must "do nothing" in {}
override def afterAll() = {
curator.close()
testingServer.stop()
}
}
示例7: DLock
//设置package包名称以及导入依赖的类
package yamrcraft.etlite.utils
import java.util.concurrent.TimeUnit
import org.apache.curator.framework.recipes.locks.InterProcessSemaphoreMutex
import org.apache.curator.framework.{CuratorFramework, CuratorFrameworkFactory}
import org.apache.curator.retry.ExponentialBackoffRetry
import org.slf4j.LoggerFactory
class DLock(zkConnect: String, lockFile: String, waitForLockSeconds: Int) {
val logger = LoggerFactory.getLogger(this.getClass)
private var zkClient: Option[CuratorFramework] = None
private var lock: Option[InterProcessSemaphoreMutex] = None
def tryLock(): Boolean = {
require(lock.isEmpty, "lock can't be reused")
logger.info("acquiring lock...")
zkClient = Some(CuratorFrameworkFactory.newClient(zkConnect, new ExponentialBackoffRetry(1000, 3)))
zkClient.get.start()
lock = Some(new InterProcessSemaphoreMutex(zkClient.get, lockFile))
lock.get.acquire(waitForLockSeconds, TimeUnit.SECONDS)
}
def release() = {
require(lock.nonEmpty, "lock wasn't acquired")
logger.info("releasing lock")
lock.foreach(_.release())
zkClient.foreach(_.close())
}
}
class FakeLock extends DLock("", "", 0) {
override def tryLock() = true
override def release() = {}
}