|
Scala example source code file (RemoteActor.scala)
The Scala RemoteActor.scala source code/* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2005-2011, LAMP/EPFL ** ** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ package scala.actors package remote /** * This object provides methods for creating, registering, and * selecting remotely accessible actors. * * A remote actor is typically created like this: * {{{ * actor { * alive(9010) * register('myName, self) * * // behavior * } * }}} * It can be accessed by an actor running on a (possibly) * different node by selecting it in the following way: * {{{ * actor { * // ... * val c = select(Node("127.0.0.1", 9010), 'myName) * c ! msg * // ... * } * }}} * * @author Philipp Haller */ object RemoteActor { private val kernels = new scala.collection.mutable.HashMap[Actor, NetKernel] /* If set to <code>null (default), the default class loader * of <code>java.io.ObjectInputStream is used for deserializing * objects sent as messages. */ private var cl: ClassLoader = null def classLoader: ClassLoader = cl def classLoader_=(x: ClassLoader) { cl = x } /** * Makes <code>self remotely accessible on TCP port * <code>port. */ def alive(port: Int): Unit = synchronized { createNetKernelOnPort(port) } private def createNetKernelOnPort(port: Int): NetKernel = { val serv = TcpService(port, cl) val kern = serv.kernel val s = Actor.self kernels += Pair(s, kern) s.onTerminate { Debug.info("alive actor "+s+" terminated") // remove mapping for `s` kernels -= s // terminate `kern` when it does // not appear as value any more if (!kernels.valuesIterator.contains(kern)) { Debug.info("terminating "+kern) // terminate NetKernel kern.terminate() } } kern } @deprecated("this member is going to be removed in a future release", "2.8.0") def createKernelOnPort(port: Int): NetKernel = createNetKernelOnPort(port) /** * Registers <code>a under Other Scala examples (source code examples)Here is a short list of links related to this Scala RemoteActor.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.