All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ecfront.ez.framework.service.distributed.DCountDownLatchService.scala Maven / Gradle / Ivy

The newest version!
package com.ecfront.ez.framework.service.distributed

import java.util.concurrent.TimeUnit

import com.ecfront.ez.framework.service.redis.RedisProcessor
import com.typesafe.scalalogging.slf4j.LazyLogging

/**
  * 分布式CountDownLatch
  *
  * @param key CountDownLatch名
  */
case class DCountDownLatchService(key: String) extends LazyLogging {

  private val countDownLatch = RedisProcessor.custom().getCountDownLatch(key)

  def set(value: Long): this.type = {
    RedisProcessor.custom().getAtomicLong(key).set(value)
    this
  }

  def await(time: Long = -1, unit: TimeUnit = null): this.type = {
    if (time == -1) {
      countDownLatch.await()
    } else {
      countDownLatch.await(time, unit)
    }
    this
  }

  def get: Long = {
    countDownLatch.getCount
  }

  def countDown(): this.type = {
    countDownLatch.countDown()
    this
  }

  def delete(): this.type = {
    countDownLatch.delete()
    this
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy