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


Scala WeakReference类代码示例

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


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

示例1: WeakExpressionWrapper

//设置package包名称以及导入依赖的类
package com.avsystem.scex
package compiler

import scala.ref.WeakReference
import scala.util.Try


  private class WeakExpressionWrapper(exprDef: ExpressionDef, initiallyWrapped: RawExpression) extends RawExpression {
    var expressionRef = new WeakReference(initiallyWrapped)

    private def wrappedExpression: RawExpression =
      expressionRef.get match {
        case Some(expr) => expr
        case None =>
          expressionRef = new WeakReference(actuallyCompileExpression(exprDef).get)
          wrappedExpression
      }

    def apply(context: ExpressionContext[_, _]) =
      wrappedExpression.apply(context)

    def debugInfo =
      wrappedExpression.debugInfo
  }

  private def actuallyCompileExpression(exprDef: ExpressionDef) =
    super.compileExpression(exprDef)

  override protected def compileExpression(exprDef: ExpressionDef): Try[RawExpression] =
    actuallyCompileExpression(exprDef).map(new WeakExpressionWrapper(exprDef, _))
} 
开发者ID:AVSystem,项目名称:scex,代码行数:32,代码来源:WeakReferenceWrappingScexCompiler.scala

示例2: ActorSystems

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

import akka.actor.{ActorPath, ActorRef, ActorSystem}
import akka.viz.ActorCellInstrumentation

import scala.collection.breakOut
import scala.ref.WeakReference
import scala.util.Try

object ActorSystems {

  private[this] val systemReferences = scala.collection.mutable.Map[String, WeakReference[ActorSystem]]()

  def systems: scala.collection.immutable.Map[String, ActorSystem] = systemReferences.flatMap {
    case (name, ref) => ref.get.map {
      system => name -> system
    }
  }(breakOut)

  def registerSystem(system: ActorSystem): Unit = {
    systemReferences.update(system.name, WeakReference(system))
  }

  def tell(path: String, message: Any): Unit = {
    Try {
      val actorPath = ActorPath.fromString(path)
      systems.get(actorPath.address.system).foreach {
        system =>
          system.actorSelection(actorPath).tell(message, ActorRef.noSender)
      }
    }
  }

  def refreshActorState(path: String): Unit = {
    tell(path, ActorCellInstrumentation.RefreshInternalStateMsg)
  }

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


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