• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala ExponentialBackoffRetry类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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)
} 
开发者ID:Box-Castle,项目名称:core,代码行数:42,代码来源:CastleZookeeperConfig.scala


示例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
  }

} 
开发者ID:bwsw,项目名称:cs-imp,代码行数:31,代码来源:CuratorTests.scala


示例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
  }

} 
开发者ID:gspandy,项目名称:d-rule,代码行数:51,代码来源:ZKDrlManager.scala


示例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()
      }
    })
  }
} 
开发者ID:bwsw,项目名称:bookkeeper-tutorial-scala,代码行数:59,代码来源:ZookeeperServerStartup.scala


示例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)
  }
} 
开发者ID:Box-Castle,项目名称:router,代码行数:24,代码来源:ZookeeperOffsetMetadataManagerFactory.scala


示例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()
  }

} 
开发者ID:bwsw,项目名称:imp,代码行数:32,代码来源:CuratorTests.scala


示例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() = {}
} 
开发者ID:yamrcraft,项目名称:etl-light,代码行数:41,代码来源:DLock.scala



注:本文中的org.apache.curator.retry.ExponentialBackoffRetry类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala StringTokenizer类代码示例发布时间:2022-05-23
下一篇:
Scala GraphiteReporter类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap