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


Scala AggregateEventTag类代码示例

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


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

示例1: MessageEventProcessor

//设置package包名称以及导入依赖的类
package sample.helloworldconsumer.impl

import akka.Done
import com.datastax.driver.core.{BoundStatement, PreparedStatement}
import com.lightbend.lagom.scaladsl.persistence.ReadSideProcessor.ReadSideHandler
import com.lightbend.lagom.scaladsl.persistence.cassandra.{CassandraReadSide, CassandraSession}
import com.lightbend.lagom.scaladsl.persistence.{AggregateEventTag, EventStreamElement, ReadSideProcessor}

import scala.concurrent.{ExecutionContext, Future}


class MessageEventProcessor(cassandraReadSide: CassandraReadSide, cassandraSession: CassandraSession)
                           (implicit ec: ExecutionContext) extends ReadSideProcessor[MessageEvent] {

  private var insertWordStmt: PreparedStatement = _

  override def buildHandler(): ReadSideHandler[MessageEvent] = {
    cassandraReadSide.builder[MessageEvent]("message_offset")
      .setGlobalPrepare(createTable)
      .setPrepare { tags =>
        prepareStatements
      }
      .setEventHandler[MessageSaved](insertWord)
      .build()
  }

  override def aggregateTags: Set[AggregateEventTag[MessageEvent]] = Set(MessageEventTag.INSTANCE)

  private def createTable(): Future[Done] = {
    for {
      _ <- cassandraSession.executeCreateTable(
        """        CREATE TABLE IF NOT EXISTS wordcounttest (
                      words text,
                      insertion_time timestamp,
                      PRIMARY KEY (words,insertion_time)
                    )WITH CLUSTERING ORDER BY (insertion_time DESC)
        """)
    } yield Done
  }

  private def prepareStatements(): Future[Done] = {
    for {
      insert <- cassandraSession.prepare(
        """insert into wordcounttest(words ,insertion_time) values(? ,toTimestamp(now())) """)
    } yield {
      insertWordStmt = insert
      Done
    }
  }

  private def insertWord(started: EventStreamElement[MessageSaved]): Future[List[BoundStatement]] = {
    Future.successful {
     val words = started.event.msg.replaceAll("[^\\p{L}\\p{Nd}]+", " ").split(" ").toList
     words.map{ word=> insertWordStmt.bind(word) }
    }
  }

} 
开发者ID:knoldus,项目名称:lagom-scala-wordcount.g8,代码行数:59,代码来源:MessageEventProcessor.scala

示例2: BasketEntityFormats

//设置package包名称以及导入依赖的类
package demo.impl.basket

import akka.{Done, NotUsed}
import com.lightbend.lagom.scaladsl.persistence.PersistentEntity.ReplyType
import com.lightbend.lagom.scaladsl.persistence.{AggregateEvent, AggregateEventTag, PersistentEntity}
import com.lightbend.lagom.scaladsl.playjson.JsonSerializer
import demo.api.basket.{Basket, Item}
import play.api.libs.json.{Format, Json}

object BasketEntityFormats {
  implicit val addItemFormat: Format[AddItem] = Json.format
  implicit val getBasketFormat: Format[GetBasket.type] = JsonSerializer.emptySingletonFormat(GetBasket)
  implicit val itemAddedFormat: Format[ItemAdded] = Json.format
  implicit val basketEntityStateFormat: Format[BasketEntityState] = Json.format
}

trait BasketEntityCommand
case class AddItem(item: Item) extends BasketEntityCommand with ReplyType[Done]
case object GetBasket extends BasketEntityCommand with ReplyType[Basket]

case class BasketEntityState(currentBasket: Basket)
object BasketEntityState{
  val initial = BasketEntityState(Basket(Seq(), 0))
}

sealed trait BasketEntityEvent extends AggregateEvent[BasketEntityEvent] {
  override def aggregateTag = BasketEntityEvent.Tag
}

object BasketEntityEvent {
  val Tag = AggregateEventTag.sharded[BasketEntityEvent](4)
}

case class ItemAdded(item: Item) extends BasketEntityEvent

final class BasketEntity extends PersistentEntity {
  override type Command = BasketEntityCommand
  override type Event = BasketEntityEvent
  override type State = BasketEntityState

  override def initialState = BasketEntityState.initial

  override def behavior: Behavior = {
    Actions()
      .onCommand[AddItem, Done] {
        case (AddItem(item), ctx, state) =>
          ctx.thenPersist(ItemAdded(item))(_ => ctx.reply(Done))
      }
      .onReadOnlyCommand[GetBasket.type, Basket] {
        case (GetBasket, ctx, state) => ctx.reply(state.currentBasket)
      }
      .onEvent {
        case (ItemAdded(item), state) => {
          val newItems = state.currentBasket.items :+ item
          state.copy(Basket(newItems, newItems.map(_.price).sum))
        }
      }
  }
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:60,代码来源:BasketEntity.scala

示例3: aggregateTag

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

import com.lightbend.lagom.scaladsl.persistence.{AggregateEvent, AggregateEventTag}
import org.wex.cmsfs.monitor.api.Monitor
import play.api.libs.json.{Format, Json}

sealed trait MonitorEvent extends AggregateEvent[MonitorEvent] {
  override def aggregateTag = MonitorEvent.Tag
}

object MonitorEvent {
  val NumShards = 1
  val Tag = AggregateEventTag.sharded[MonitorEvent](NumShards)
}

case class MonitorCreated(monitor: Monitor) extends MonitorEvent

object MonitorCreated {
  implicit val format: Format[MonitorCreated] = Json.format
} 
开发者ID:shinhwazx160,项目名称:test,代码行数:21,代码来源:MonitorEvent.scala

示例4: ExOneService

//设置package包名称以及导入依赖的类
package com.example.exone.api

import com.lightbend.lagom.scaladsl.api.Service
import com.lightbend.lagom.scaladsl.api.broker.Topic
import com.lightbend.lagom.scaladsl.persistence.{AggregateEvent, AggregateEventTag, AggregateEventTagger}
import play.api.libs.json.{Format, Json}

object ExOneService {

  val TOPIC_NAME = "exoneEvents"

}


trait ExOneService extends Service {

  def exOneEvents(): Topic[ExOneEvent]

  override final def descriptor = {
    import Service._
    named("exonedocs").withTopics(
      topic(ExOneService.TOPIC_NAME, exOneEvents)
    ).withAutoAcl(true)
  }

}

case class ExOneEvent(id:String, value:String) extends AggregateEvent[ExOneEvent]{
  override def aggregateTag: AggregateEventTagger[ExOneEvent] = ExOneEvent.Tag
}
object ExOneEvent{
  val NumShards = 4
  val Tag = AggregateEventTag.sharded[ExOneEvent](4)
  implicit val format: Format[ExOneEvent] = Json.format[ExOneEvent]
} 
开发者ID:dsugden,项目名称:saga-lagom,代码行数:36,代码来源:ExOneService.scala

示例5: CounterEntity

//设置package包名称以及导入依赖的类
package com.example.counter.impl

import akka.Done
import com.lightbend.lagom.scaladsl.persistence.PersistentEntity.ReplyType
import com.lightbend.lagom.scaladsl.persistence.{AggregateEvent, AggregateEventTag, PersistentEntity}
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import play.api.libs.json.Json

import scala.collection.immutable.Seq

class CounterEntity extends PersistentEntity {
  type Command = CounterCommand[_]
  type Event = CounterEvent
  type State = CounterState

  def initialState = CounterState(0)

  def behavior = {
    case CounterState(_) => Actions()
      .onCommand[Add, Done] { case (Add(x), ctx, _) => ctx.thenPersist(Added(x)) { _ => ctx.reply(Done) } }
      .onReadOnlyCommand[GetState.type, Int] { case (GetState, ctx, CounterState(n)) => ctx.reply(n) }
      .onEvent { case (Added(x), CounterState(n)) => CounterState(n + x) }
  }
}

case class CounterState(n: Int)
object CounterState { implicit val format = Json.format[CounterState] }

sealed trait CounterEvent extends AggregateEvent[CounterEvent] { def aggregateTag = CounterEvent.Tag }
object CounterEvent { val Tag = AggregateEventTag[CounterEvent] }
case class Added(n: Int) extends CounterEvent
object Added { implicit val format = Json.format[Added] }

sealed trait CounterCommand[R] extends ReplyType[R]
case class Add(n: Int) extends CounterCommand[Done]
object Add { implicit val format = Json.format[Add] }
case object GetState extends CounterCommand[Int] { implicit val format = JsonSerializer.emptySingletonFormat(GetState) }

object CounterSerializerRegistry extends JsonSerializerRegistry {
  override def serializers: Seq[JsonSerializer[_]] = Seq(
    JsonSerializer[Add],
    JsonSerializer[Added],
    JsonSerializer[CounterState],
    JsonSerializer[GetState.type]
  )
} 
开发者ID:namelos,项目名称:lagom-spike,代码行数:47,代码来源:CounterEntity.scala

示例6: IdentityEvent

//设置package包名称以及导入依赖的类
package io.digitalcat.publictransportation.services.identity.impl

import java.util.UUID

import com.lightbend.lagom.scaladsl.persistence.{AggregateEvent, AggregateEventShards, AggregateEventTag}
import play.api.libs.json.{Format, Json}

object IdentityEvent {
  val NumShards = 5
  val Tag = AggregateEventTag.sharded[IdentityEvent]("IdentityEvent", NumShards)
}

sealed trait IdentityEvent extends AggregateEvent[IdentityEvent] {
  override def aggregateTag(): AggregateEventShards[IdentityEvent] = IdentityEvent.Tag
}

case class ClientCreated(company: String) extends IdentityEvent
object ClientCreated {
  implicit val format: Format[ClientCreated] = Json.format
}

case class UserCreated(userId: UUID, firstName: String, lastName: String, email: String, username: String, hashedPassword: String) extends IdentityEvent
object UserCreated {
  implicit val format: Format[UserCreated] = Json.format
} 
开发者ID:dpalinic,项目名称:lagom-jwt-authentication,代码行数:26,代码来源:IdentityEvent.scala

示例7: IdentityEventProcessor

//设置package包名称以及导入依赖的类
package io.digitalcat.publictransportation.services.identity.impl

import java.util.UUID

import akka.Done
import com.datastax.driver.core.PreparedStatement
import com.lightbend.lagom.scaladsl.persistence.ReadSideProcessor.ReadSideHandler
import com.lightbend.lagom.scaladsl.persistence.cassandra.{CassandraReadSide, CassandraSession}
import com.lightbend.lagom.scaladsl.persistence.{AggregateEventTag, EventStreamElement, ReadSideProcessor}

import scala.concurrent.{ExecutionContext, Future}

class IdentityEventProcessor(session: CassandraSession, readSide: CassandraReadSide)(implicit ec: ExecutionContext) extends ReadSideProcessor[IdentityEvent] {
  private var insertUserStatement: PreparedStatement = _
  private var reportIdToReservedUsernamesStatement: PreparedStatement = _
  private var reportIdToReservedEmailsStatement: PreparedStatement = _

  override def buildHandler(): ReadSideHandler[IdentityEvent] = {
    readSide.builder[IdentityEvent]("identityEventOffset")
      .setPrepare { tag =>
        prepareStatements()
      }.setEventHandler[UserCreated](insertUser)
      .build()
  }

  override def aggregateTags: Set[AggregateEventTag[IdentityEvent]] = {
    IdentityEvent.Tag.allTags
  }

  private def prepareStatements(): Future[Done] = {
    for {
      insertUser <- session.prepare("INSERT INTO users(id, client_id, username, email, first_name, last_name, hashed_password) VALUES (?, ?, ?, ?, ?, ?, ?)")
      reportIdToReservedUsernames <- session.prepare("UPDATE reserved_usernames SET user_id = ? WHERE username = ?")
      reportIdToReservedEmails <- session.prepare("UPDATE reserved_emails SET user_id = ? WHERE email = ?")
    } yield {
      insertUserStatement = insertUser
      reportIdToReservedUsernamesStatement = reportIdToReservedUsernames
      reportIdToReservedEmailsStatement = reportIdToReservedEmails
      Done
    }
  }

  private def insertUser(user: EventStreamElement[UserCreated]) = {
    Future.successful(
      List(
        insertUserStatement.bind(
          user.event.userId,
          UUID.fromString(user.entityId),
          user.event.username,
          user.event.email,
          user.event.firstName,
          user.event.lastName,
          user.event.hashedPassword
        ),
        reportIdToReservedUsernamesStatement.bind(user.event.userId, user.event.username),
        reportIdToReservedEmailsStatement.bind(user.event.userId, user.event.email)
      )
    )
  }
} 
开发者ID:dpalinic,项目名称:lagom-jwt-authentication,代码行数:61,代码来源:IdentityEventProcessor.scala

示例8: BlogEventProcessor

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

import com.lightbend.lagom.scaladsl.persistence.AggregateEventTag
import com.lightbend.lagom.scaladsl.persistence.ReadSideProcessor

trait BlogEventProcessorInitial {

  //#processor
  class BlogEventProcessor extends ReadSideProcessor[BlogEvent] {

    override def buildHandler(): ReadSideProcessor.ReadSideHandler[BlogEvent] = {
      // TODO build read side handler
      ???
    }

    override def aggregateTags: Set[AggregateEventTag[BlogEvent]] = {
      // TODO return the tag for the events
      ???
    }
  }
  //#processor
} 
开发者ID:lagom,项目名称:lagom,代码行数:23,代码来源:BlogEventProcessorInitial.scala

示例9: ShardedBlogEventTag

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

import com.lightbend.lagom.scaladsl.persistence.AggregateEventShards
import com.lightbend.lagom.scaladsl.persistence.AggregateEvent
import com.lightbend.lagom.scaladsl.persistence.AggregateEventTag

class ShardedBlogEventTag {

  //#sharded-tags
  object BlogEvent {
    val NumShards = 20
    val Tag = AggregateEventTag.sharded[BlogEvent](NumShards)
  }

  sealed trait BlogEvent extends AggregateEvent[BlogEvent] {
    override def aggregateTag: AggregateEventShards[BlogEvent] = BlogEvent.Tag
  }
  //#sharded-tags
} 
开发者ID:lagom,项目名称:lagom,代码行数:20,代码来源:ShardedBlogEventTag.scala

示例10: BlogEventTag

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

import com.lightbend.lagom.scaladsl.persistence.AggregateEventShards
import com.lightbend.lagom.scaladsl.persistence.AggregateEvent
import com.lightbend.lagom.scaladsl.persistence.AggregateEventTag

class BlogEventTag {

  //#aggregate-tag
  object BlogEvent {
    val BlogEventTag = AggregateEventTag[BlogEvent]
  }

  sealed trait BlogEvent extends AggregateEvent[BlogEvent] {
    override def aggregateTag: AggregateEventTag[BlogEvent] =
      BlogEvent.BlogEventTag
  }
  //#aggregate-tag
} 
开发者ID:lagom,项目名称:lagom,代码行数:20,代码来源:BlogEventTag.scala

示例11: BlogEvent

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

//#full-example
import com.lightbend.lagom.scaladsl.persistence.AggregateEvent
import com.lightbend.lagom.scaladsl.persistence.AggregateEventShards
import com.lightbend.lagom.scaladsl.persistence.AggregateEventTag
import com.lightbend.lagom.scaladsl.playjson.JsonSerializer

object BlogEvent {
  val NumShards = 20
  // second param is optional, defaults to the class name
  val Tag = AggregateEventTag.sharded[BlogEvent](NumShards)

  import play.api.libs.json._
  private implicit val postContentFormat = Json.format[PostContent]

  val serializers = Vector(
    JsonSerializer(Json.format[PostAdded]),
    JsonSerializer(Json.format[BodyChanged]),
    JsonSerializer(Json.format[PostPublished]))
}

sealed trait BlogEvent extends AggregateEvent[BlogEvent] {
  override def aggregateTag: AggregateEventShards[BlogEvent] = BlogEvent.Tag
}

final case class PostAdded(postId: String, content: PostContent) extends BlogEvent

final case class BodyChanged(postId: String, body: String) extends BlogEvent

final case class PostPublished(postId: String) extends BlogEvent
//#full-example 
开发者ID:lagom,项目名称:lagom,代码行数:33,代码来源:BlogEvent.scala

示例12: CassandraReadSideImpl

//设置package包名称以及导入依赖的类
package com.lightbend.lagom.internal.scaladsl.persistence.cassandra

import akka.Done
import akka.actor.ActorSystem
import com.datastax.driver.core.BoundStatement
import com.lightbend.lagom.internal.persistence.cassandra.CassandraOffsetStore
import com.lightbend.lagom.scaladsl.persistence.ReadSideProcessor.ReadSideHandler
import com.lightbend.lagom.scaladsl.persistence.cassandra.CassandraReadSide.ReadSideHandlerBuilder
import com.lightbend.lagom.scaladsl.persistence.cassandra.{ CassandraReadSide, CassandraSession }
import com.lightbend.lagom.scaladsl.persistence.{ AggregateEvent, AggregateEventTag, EventStreamElement }

import scala.collection.immutable
import scala.concurrent.Future
import scala.reflect.ClassTag


private[lagom] final class CassandraReadSideImpl(
  system: ActorSystem, session: CassandraSession, offsetStore: CassandraOffsetStore
) extends CassandraReadSide {

  private val dispatcher = system.settings.config.getString("lagom.persistence.read-side.use-dispatcher")
  implicit val ec = system.dispatchers.lookup(dispatcher)

  override def builder[Event <: AggregateEvent[Event]](eventProcessorId: String): ReadSideHandlerBuilder[Event] = {
    new ReadSideHandlerBuilder[Event] {
      import CassandraAutoReadSideHandler.Handler
      private var prepareCallback: AggregateEventTag[Event] => Future[Done] = tag => Future.successful(Done)
      private var globalPrepareCallback: () => Future[Done] = () => Future.successful(Done)
      private var handlers = Map.empty[Class[_ <: Event], Handler[Event]]

      override def setGlobalPrepare(callback: () => Future[Done]): ReadSideHandlerBuilder[Event] = {
        globalPrepareCallback = callback
        this
      }

      override def setPrepare(callback: (AggregateEventTag[Event]) => Future[Done]): ReadSideHandlerBuilder[Event] = {
        prepareCallback = callback
        this
      }

      override def setEventHandler[E <: Event: ClassTag](handler: EventStreamElement[E] => Future[immutable.Seq[BoundStatement]]): ReadSideHandlerBuilder[Event] = {
        val eventClass = implicitly[ClassTag[E]].runtimeClass.asInstanceOf[Class[Event]]
        handlers += (eventClass -> handler.asInstanceOf[Handler[Event]])
        this
      }

      override def build(): ReadSideHandler[Event] = {
        new CassandraAutoReadSideHandler[Event](session, offsetStore, handlers, globalPrepareCallback, prepareCallback, eventProcessorId, dispatcher)
      }
    }
  }
} 
开发者ID:lagom,项目名称:lagom,代码行数:53,代码来源:CassandraReadSideImpl.scala

示例13: JournalEntity

//设置package包名称以及导入依赖的类
package io.namelos.journal.impl

import akka.Done
import com.lightbend.lagom.scaladsl.persistence.PersistentEntity.ReplyType
import com.lightbend.lagom.scaladsl.persistence.{AggregateEvent, AggregateEventTag, PersistentEntity}
import com.lightbend.lagom.scaladsl.playjson.{JsonSerializer, JsonSerializerRegistry}
import play.api.libs.json.Json

import scala.collection.immutable.Seq

class JournalEntity extends PersistentEntity {
  type Command = JournalCommand[_]
  type Event = JournalEvent
  type State = JournalState

  def initialState = JournalState(0)

  def behavior = {
    case JournalState(_) => Actions()
      .onCommand[Add, Done] { case (Add(x), ctx, _) => ctx.thenPersist(Added(x)) { _ => ctx.reply(Done) } }
      .onReadOnlyCommand[GetState.type, Int] { case (GetState, ctx, JournalState(n)) => ctx.reply(n) }
      .onEvent { case (Added(x), JournalState(n)) => JournalState(n + x) }
  }
}

case class JournalState(n: Int)
object JournalState { implicit val format = Json.format[JournalState] }

sealed trait JournalEvent extends AggregateEvent[JournalEvent] { def aggregateTag = JournalEvent.Tag }
object JournalEvent { val Tag = AggregateEventTag[JournalEvent] }
case class Added(n: Int) extends JournalEvent
object Added { implicit val format = Json.format[Added] }

sealed trait JournalCommand[R] extends ReplyType[R]
case class Add(n: Int) extends JournalCommand[Done]
object Add { implicit val format = Json.format[Add] }
case object GetState extends JournalCommand[Int] { implicit val format = JsonSerializer.emptySingletonFormat(GetState) }

object JournalSerializerRegistry extends JsonSerializerRegistry {
  override def serializers: Seq[JsonSerializer[_]] = Seq(
    JsonSerializer[Add],
    JsonSerializer[Added],
    JsonSerializer[JournalState],
    JsonSerializer[GetState.type]
  )
} 
开发者ID:namelos,项目名称:namelos-journal,代码行数:47,代码来源:JournalEntity.scala

示例14: aggregateTag

//设置package包名称以及导入依赖的类
package com.livelygig.product.message.impl

import com.lightbend.lagom.scaladsl.persistence.{AggregateEvent, AggregateEventTag, AggregateEventTagger}
import com.lightbend.lagom.scaladsl.playjson.Jsonable
import com.livelygig.product.message.api.Message
import play.api.libs.json.Json


sealed trait MessageEvent extends AggregateEvent[MessageEvent] with Jsonable  {
  override def aggregateTag: AggregateEventTagger[MessageEvent] = MessageEvent.Tag
}

object MessageEvent {
  val NumShards = 4
  val Tag = AggregateEventTag.sharded[MessageEvent](NumShards)
}

case class MessagePosted(message: Message) extends MessageEvent

object MessagePosted {
  implicit val format = Json.format[MessagePosted]
} 
开发者ID:francescopersico,项目名称:i,代码行数:23,代码来源:MessageEvents.scala

示例15: aggregateTag

//设置package包名称以及导入依赖的类
package com.livelygig.product.user.impl

import com.lightbend.lagom.scaladsl.persistence.{AggregateEvent, AggregateEventTag, AggregateEventTagger}
import com.lightbend.lagom.scaladsl.playjson.Jsonable
import com.livelygig.product.user.api.User
import play.api.libs.json.{Format, Json}


sealed trait UserEvent extends AggregateEvent[UserEvent] with Jsonable  {
  override def aggregateTag: AggregateEventTagger[UserEvent] = UserEvent.Tag
}

object UserEvent {
  val NumShards = 4
  val Tag = AggregateEventTag.sharded[UserEvent](NumShards)
}

case class UserCreated(user: User) extends UserEvent

object UserCreated {
  implicit val format: Format[UserCreated] = Json.format
} 
开发者ID:francescopersico,项目名称:i,代码行数:23,代码来源:UserEvents.scala


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