Skip to content

Instantly share code, notes, and snippets.

View remeniuk's full-sized avatar

Vasil Remeniuk remeniuk

View GitHub Profile
@remeniuk
remeniuk / gist:657953
Created November 1, 2010 10:25
case object PingObject and case class PingClass desugared
[[syntax trees at end of cleanup]]// Scala source: app.scala
package <empty> {
@serializable final case class PingObject extends java.lang.Object with ScalaObject with Product {
def productIterator(): Iterator = scala.Product$class.productIterator(PingObject.this);
@deprecated("use productIterator instead") def productElements(): Iterator = scala.Product$class.productElements(PingObject.this);
final override def toString(): java.lang.String = "PingObject";
override def productPrefix(): java.lang.String = "PingObject";
override def productArity(): Int = 0;
override def productElement(x$1: Int): java.lang.Object = {
<synthetic> val temp1: Int = x$1;
sealed trait Base[T] {
val s: Option[String]
def copy(s: Option[String]) : T
}
case class CaseClass(override val s: Option[String] = None) extends Base[CaseClass] {
override def copy(s: Option[String]) = CaseClass(s)
}
def method[T <: Base[T]](base : Base[T]): T = {
@remeniuk
remeniuk / gist:708616
Created November 21, 2010 10:06
Futures with local actors
class SimpleActor extends Actor {
def receive = {
case message: String =>
log.info("STARTED: %s @ %s" format(message, self.uuid))
Thread.sleep(3000)
self.reply_?("[%s] received %s" format(self.uuid, message))
log.info("FINISHED: %s @ %s" format(message, self.uuid))
}
}
@remeniuk
remeniuk / gist:708619
Created November 21, 2010 10:11
Futures with remote actors
class SimpleActor extends Actor {
def receive = {
case message: String =>
log.info("STARTED: %s @ %s" format(message, self.uuid))
Thread.sleep(3000)
self.reply_?("[%s] received %s" format(self.uuid, message))
log.info("FINISHED: %s @ %s" format(message, self.uuid))
}
}
/**
* Registers reference to the actor (RemoteActorRef) at remote registry,
* so that the reference can be picked from the registry just like the other
* local actors
*/
case class RegisterActor(actor: ActorLink)
/**
* Unregisters reference to the actor from remote registry
*/
case class UnregisterActor(actor: ActorLink)
/**
* Adds registry actor to the list of links on a remote node
*/
case class AddRegistryLink(link: RegistryLink)
/**
* Removes registry actor from the list of links on a remote node
*/
case class RemoveRegistryLink(link: RegistryLink)
neighbour { # One of the hosts in the group that has a started RegistryActor
hostname = "localhost"
port = 9999
}
case RegisterActor(actor) =>
log.debug("Registering remote actor [%s]" format(actor))
if(!isActorInRegistry(actor.uuid) && !isLinkToLocal(actor))
ActorRegistry.register( // Hack for 0.10, 1.0-M1
RemoteClient.actorFor(actor.uuid.toString, actor.className, actor.hostname, actor.port)
) // RemoteActorRefs will register themselves in 1.0-M1+
case UnregisterActor(actor) => {
log.debug("Unregistering remote actor [%s]" format(actor))
ActorRegistry.foreach{act =>
case AddRegistryLink(link) =>
if(!linkedRegistries.containsKey(link))
addRegistryLink(link)
else
log.debug("Link to registry [%s] is already present" format(link))
case RemoveRegistryLink(link) => {
log.debug("Unlinking from registry [%s]" format(link))
linkedRegistries.remove(link)
/**
* Publishes all local actors as remote references to the linked registry
* when the registry link is added
*/
trait StartupActorRefsDistribution extends RegistryActor{
/**
* Adds link to remote registry, and register all local actors at there
*/
protected override def addRegistryLink(link: RegistryLink) = {