当前位置: 首页>>代码示例>>Scala>>正文


Scala UUIDs类代码示例

本文整理汇总了Scala中com.datastax.driver.core.utils.UUIDs的典型用法代码示例。如果您正苦于以下问题:Scala UUIDs类的具体用法?Scala UUIDs怎么用?Scala UUIDs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UUIDs类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: UUIDV1Generator

//设置package包名称以及导入依赖的类
package me.ivanyu.pg_uuids_v1_compare

import java.util.UUID

import com.datastax.driver.core.utils.UUIDs

class UUIDV1Generator(unixTimestamp: Long) {
  import UUIDV1Generator._

  UUIDs.timeBased()

  private var generations = 0
  private var lastTimestamp = fromUnixTimestamp(unixTimestamp)

  def generate(): UUID = {
    generations += 1
    if (generations == 10001)
      throw new IllegalStateException("Not more than 10000 version 1 UUIDs per one UNIX timestamp.")

    new UUID(makeMSB(getCurrentTimestamp), CLOCK_SEQ_AND_NODE)
  }

  private def getCurrentTimestamp: Long = {
    val result = lastTimestamp
    lastTimestamp += 1
    result
  }
}

object UUIDV1Generator {
  private val CLOCK_SEQ_AND_NODE = {
    val field = classOf[UUIDs].getDeclaredField("CLOCK_SEQ_AND_NODE")
    field.setAccessible(true)
    field.getLong(null)
  }

  private def fromUnixTimestamp(tstamp: Long): Long = {
    val method = classOf[UUIDs].getDeclaredMethod("fromUnixTimestamp", classOf[Long])
    method.setAccessible(true)
    method.invoke(null, tstamp.asInstanceOf[AnyRef]).asInstanceOf[Long]
  }

  private def makeMSB(timestamp: Long): Long = {
    val method = classOf[UUIDs].getDeclaredMethod("makeMSB", classOf[Long])
    method.setAccessible(true)
    method.invoke(null, timestamp.asInstanceOf[AnyRef]).asInstanceOf[Long]
  }
} 
开发者ID:ivanyu,项目名称:pg-uuids-v1-compare,代码行数:49,代码来源:UUIDV1Generator.scala

示例2: MonitorServiceImpl

//设置package包名称以及导入依赖的类
package org.wex.cmsfs.monitor.impl

import java.util.UUID

import akka.persistence.query.Offset
import com.datastax.driver.core.utils.UUIDs
import com.lightbend.lagom.scaladsl.api.ServiceCall
import com.lightbend.lagom.scaladsl.broker.TopicProducer
import com.lightbend.lagom.scaladsl.persistence.{EventStreamElement, PersistentEntityRegistry}
import org.wex.cmsfs.monitor.api
import org.wex.cmsfs.monitor.api._

import scala.concurrent.{ExecutionContext, Future}

class MonitorServiceImpl(registry: PersistentEntityRegistry)(implicit ec: ExecutionContext) extends MonitorService {
  override def createMonitor: ServiceCall[Monitor, Monitor] = ServiceCall { m =>
    val id = UUIDs.timeBased()
    val monitor = Monitor(Some(id), m.cron, m.mode, m.monitorId, m.connectorId, MonitorStatus.Created)
    val command = CreateMonitor(monitor)
    entityRef(id).ask(command).map(_ => monitor)
  }

  override def monitorCollectEvents = TopicProducer.taggedStreamWithOffset(MonitorEvent.Tag.allTags.toList) { (tag, offset) =>
    println(11)
    registry.eventStream(tag, offset).mapAsync(1)(p => Future{
      println(offset);
      (api.MonitorCreated(UUIDs.random(), 1, 1), offset)
    })
  }


    private def convertEvent(eventStreamElement: EventStreamElement[MonitorEvent]): Future[(api.MonitorEvent, Offset)] = {
      eventStreamElement match {
        case EventStreamElement(_, MonitorCreated(m), offset) =>
          Future((api.MonitorCreated(m.id.get, m.monitorId, m.connectorId), offset))
      }
    }

  private def entityRef(id: UUID) = entityRefString(id.toString)

  private def entityRefString(id: String) = registry.refFor[MonitorEntity](id)
} 
开发者ID:shinhwazx160,项目名称:test,代码行数:43,代码来源:MonitorServiceImpl.scala

示例3: User

//设置package包名称以及导入依赖的类
package models

import java.time.temporal.ChronoUnit
import java.time.{ZoneOffset, ZonedDateTime}
import java.util.{Date, UUID}

import com.datastax.driver.core.utils.UUIDs
import models.Language.Language
import models.Task.yearAsOfJan1


case class User(name: String, password: String, timeuuid: UUID = UUIDs.timeBased())

case class Task(year: Date, lang: Language, timeuuid: UUID, name: String, description: String,
                solutionTemplate: String, referenceSolution: String, suite: String, solutionTrait: String)

object Task {
  val now = 0

  def yearAsOfJan1(ago: Int = now) =
    Date.from(ZonedDateTime.now(ZoneOffset.UTC)
      .truncatedTo(ChronoUnit.DAYS)
      .withDayOfMonth(1).withMonth(1)
      .minusYears(ago).toInstant)
}

case class NewTask(lang: Language, name: String, description: String, solutionTemplate: String,
                   referenceSolution: String, suite: String, solutionTrait: String, year: Date = yearAsOfJan1(),
                   timeuuid: UUID = UUIDs.timeBased())

object Language extends Enumeration {
  type Language = Value

  val scalaLang = Value
} 
开发者ID:DmytroOrlov,项目名称:devgym,代码行数:36,代码来源:Model.scala

示例4: EventPersistorActor

//设置package包名称以及导入依赖的类
package akkaviz.persistence

import akka.actor.{ActorRef, Actor, ActorLogging}
import akkaviz.events.EventPublisherActor.Subscribe
import akkaviz.events.{FilteringRule, Helpers}
import akkaviz.events.Helpers.actorRefToString
import akkaviz.events.types._
import akkaviz.serialization.MessageSerialization
import com.datastax.driver.core.utils.UUIDs
import io.getquill._
import io.getquill.naming._

import scala.concurrent.duration._

class EventPersistorActor(publisherRef: ActorRef) extends Actor with ActorLogging {

  import context.dispatcher

  private[this] var queue = List[ReceivedRecord]()

  private[this] val maxItemsInQueue = 20

  override def preStart(): Unit = {
    super.preStart()
    context.system.scheduler.schedule(30.seconds, 30.seconds, self, DoInsert)
    publisherRef ! Subscribe
  }

  override def receive: Receive = {
    case DoInsert =>
      doInsert()

    case r: ReceivedWithId if FilteringRule.isUserActor(r.actorRef) && FilteringRule.isUserActor(r.sender) =>
      val msg = MessageSerialization.render(r.message)
      val id = UUIDs.timeBased()
      val time = System.currentTimeMillis()
      val records = List(
        ReceivedRecord(id, time, actorRefToString(r.sender), To, actorRefToString(r.actorRef), msg),
        ReceivedRecord(id, time, actorRefToString(r.actorRef), From, actorRefToString(r.sender), msg)
      )
      queue ++= records
      if (queue.size >= maxItemsInQueue) {
        doInsert()
      }

    case _ => {}

  }

  private[this] case object DoInsert

  private[this] def doInsert(): Unit = {
    if (queue.nonEmpty) {
      db.run(query[ReceivedRecord].insert)(queue)
      queue = List()
    }
  }

  private[this] val db = source(new CassandraSyncSourceConfig[SnakeCase]("akkaviz.cassandra"))

} 
开发者ID:blstream,项目名称:akka-viz,代码行数:62,代码来源:EventPersistorActor.scala

示例5: PlanServiceScalaTest

//设置package包名称以及导入依赖的类
package optrak.lagomtest.plan.impl


import akka.Done
import com.datastax.driver.core.utils.UUIDs
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import optrak.lagomtest.data.Data.Product
import optrak.lagomtest.plan.PlanApplication
import optrak.lagomtest.plan.api.PlanService
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}

class PlanServiceScalaTest extends AsyncWordSpec with Matchers with BeforeAndAfterAll {

  private val server = ServiceTest.startServer(
    ServiceTest.defaultSetup
      .withCassandra(true)
  ) { ctx =>
    new PlanApplication(ctx) with LocalServiceLocator
  }

  val planService = server.serviceClient.implement[PlanService]
  val product1 = Product("product1", 1, "g1", false)

  override protected def afterAll() = server.stop()

  val planId = UUIDs.timeBased()


  "plan service" should {

    "create plan" in {
      for {
        answer <- planService.createPlan(planId).invoke("my plan")
      } yield {
        answer should ===(Done)
      }
    }

    "add product" in {
      for {
        answer <- planService.addProduct(planId).invoke(product1)
      } yield {
        answer should === (Done)
      }
    }

    "removed plan" in {
      for {
        answer <- planService.removeProduct(planId).invoke(product1.id)
      } yield {
        answer should === (Done)
      }
    }
  }
} 
开发者ID:TimPigden,项目名称:lagom-multitenant,代码行数:57,代码来源:PlanServiceScalaTest.scala

示例6: PlanReaderServiceTest

//设置package包名称以及导入依赖的类
package optrak.lagomtest.planreader.impl


import com.datastax.driver.core.utils.UUIDs
import com.lightbend.lagom.scaladsl.server.LocalServiceLocator
import com.lightbend.lagom.scaladsl.testkit.ServiceTest
import optrak.lagomtest.data.Data.{Plan, PlanDescription, Product}
import optrak.lagomtest.plan.api.{PlanImpl, PlanService}
import optrak.lagomtest.planreader.api.PlanReaderService
import org.scalatest.{AsyncWordSpec, BeforeAndAfterAll, Matchers}

class PlanReaderServiceTest extends AsyncWordSpec with Matchers with BeforeAndAfterAll {

  private val server = ServiceTest.startServer(
    ServiceTest.defaultSetup
      .withCassandra(true)
  ) { ctx =>
    new PlanReaderApplication(ctx) with LocalServiceLocator
  }

  val planService = server.serviceClient.implement[PlanService]
  val planReaderService = server.serviceClient.implement[PlanReaderService]
  val product1 = Product("product1", 1, "g1", false)

  override protected def afterAll() = server.stop()

  val planId = UUIDs.timeBased()

  implicit val mat = server.materializer

  "plan service" should {
    "create plan" in {
      for {
        created <- planService.createPlan(planId).invoke("my plan")
        addedProduct <- planService.addProduct(planId).invoke(product1)
        fromReader <- {
          Thread.sleep(2000)
          planReaderService.getPlan(planId).invoke()
        }
      } yield {
        fromReader should ===(PlanImpl(PlanDescription(planId, "my plan"), Map(product1.id -> product1)))
      }
    }
  }
} 
开发者ID:TimPigden,项目名称:lagom-multitenant,代码行数:46,代码来源:PlanReaderServiceTest.scala

示例7: TenantServiceImpl

//设置package包名称以及导入依赖的类
package optrak.lagomtest.tenant.impl

import akka.{Done, NotUsed}
import com.datastax.driver.core.utils.UUIDs
import com.lightbend.lagom.scaladsl.api.ServiceCall
import com.lightbend.lagom.scaladsl.persistence.PersistentEntityRegistry
import optrak.lagomtest.data.Data
import optrak.lagomtest.data.Data.{PlanId, TenantId}
import optrak.lagomtest.tenant
import optrak.lagomtest.tenant.api.{ModelCreated, TenantService}


class TenantServiceImpl(persistentEntityRegistry: PersistentEntityRegistry, tenantRepository: TenantRepository) extends TenantService {

  override def createTenant(tenantId: TenantId): ServiceCall[tenant.api.TenantCreationData, Done] = ServiceCall { request =>
    val ref = persistentEntityRegistry.refFor[TenantEntity](tenantId)
    ref.ask(CreateTenant(tenantId, request.description))
  }

  override def createModel(tenantId: TenantId): ServiceCall[tenant.api.ModelCreationData, ModelCreated] = ServiceCall { request =>
    val ref = persistentEntityRegistry.refFor[TenantEntity](tenantId)
    val uuid = UUIDs.timeBased()
    ref.ask(CreateModel(uuid, request.description))
  }

  override def removeModel(tenantId: TenantId, modelId: PlanId): ServiceCall[NotUsed, Done] = ServiceCall { request =>
    val ref = persistentEntityRegistry.refFor[TenantEntity](tenantId)
    ref.ask(RemoveModel(modelId))
  }

  override def getTenant(tenantId: TenantId): ServiceCall[NotUsed, Data.Tenant] = ???

  override def getAllTenants: ServiceCall[NotUsed, Seq[TenantId]] = ServiceCall { _ =>
    tenantRepository.selectAllTenants
  }


} 
开发者ID:TimPigden,项目名称:lagom-multitenant,代码行数:39,代码来源:TenantServiceImpl.scala


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