Packages

p

gopher

package gopher

Provides scala API for 'go-like' CSP channels.

Overview

see readme for quick introduction.

Usage

At first you must receive gopherApi as Akka extension:

import gopher._

.....
val gopherApi = Gopher(actorSystem)

Then you can use CPS channels with blocling operations inside go clauses:

val channel = gopherApi.makeChannel[Long]
val n = 10000
val producer = go {
 @volatile var(x,y) = (0L,1L)
 for( s <- gopherApi.select.forever) {
   case z: channel.write if (z==x) =>
              x = y
              y = x+z
              if (x > n) {
                 channel.close
                 implicitly[FlowTermination[Unit]].doExit()
              }
 }
}
val consumer = for((c,i) <- channel.zip(1 to n)) {
   Console.println(s"fib(${i})=${c}")
}
Await.ready(consumer, 10 seconds)

and defer/recover in go/goScope

goScope{
  val f = openFile(myFileName)
  defer{
    if (! recover{case ex:FileNotFoundException => Console.println("invalid fname")}) {
       f.close()
    }
  }
}
See also

gopher.GopherAPI

gopher.channels.Channel

gopher.channels.Input

gopher.channels.Output

gopher.channels.SelectorBuilder

gopher.channels.SelectFactory

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. gopher
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Package Members

  1. package channels

    Core entity is Continuated which provide iteratee-like structure for reading and writing.

    Overview

    • Input and Output provide callback-based interfaces for input/output facilities.
    • Channel provide implementation for asynchronics channels processing inside JVM.
    • SelectorBuilder is a way to create selectors.

    Internals

    Core entity is Continuated which provide iteratee-like structure for reading and writing. Instance of Continuated represent one step of computations and leave in queue inside ChannelProcessor or ChannelActor Selector transform Continuated to executed exclusive with each other within one selector. Also we have IdleDetector which determinate idle selectors and activer appropriative actions.

  2. package goasync
  3. package transputers

    transputers implementations

    transputers implementations

    See also

    gopher.transputers.TransputerSupervisor

    gopher.transputers.ReplicatedTransputer

  4. package util

Type Members

  1. class ChannelClosedException extends IllegalStateException

    throwed when channel is closed:

    throwed when channel is closed:

    • during attempt to write to closed channel.
    • during attempt to read from closed channel 'behind' last message.
  2. class Defers[T] extends AnyRef

    Construction Defers: defer/recover is alternative mechanism to exception handling, simular to one in Go language.

    Construction Defers: defer/recover is alternative mechanism to exception handling, simular to one in Go language.

    We use one hidden in go and goScope construct are transformed to withDefers usage with help of macroses.

    It is also possible to use one unsugared (as in next example), but this is a bit verbose.

    def parseCsv(fname: String): Either[String, Seq[Seq[Double]]] =
     withDefer[Either[String,Seq[Seq[Double]]]]{ d =>
       val in = Source.fromFile(fname)
       d.defer{
          var r = d.recover{
                    case FileNotFoundException => Left("fileNotFound")
                  }
          if (!r) in.close()
          d.recover {
            case ex: Throwable => Left(ex.getMessage)
          }
       }
       val retval:Either[String,Seq[Seq[Double]]] = Right{
           for( (line, nLine) <- in.getLines.toSeq zip Stream.from(1) ) yield withDefer[Seq[Double]] { d =>
              line.split(",") map { s=>
                                    d.defer{
                                     d.recover{
                                        case ex: NumberFormatException =>
                                          throw new RuntimeException(s"parse error in line ${nLine} file ${fname} ")
                                     }
                                    }
                                    s.toDouble
                                  }
           }.toSeq
         }
       retval
    }
    

  3. trait FlowTermination[-A] extends AnyRef

    FlowTermination[-A] - termination of flow.

    FlowTermination[-A] - termination of flow.

    Inside each block in select loop or select apply (once or forever) we have implicit FlowTermination entity, which we can use for exiting the loop.

    select.forever{
        case x: info.read => Console.println(s"received from info $x")
        case x: control.read => implicitly[FlowTermination[Unit]].doExit(())
    }
  4. implicit class FutureWithRead[T] extends AnyRef

    sugar for reading value from future.

  5. class GopherAPI extends AnyRef

    Api for providing access to channel and selector interfaces.

  6. class GopherImpl extends GopherAPI with Extension

    Akka extension which provide gopherApi interface

    Akka extension which provide gopherApi interface

    See also

    GopherAPI

  7. class ParTransputer extends Transputer
  8. trait SelectTransputer extends ForeverSelectorBuilder with Transputer

    Transputer, where dehaviour can be described by selector function

  9. sealed trait ThreadingPolicy extends AnyRef
  10. class Time extends AnyRef

    Time API, simular to one in golang standard library.

    Time API, simular to one in golang standard library.

    See also

    gopherApi#time

  11. trait Transputer extends AnyRef

    Reusable unit of application structure, which consists from set of input ports, set of output ports and behaviour

    Reusable unit of application structure, which consists from set of input ports, set of output ports and behaviour

    Transputers can be created as elementary behaviour, descibed by select statement and then can be combined into larger structures

    Transputers can be recovered from execeptions (i.e. transputer can be restarted or resume execution) or escalated to parent transputers or root superviser.

  12. trait TransputerLogging extends AnyRef

    mix this trait to ypu transputer for access to akka logging.

Value Members

  1. macro def asyncApply1[A, B, C](hof: ((A) => B) => C)(nf: (A) => Future[B]): Future[C]
  2. def awaitImpl[T](c: Context)(v: scala.reflect.macros.blackbox.Context.Expr[Future[T]]): scala.reflect.macros.blackbox.Context.Expr[T]
  3. implicit def compileTimeFlowTermination[A]: FlowTermination[A]
  4. def defer(x: => Unit): Unit

    pseudostatement which can be used inside go/goScope block.

    pseudostatement which can be used inside go/goScope block.

    Annotations
    @compileTimeOnly("defer/recover method usage outside go / goScope ")
  5. macro def go[T](body: T)(implicit ec: ExecutionContext): Future[T]

    starts asyncronics execution of body in provided execution context.

    starts asyncronics execution of body in provided execution context. Inside go we can use defer/recover clauses and blocked read/write channel operations.

  6. macro def goScope[T](body: T): T

    provide access to using defer/recover inside body in the current thread of execution.

  7. def recover[T](f: PartialFunction[Throwable, T]): Boolean

    can be called only from defer block.

    can be called only from defer block. If we in handling exception, try to apply f to exception and if it's applied - stop panic and return true, otherwise return false.

    f

    - partial function for recovering exception.

    returns

    true if exception was recovered, false otherwise

    Annotations
    @compileTimeOnly("defer/recover method usage outside go / goScope ")
  8. implicit def toAsyncFullReadSelectorArgument[A, B](f: (ContRead[A, B]) => Option[(In[A]) => Future[Continuated[B]]]): ReadSelectorArgument[A, B]
  9. implicit def toAsyncFullSkipSelectorArgument[A](f: (Skip[A]) => Option[Future[Continuated[A]]]): SkipSelectorArgument[A]
  10. implicit def toAsyncFullWriteSelectorArgument[A, B](f: (ContWrite[A, B]) => Option[(A, Future[Continuated[B]])]): WriteSelectorArgument[A, B]
  11. implicit def toAsyncIterable[CC[_] <: Iterable[_], A](x: CC[A]): AsyncIterable[A, CC]
  12. implicit def toAsyncNoGenReadSelectorArgument[A, B](f: (ContRead[A, B]) => (A) => Future[Continuated[B]]): ReadSelectorArgument[A, B]
  13. implicit def toAsyncNoOptSkipSelectorArgument[A](f: (Skip[A]) => Future[Continuated[A]]): SkipSelectorArgument[A]
  14. implicit def toAsyncNoOptWriteSelectorArgument[A, B](f: (ContWrite[A, B]) => (A, Future[Continuated[B]])): WriteSelectorArgument[A, B]
  15. implicit def toAsyncNoOptionReadSelectorArgument[A, B](f: (ContRead[A, B]) => (In[A]) => Future[Continuated[B]]): ReadSelectorArgument[A, B]
  16. implicit def toAsyncOption[T](x: Option[T]): AsyncOption[T]
  17. implicit def toAsyncPairReadSelectorArgument[A, B](f: (A, ContRead[A, B]) => Future[Continuated[B]]): ReadSelectorArgument[A, B]
  18. implicit def toSyncPairReadSelectorArgument[A, B](f: (A, ContRead[A, B]) => Continuated[B]): ReadSelectorArgument[A, B]
  19. implicit def toSyncReadSelectorArgument[A, B](f: (ContRead[A, B]) => (In[A]) => Continuated[B]): ReadSelectorArgument[A, B]
  20. implicit def toSyncSelectorArgument[A](f: (Skip[A]) => Continuated[A]): SkipSelectorArgument[A]
  21. implicit def toSyncWriteSelectorArgument[A, B](f: (ContWrite[A, B]) => (A, Continuated[B])): WriteSelectorArgument[A, B]
  22. object Defers
  23. object Gopher extends ExtensionId[GopherImpl] with ExtensionIdProvider

    Factory object for Akka extension

    Factory object for Akka extension

    val actorSystem = ActorSystem("myapp")
    val gopherApi = Gopher(actorSystem)
  24. object GopherAPI
  25. object GopherAPIExtensionHelper
  26. object ThreadingPolicy
  27. object Time
  28. object Transputer
  29. object withDefer

    syntax sugar, for calling Defers.

Inherited from AnyRef

Inherited from Any

Ungrouped