• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala Serialization类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: ServerActor

//设置package包名称以及导入依赖的类
package com.naoh.beef.internal.server

import akka.actor.Actor
import akka.actor.Props
import akka.serialization.Serialization
import com.naoh.beef.Beef
import com.naoh.beef.Server
import com.naoh.beef.internal.Network.ServerLocation
import com.naoh.beef.internal.ServerSelectorActor
import com.naoh.beef.proto.network.RequestChannel
import com.naoh.beef.proto.network.ServerChannel



object ServerActor {
  def props(server: Server) = Props(new ServerActor(server))
}

class ServerActor(
  server: Server
) extends Actor {
  val location = ServerLocation(server.region, self)
  val locationProto = location.toProto
  Beef(context.system).network ! ServerSelectorActor.Add(location)

  println("Server Actor Start")
  var created = 0

  override def receive: Receive = {
    case req: RequestChannel =>
      sender() ! create()
  }

  def create(): ServerChannel = {
    val ref = context.actorOf(ServerChannelActor.props(server), s"channel-$created")
    created += 1
    ServerChannel(Some(location.toProto), Serialization.serializedActorPath(ref))
  }
} 
开发者ID:naoh87,项目名称:grpc-scala-experiment,代码行数:40,代码来源:ServerActor.scala


示例2: AssemblyApp

//设置package包名称以及导入依赖的类
package csw.services.integtration.apps

import akka.actor.{Actor, ActorPath, Props}
import akka.serialization.Serialization
import csw.services.integtration.common.TestFutureExtension.RichFuture
import csw.services.location.commons.{ClusterSettings, CswCluster}
import csw.services.location.models.Connection.AkkaConnection
import csw.services.location.models.{AkkaRegistration, ComponentId, ComponentType}
import csw.services.location.scaladsl.{ActorSystemFactory, LocationServiceFactory}

object AssemblyApp {
  private val cswCluster = CswCluster.withSettings(ClusterSettings().withInterface("eth1"))

  val assemblyActorRef = ActorSystemFactory.remote.actorOf(Props[AssemblyApp], "assembly")
  val componentId      = ComponentId("assembly", ComponentType.Assembly)
  val connection       = AkkaConnection(componentId)

  val actorPath          = ActorPath.fromString(Serialization.serializedActorPath(assemblyActorRef))
  val registration       = AkkaRegistration(connection, assemblyActorRef)
  val registrationResult = LocationServiceFactory.withCluster(cswCluster).register(registration).await

  def main(args: Array[String]): Unit = {}

}

class AssemblyApp extends Actor {
  override def receive: Receive = {
    case "Unregister" => {
      AssemblyApp.registrationResult.unregister()
    }
  }
} 
开发者ID:tmtsoftware,项目名称:csw-prod,代码行数:33,代码来源:AssemblyApp.scala


示例3: JBasicLoggerActor

//设置package包名称以及导入依赖的类
package csw.services.logging.javadsl
import java.util.Optional

import akka.actor.{AbstractActor, ActorPath}
import akka.serialization.Serialization
import akka.typed.javadsl.ActorContext
import csw.services.logging.internal.JLogger
import csw.services.logging.scaladsl.LoggerImpl

import scala.compat.java8.OptionConverters.RichOptionalGeneric


abstract class JBasicLoggerActor extends AbstractActor {
  protected def maybeComponentName: Optional[String]
  protected def getLogger: ILogger = {
    val actorName = ActorPath.fromString(Serialization.serializedActorPath(getSelf)).toString
    val log       = new LoggerImpl(maybeComponentName.asScala, Some(actorName))
    new JLogger(log, getClass)
  }
}

import akka.typed.scaladsl.adapter._
abstract class JBasicLoggerTypedActor[T](actorContext: ActorContext[T])
    extends akka.typed.javadsl.Actor.MutableBehavior[T] {
  protected def maybeComponentName: Optional[String]
  protected def getLogger: ILogger = {
    val actorName = ActorPath.fromString(Serialization.serializedActorPath(actorContext.getSelf.toUntyped)).toString
    val log       = new LoggerImpl(maybeComponentName.asScala, Some(actorName))
    new JLogger(log, getClass)
  }
} 
开发者ID:tmtsoftware,项目名称:csw-prod,代码行数:32,代码来源:loggers.scala


示例4: PgAsyncSnapshotStore

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

import akka.actor.{ActorLogging, ActorSystem}
import akka.persistence.pg.{PgConfig, PgExtension}
import akka.persistence.serialization.Snapshot
import akka.persistence.{SelectedSnapshot, SnapshotMetadata, SnapshotSelectionCriteria}
import akka.serialization.{Serialization, SerializationExtension}

import scala.concurrent.Future

class PgAsyncSnapshotStore extends akka.persistence.snapshot.SnapshotStore
  with PgSnapshotStore
  with ActorLogging
  with PgConfig {

  implicit val system: ActorSystem = context.system
  implicit val executionContext = context.system.dispatcher

  override val serialization: Serialization = SerializationExtension(context.system)
  override lazy val pluginConfig = PgExtension(context.system).pluginConfig

  import driver.api._

  override def loadAsync(persistenceId: String, criteria: SnapshotSelectionCriteria): Future[Option[SelectedSnapshot]] = {
    log.debug(s"loading snapshot for persistenceId: {}, criteria: {}", persistenceId, criteria)
    selectMostRecentSnapshotFor(persistenceId, criteria)
  }

  override def saveAsync(metadata: SnapshotMetadata, snapshot: Any): Future[Unit] = {
    log.debug(s"saving snapshot for metadata {}",metadata)
    val serialized: Array[Byte] = serialization.serialize(Snapshot(snapshot)).get
    database.run(snapshotsQuery(metadata).length
      .result.flatMap { result: Int =>
        val v = (metadata.persistenceId, metadata.sequenceNr, metadata.timestamp, serialized)
        if (result > 0) {
          snapshotsQuery(metadata).update(v)
        } else {
          snapshots += v
        }
    }).map { _ => () }
  }

  override def deleteAsync(metadata: SnapshotMetadata): Future[Unit] = {
    log.debug(s"deleting: {}",metadata)
    deleteSnapshot(metadata).map { _ =>
      log.debug(s"deleted snapshot {}",metadata)
    }
  }

  override def deleteAsync(persistenceId: String, criteria: SnapshotSelectionCriteria): Future[Unit] = {
    log.debug(s"deleting for persistenceId: {} and criteria: {}",persistenceId, criteria)
    database.run(selectSnapshotsQuery(persistenceId, criteria).delete).map { deleted =>
      log.debug(s"deleted {} snapshots", deleted); ()
    }
  }

} 
开发者ID:WegenenVerkeer,项目名称:akka-persistence-postgresql,代码行数:58,代码来源:PgAsyncSnapshotStore.scala


示例5: serialization

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

import akka.persistence.pg.PgConfig
import akka.persistence.serialization.Snapshot
import akka.persistence.{SelectedSnapshot, SnapshotMetadata, SnapshotSelectionCriteria}
import akka.serialization.Serialization

import scala.concurrent.{ExecutionContext, Future}
import scala.language.postfixOps

trait PgSnapshotStore extends SnapshotTable {
  self: PgConfig =>

  def serialization: Serialization

  import driver.api._

  def snapshotsQuery(metadata: SnapshotMetadata) = {
    snapshots
      .filter(_.persistenceId === metadata.persistenceId)
      .filter(_.sequenceNr === metadata.sequenceNr)
  }

  def deleteSnapshot(metadata: SnapshotMetadata): Future[Int] = {
    database.run {
      snapshotsQuery(metadata).delete
    }
  }

  def selectMostRecentSnapshotFor(persistenceId: String, criteria: SnapshotSelectionCriteria)
                                 (implicit executionContext: ExecutionContext): Future[Option[SelectedSnapshot]] = {
    database.run {
      selectSnapshotsQuery(persistenceId, criteria)
        .sortBy(_.sequenceNr.desc)
        .take(1)
        .result.headOption
    } map {
      _ map { r =>
        SelectedSnapshot(SnapshotMetadata(r._1, r._2, r._3), serialization.deserialize(r._4, classOf[Snapshot]).get.data)
      }
    }
  }

  def selectSnapshotsQuery(persistenceId: String, criteria: SnapshotSelectionCriteria): Query[SnapshotTable, (String, Long, Long, Array[Byte]), Seq] = {
    snapshots
      .filter(_.persistenceId === persistenceId)
      .filter(_.sequenceNr <= criteria.maxSequenceNr)
      .filter(_.timestamp <= criteria.maxTimestamp)
  }

} 
开发者ID:WegenenVerkeer,项目名称:akka-persistence-postgresql,代码行数:52,代码来源:PgSnapshotStore.scala


示例6: PgSnapshotStoreSpec

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

import akka.persistence.pg.snapshot.PgSnapshotStore
import akka.persistence.pg.{PgExtension, PgConfig}
import akka.persistence.pg.util.RecreateSchema
import akka.persistence.snapshot.SnapshotStoreSpec
import akka.serialization.{Serialization, SerializationExtension}
import com.typesafe.config.ConfigFactory
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.time.{Milliseconds, Second, Span}

import scala.language.postfixOps

class PgSnapshotStoreSpec extends SnapshotStoreSpec(ConfigFactory.load("pg-application.conf"))
  with PgSnapshotStore
  with RecreateSchema
  with ScalaFutures
  with PgConfig {

  override implicit val patienceConfig = PatienceConfig(timeout = Span(1, Second), interval = Span(100, Milliseconds))

  override lazy val pluginConfig = PgExtension(system).pluginConfig
  override val serialization: Serialization = SerializationExtension(system)

  import driver.api._

  override def beforeAll() {
    database.run(recreateSchema.andThen(snapshots.schema.create)).futureValue
    super.beforeAll()
  }

  override protected def afterAll(): Unit = {
    system.terminate()
    system.whenTerminated.futureValue
    ()
  }


} 
开发者ID:WegenenVerkeer,项目名称:akka-persistence-postgresql,代码行数:40,代码来源:PgSnapshotStoreSpec.scala


示例7: jsonToAny

//设置package包名称以及导入依赖的类
package com.seancheatham.akka

import akka.serialization.Serialization
import com.google.common.io.BaseEncoding
import play.api.libs.json._

package object persistence {

  
  def jsonToAny(v: JsValue)(implicit serialization: Serialization): Any =
    serializedToAny((v \ "vt").as[String], (v \ "v").get)

  protected[persistence] def serializedToAny(typeName: String, json: JsValue)(implicit serialization: Serialization): Any = {
    typeName match {
      case "int" => json.as[Int]
      case "long" => json.as[Long]
      case "float" => json.as[Float]
      case "double" => json.as[Double]
      case "boolean" => json.as[Boolean]
      case "string" => json.as[String]
      case t =>
        val decoded = BaseEncoding.base64().decode(json.as[String])
        serialization.deserialize(decoded, t.toInt, None).get
    }
  }
  
} 
开发者ID:SeanCheatham,项目名称:akka-persistence-firebase,代码行数:28,代码来源:package.scala



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala GzipFilter类代码示例发布时间:2022-05-23
下一篇:
Scala FilePart类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap