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


Scala ReplyType类代码示例

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


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

示例1: SaveNewMessage

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

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

import scala.collection.immutable.Seq


sealed trait MessageCommand [T] extends ReplyType[T]

case class SaveNewMessage(message: String) extends MessageCommand[Done]

object SaveNewMessage {
  implicit val formatter = Json.format[SaveNewMessage]
}

object HelloConsumerSerializerRegistry extends JsonSerializerRegistry {
  override def serializers: Seq[JsonSerializer[_]] = Seq(
    JsonSerializer[SaveNewMessage],
    JsonSerializer[MessageSaved],
    JsonSerializer[MessageState]
  )
} 
开发者ID:knoldus,项目名称:lagom-scala-wordcount.g8,代码行数:26,代码来源:MessageCommand.scala

示例2: OrderEntityFormats

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

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

object OrderEntityFormats {
  implicit val orderItemsFormat: Format[OrderItems] = Json.format
  implicit val createOrderFormat: Format[CreateOrder] = Json.format
  implicit val getOrderFormat = JsonSerializer.emptySingletonFormat(GetOrder)
  implicit val orderInitialisedFormat: Format[OrderInitialized] = Json.format
  implicit val orderStateFormat: Format[OrderState] = Json.format
}

case class OrderItems (items: Seq[String])

trait OrderCommand
case class CreateOrder(items: Seq[String]) extends OrderCommand with ReplyType[Done]
case object GetOrder extends OrderCommand with ReplyType[OrderItems]

trait OrderEvent
case class OrderInitialized(items: Seq[String]) extends OrderEvent
case class OrderState(items: Seq[String])

object OrderState {
  def empty = OrderState(Seq())
}

class Order extends PersistentEntity {
  override type Command = OrderCommand
  override type Event = OrderEvent
  override type State = OrderState

  override def initialState = OrderState.empty

  override def behavior: Behavior = Actions()
    .onCommand[CreateOrder, Done] {
      case (CreateOrder(items), ctx, state) => {
        ctx.thenPersist(OrderInitialized(items)){
          evt => ctx.reply(Done)
        }
      }
    }
    .onReadOnlyCommand[GetOrder.type, OrderItems] {
      case (GetOrder, ctx, state) => ctx.reply(OrderItems(state.items))
    }
    .onEvent{
      case (OrderInitialized(items), state) => OrderState(items)
    }
} 
开发者ID:tommpy,项目名称:demo-lagom-checkout,代码行数:53,代码来源:Order.scala

示例3: 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

示例4: StartTrip

//设置package包名称以及导入依赖的类
package com.packt.chapter11.trip.impl

import akka.Done
import com.lightbend.lagom.scaladsl.persistence.PersistentEntity.ReplyType
import com.packt.chapter11.trip.api.ReportLocation
import play.api.libs.json.{Format, Json}

sealed trait ClientCommand[R] extends ReplyType[R]
case object StartTrip extends ClientCommand[Done]
case object EndTrip extends ClientCommand[Done]
case class AddLocation(reportLocationRequest: ReportLocation) extends ClientCommand[Done]

sealed trait ClientEvent
case class TripStarted(time: Long) extends ClientEvent
case class TripEnded(time: Long) extends ClientEvent
case class LocationAdded(location: Location) extends ClientEvent

case class Location(lat: Double, lon: Double)
case class ClientState(tripInProgress: Boolean, locations: List[Location])

object Location {
  implicit val format : Format[Location] = Json.format[Location]
}
object ClientState {
  implicit val format: Format[ClientState] = Json.format
}
object TripStarted {
  implicit val format: Format[TripStarted] = Json.format
}
object TripEnded {
  implicit val format: Format[TripEnded] = Json.format
}
object LocationAdded {
  implicit val format: Format[LocationAdded] = Json.format
}
object AddLocation {
  implicit val format: Format[AddLocation] = Json.format
} 
开发者ID:PacktPublishing,项目名称:Akka-Cookbook,代码行数:39,代码来源:CommandEventState.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: BlogCommand

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

//#full-example
import com.lightbend.lagom.scaladsl.persistence.PersistentEntity.ReplyType
import akka.Done
import com.lightbend.lagom.scaladsl.playjson.JsonSerializer

sealed trait BlogCommand

object BlogCommand {
  import play.api.libs.json._
  import JsonSerializer.emptySingletonFormat

  implicit val postContentFormat = Json.format[PostContent]

  val serializers = Vector(
    JsonSerializer(Json.format[AddPost]),
    JsonSerializer(Json.format[AddPostDone]),
    JsonSerializer(emptySingletonFormat(GetPost)),
    JsonSerializer(Json.format[ChangeBody]),
    JsonSerializer(emptySingletonFormat(Publish)))
}

//#AddPost
final case class AddPost(content: PostContent) extends BlogCommand with ReplyType[AddPostDone]
//#AddPost

final case class AddPostDone(postId: String)

case object GetPost extends BlogCommand with ReplyType[PostContent]

final case class ChangeBody(body: String) extends BlogCommand with ReplyType[Done]

case object Publish extends BlogCommand with ReplyType[Done]
//#full-example 
开发者ID:lagom,项目名称:lagom,代码行数:36,代码来源:BlogCommand.scala

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

示例8: PlanCommands

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

import akka.Done
import com.lightbend.lagom.scaladsl.persistence.PersistentEntity.ReplyType
import optrak.lagomtest.data.Data._
import optrak.lagomtest.data.DataJson._
import play.api.libs.json.{Format, Json}
  
object PlanCommands {

  sealed trait PlanCommand extends ReplyType[Done]

  case class CreatePlan(planDescription: PlanDescription) extends PlanCommand

  case class AddOrUpdateProduct(planId: PlanId, product: Product) extends PlanCommand
  case class UpdateProduct(planId: PlanId, product: Product) extends PlanCommand
  case class AddProduct(planId: PlanId, product: Product) extends PlanCommand
  case class RemoveProduct(planId: PlanId, productId: ProductId) extends PlanCommand

  case class AddOrUpdateSite(planId: PlanId, site: Site) extends PlanCommand
  case class UpdateSite(planId: PlanId, site: Site) extends PlanCommand
  case class AddSite(planId: PlanId, site: Site) extends PlanCommand
  case class RemoveSite(planId: PlanId, siteId: SiteId) extends PlanCommand

  implicit def formatCreatePlan: Format[CreatePlan] = Json.format[CreatePlan]
  implicit def formatAddOrUpdateProduct: Format[AddOrUpdateProduct] = Json.format[AddOrUpdateProduct]
  implicit def formatUpdateProduct: Format[UpdateProduct] = Json.format[UpdateProduct]
  implicit def formatAddProduct: Format[AddProduct] = Json.format[AddProduct]
  implicit def formatRemoveProduct: Format[RemoveProduct] = Json.format[RemoveProduct]

  implicit def formatAddOrUpdateSite: Format[AddOrUpdateSite] = Json.format[AddOrUpdateSite]
  implicit def formatUpdateSite: Format[UpdateSite] = Json.format[UpdateSite]
  implicit def formatAddSite: Format[AddSite] = Json.format[AddSite]
  implicit def formatRemoveSite: Format[RemoveSite] = Json.format[RemoveSite]


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

示例9: createTenant

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

import akka.{Done, NotUsed}
import com.lightbend.lagom.scaladsl.api.{Service, ServiceCall}
import com.lightbend.lagom.scaladsl.persistence.PersistentEntity.ReplyType
import optrak.lagomtest.data.Data._
import optrak.lagomtest.utils.JsonFormats
import play.api.libs.json.{Format, Json}
import optrak.lagomtest.data.DataJson._

trait TenantService extends Service {

  def createTenant(tenantId: TenantId): ServiceCall[TenantCreationData, Done]

  def createModel(tenantId: TenantId): ServiceCall[ModelCreationData, ModelCreated]

  def removeModel(tenantId: TenantId, modelId: PlanId): ServiceCall[NotUsed, Done]

  def getTenant(tenantId: TenantId): ServiceCall[NotUsed, Tenant]

  def getAllTenants: ServiceCall[NotUsed, Seq[TenantId]]

  override final def descriptor = {
    import Service._

    named("product").withCalls(
      pathCall("/optrak.model.api/createTenant/:id", createTenant _),
      pathCall("/optrak.model.api/createModel/:id", createModel _),
      pathCall("/optrak.model.api/removeModel/:tenantId/:modelId", removeModel _),
      pathCall("/optrak.model.api/tenant/:id", getTenant _),
      pathCall("/optrak.model.api/tenant", getAllTenants _)

    ).withAutoAcl(true)
  }

}

sealed trait TenantApiCommand
// nb these could easily be passed in query params but in real world will have much greater data payload
case class TenantCreationData(description: String) extends TenantApiCommand with ReplyType[Done]
case class ModelCreationData(description: String) extends TenantApiCommand with ReplyType[ModelCreated]

object TenantCreationData {
  implicit def format: Format[TenantCreationData] = Json.format[TenantCreationData]
}

object ModelCreationData {
  implicit def format: Format[ModelCreationData] = Json.format[ModelCreationData]
}

// responses
case class ModelCreated(id: PlanId)

object ModelCreated {
  implicit def format: Format[ModelCreated] = Json.format[ModelCreated]
} 
开发者ID:TimPigden,项目名称:lagom-multitenant,代码行数:57,代码来源:TenantService.scala


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