本文整理汇总了Scala中java.util.concurrent.CopyOnWriteArrayList类的典型用法代码示例。如果您正苦于以下问题:Scala CopyOnWriteArrayList类的具体用法?Scala CopyOnWriteArrayList怎么用?Scala CopyOnWriteArrayList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CopyOnWriteArrayList类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Server
//设置package包名称以及导入依赖的类
package ren.wenchao.code.collect
import java.util.concurrent.CopyOnWriteArrayList
import akka.actor.{Actor, ActorRef, ActorSystem, Props}
import akka.event.{Logging, LoggingAdapter}
import ren.wenchao.code.collect.Client.ClientInfo
class Server extends Actor {
private val clients: CopyOnWriteArrayList[ClientInfo] = new CopyOnWriteArrayList[ClientInfo]()
private val logging: LoggingAdapter = Logging(context.system, this)
override def receive: Receive = {
case startServerMsg => {
logging.info("server start...")
}
case ClientRegisterMsg(clientInfo) => {
logging.info("client register, client info :{}", clientInfo)
clients.add(clientInfo)
}
case ClientUnRegisterMsg(clientInfo) => {
logging.info("client unregister, clinet info:{}", clientInfo)
clients.remove(clientInfo)
}
}
}
object Server {
def main(args: Array[String]) {
val serverSystem: ActorSystem = ActorSystem("Server")
val server: ActorRef = serverSystem.actorOf(Props(classOf[Server]), name = "server")
server ! StartServerMsg
}
}