本文整理汇总了Scala中akka.persistence.journal.Tagged类的典型用法代码示例。如果您正苦于以下问题:Scala Tagged类的具体用法?Scala Tagged怎么用?Scala Tagged使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Tagged类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: TaggingEventAdapter
//设置package包名称以及导入依赖的类
package homeworkzen.domain.utils
import akka.persistence.journal.{Tagged, WriteEventAdapter}
import homeworkzen.domain.command.message.{UnitEvent, UserCreatedEvent, UserEvent}
import homeworkzen.util.Base64
class TaggingEventAdapter extends WriteEventAdapter {
override def toJournal(event: Any): Any = event match {
case unitEvent: UnitEvent => Tagged(unitEvent, Set(unitEvent.userId.id.toString, unitEvent.unitId.id.toString))
case createdEvent: UserCreatedEvent => // add username to allow authentification query
Tagged(createdEvent, Set(createdEvent.userId.id.toString, Base64.encodeString(createdEvent.userEntry.username)))
case userEvent: UserEvent => Tagged(userEvent, Set(userEvent.userId.id.toString))
case _ => event
}
override def manifest(event: Any): String = ""
}
开发者ID:anopse,项目名称:HomeworkZen,代码行数:18,代码来源:TaggingEventAdapter.scala
示例2: AbstractAccount
//设置package包名称以及导入依赖的类
package com.franklevering.banking.domain.model.account
import java.util.UUID
import akka.persistence.PersistentActor
import akka.persistence.journal.Tagged
import com.franklevering.common.domain.event.Event
import com.franklevering.ports.adapters.http.request.handlers.CreateCheckingsAccountResponse
abstract class AbstractAccount()
case class CheckingsAccountCreated(id: UUID, balance: BigDecimal = 0.0) extends Event
case class CreateCheckingsAccount(name: String)
case class CheckingsAccount(id: UUID, balance: BigDecimal = 0.0) extends AbstractAccount ()
case class SavingsAccountCreated(id: UUID, balance: BigDecimal = 0.0) extends Event
case class CreateSavingsAccount(id: UUID)
case class SavingsAccount(id: UUID, balance: BigDecimal = 0.0) extends AbstractAccount()
case class WithdrawMoney(id: UUID, amount: BigDecimal)
case class MoneyWithdrawn(id: UUID, amount: BigDecimal) extends Event
class Account(id: UUID) extends PersistentActor {
var state: Option[AbstractAccount] = None
var balance: BigDecimal = 0.0
override def receiveRecover: Receive = {
case checkingsAccountCreated: CheckingsAccountCreated => updateState(checkingsAccountCreated)
}
override def receiveCommand: Receive = {
case createCheckingsAccount: CreateCheckingsAccount =>
persist(Tagged(CheckingsAccountCreated(id), Set("account"))) { event =>
val checkingsAccountCreatedEvent = event.payload.asInstanceOf[CheckingsAccountCreated]
updateState(checkingsAccountCreatedEvent)
sender ! CreateCheckingsAccountResponse(checkingsAccountCreatedEvent.id.toString)
}
case withdrawMoney: WithdrawMoney =>
if ((balance - withdrawMoney.amount) < 0) {
throw new Exception("Not enough funds")
}
persist(Tagged(MoneyWithdrawn(withdrawMoney.id, withdrawMoney.amount), Set("withdrawn"))) { event =>
updateState(event.payload.asInstanceOf[MoneyWithdrawn])
}
}
def updateState(evt: Event): Unit = {
evt match {
case checkingsAccountCreated: CheckingsAccountCreated =>
state = Some(CheckingsAccount(checkingsAccountCreated.id, checkingsAccountCreated.balance))
balance = checkingsAccountCreated.balance
}
}
override def persistenceId: String = s"account-$id"
}
开发者ID:frankieleef,项目名称:banking,代码行数:59,代码来源:Account.scala
示例3: ActorEventAdapter
//设置package包名称以及导入依赖的类
package im.actor.server.cqrs
import akka.actor.ExtendedActorSystem
import akka.persistence.journal.{ Tagged, EventSeq, EventAdapter }
final class ActorEventAdapter(system: ExtendedActorSystem) extends EventAdapter {
override def manifest(event: Any): String = "V1"
override def toJournal(event: Any): Any = {
event match {
case e: TaggedEvent ? Tagged(e, e.tags)
case _ ? event
}
}
override def fromJournal(event: Any, manifest: String): EventSeq =
event match {
case e: AnyRef ? EventSeq(e)
case _ ? throw new IllegalArgumentException(s"Supported AnyRef but got: ${event.getClass}")
}
}
开发者ID:wex5,项目名称:dangchat-server,代码行数:23,代码来源:ActorEventAdapter.scala
示例4: CreateProduct
//设置package包名称以及导入依赖的类
package module9
import akka.actor._
import akka.persistence._
import java.util.Date
// commands
final case class CreateProduct(name: String, description: String)
// events
trait DomainEvent { val occurredOn = new Date() }
final case class ProductCreated(productId: String, name: String, description: String)
class Product(productId: String) extends PersistentActor {
override def persistenceId = productId
var state: Option[ProductState] = None
override def receiveCommand: Receive = {
case command: CreateProduct =>
persist(ProductCreated(productId, command.name, command.description)) { event =>
updateWith(event)
}
}
override def receiveRecover: Receive = {
case event: ProductCreated =>
updateWith(event)
}
def updateWith(event: ProductCreated) {
state = Some(ProductState(event.name, event.description))
}
}
protected final case class ProductState(name: String, description: String)
import akka.persistence.journal.{Tagged, WriteEventAdapter}
class ProductEventsTaggingAdapter extends WriteEventAdapter {
override def manifest(event: Any): String = ""
override def toJournal(event: Any): Any = {
println(s"TAGGING product: $event")
Tagged(event, Set("product"))
}
}
开发者ID:byu-oit,项目名称:paul-akka-training-sandbox,代码行数:49,代码来源:Product.scala
示例5: TagWriterEventAdapter
//设置package包名称以及导入依赖的类
package backend
import akka.persistence.journal.{ Tagged, WriteEventAdapter }
import model.write.Order
import model.write.OrderProtocol.OrderEvent
class TagWriterEventAdapter extends WriteEventAdapter {
def manifest(event: Any): String = ""
def toJournal(event: Any): Any = {
event match {
// Order events get tagged with Order tag!
case evt: OrderEvent => Tagged(evt, Set(Order.tag.value))
// other events are not tagged
case evt => evt
}
}
}
开发者ID:strongtyped,项目名称:fun-cqrs-order-demo,代码行数:22,代码来源:TagWriterEventAdapter.scala
示例6: OrderTaggingEventAdapter
//设置package包名称以及导入依赖的类
package poc.persistence.write
import java.nio.charset.Charset
import akka.actor.ExtendedActorSystem
import akka.event.Logging
import akka.persistence.journal.{Tagged, WriteEventAdapter}
import org.json4s.DefaultFormats
import poc.persistence.events.{OrderCancelled, OrderInitialized}
class OrderTaggingEventAdapter(actorSystem: ExtendedActorSystem) extends WriteEventAdapter {
private val log = Logging.getLogger(actorSystem, this)
override def toJournal(event: Any): Any = event match {
case e: OrderInitialized =>
log.debug("tagging OrderInitialized event")
Tagged(e, Set("UserEvent"))
case e: OrderCancelled =>
log.debug("tagged OrderCancelled event")
Tagged(e, Set("UserEvent"))
}
override def manifest(event: Any): String = ""
}
import akka.serialization.Serializer
class EventSerialization(actorSystem: ExtendedActorSystem) extends Serializer {
import org.json4s.jackson.Serialization.{read, write}
private val log = Logging.getLogger(actorSystem, this)
val UTF8: Charset = Charset.forName("UTF-8")
implicit val formats = DefaultFormats
// Completely unique value to identify this implementation of Serializer, used to optimize network traffic.
// Values from 0 to 16 are reserved for Akka internal usage.
// Make sure this does not conflict with any other kind of serializer or you will have problems
override def identifier: Int = 90020001
override def includeManifest = true
override def fromBinary(bytes: Array[Byte], manifestOpt: Option[Class[_]]): AnyRef = {
implicit val manifest = manifestOpt match {
case Some(x) => Manifest.classType(x)
case None => Manifest.AnyRef
}
val str = new String(bytes, UTF8)
val result = read(str)
result
}
override def toBinary(o: AnyRef): Array[Byte] = {
val jsonString = write(o)
val dat = write(o).getBytes(UTF8)
dat
}
}
开发者ID:logicaalternativa,项目名称:akka-persistence-POC,代码行数:62,代码来源:Infrastructure.scala
示例7: TaggingEventAdapter
//设置package包名称以及导入依赖的类
package de.htw.pgerhard
import akka.persistence.journal.{Tagged, WriteEventAdapter}
import de.htw.pgerhard.domain.users.events._
import de.htw.pgerhard.domain.tweets.events._
class TaggingEventAdapter extends WriteEventAdapter {
override def toJournal(event: Any): Any = event match {
case ev: UserRegisteredEvent ? Tagged(event, Set("user-event", "user-registered"))
case ev: UserNameSetEvent ? Tagged(event, Set("user-event", "user-name-set"))
case ev: UserSubscriptionAddedEvent ? Tagged(event, Set("user-event", "user-subscription-added"))
case ev: UserSubscriptionRemovedEvent ? Tagged(event, Set("user-event", "user-subscription-removed"))
case ev: UserDeletedEvent ? Tagged(event, Set("user-event", "user-deleted"))
case ev: TweetPostedEvent ? Tagged(event, Set("tweet-event", "tweet-posted"))
case ev: TweetRepostedEvent ? Tagged(event, Set("tweet-event", "tweet-reposted"))
case ev: TweetRepostDeletedEvent ? Tagged(event, Set("tweet-event", "tweet-repost-deleted"))
// case ev: TweetLikedEvent ? Tagged(event, Set("tweet-event", "tweet-liked"))
// case ev: TweetUnLikedEvent ? Tagged(event, Set("tweet-event", "tweet-unliked"))
case ev: TweetDeletedEvent ? Tagged(event, Set("tweet-event", "tweet-deleted"))
case _ ? event
}
override def manifest(event: Any): String = ""
}
开发者ID:peter-gerhard,项目名称:my-twitter-playground,代码行数:29,代码来源:TaggingEventAdapter.scala
示例8: ProtobufDatamodelAdapter
//设置package包名称以及导入依赖的类
package com.packt.masteringakka.bookstore.common
import akka.persistence.journal.EventAdapter
import akka.persistence.journal.EventSeq
import com.google.protobuf.Message
import akka.persistence.journal.Tagged
class ProtobufDatamodelAdapter extends EventAdapter{
override def manifest(event:Any) = event.getClass.getName
override def toJournal(event:Any) = event match {
case ev:EntityEvent with DatamodelWriter =>
val message = ev.toDatamodel
//Add tags for the entity type and the event class name
val eventType = ev.getClass.getName().toLowerCase().split("\\$").last
Tagged(message, Set(ev.entityType, eventType))
case _ => throw new RuntimeException(s"Protobuf adapter can't write adapt type: $event")
}
override def fromJournal(event:Any, manifest:String) = {
event match{
case m:Message =>
//Reflect to get the companion for the domain class that was serialized and then
//use that to perform the conversion back into the domain model
val reader = Class.forName(manifest + "$").getField("MODULE$").get(null).asInstanceOf[DatamodelReader]
reader.
fromDatamodel.
lift(m).
map(EventSeq.single).
getOrElse(throw readException(event))
case _ => throw readException(event)
}
}
private def readException(event:Any) = new RuntimeException(s"Protobuf adapter can't read adapt for type: $event")
}
开发者ID:PacktPublishing,项目名称:Mastering-Akka,代码行数:41,代码来源:ProtobufDatamodelAdapter.scala
注:本文中的akka.persistence.journal.Tagged类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论