SlideShare uma empresa Scribd logo
1 de 45
Actor-Based Programming,[object Object],OOP 2011,[object Object],Prof. Dr. Michael Stal,[object Object],Michael.Stal@siemens.com,[object Object]
Objectives of this Presentation,[object Object],Emphasize the Multicore Revolution and its impact on Programming,[object Object],Introduce the Actor Model,[object Object],Present Show Case using Scala,[object Object],Conclusions ,[object Object],Page 2,[object Object]
Motivation: From Single Core to Hard Core,[object Object],Multi-Core processor architectures and GPUs offer scaling-up opportunities,[object Object],But how can we harness these new hardware architectures?,[object Object],Obviously, we need to adapt our applications,[object Object],Fortunately, Multi-Threading respectively Concurrent Programming comes to our rescue ,[object Object],Page 3,[object Object]
Concurrency,[object Object],Concurrency and Performance,[object Object],When talking about improving the performance of software concurrency and multi-threadingare often considered as a promising technique for achieving this goal.,[object Object],Multi-threading can improve the“real” performance of a system on multi-processor platforms without incurring the overhead of multi-processing.,[object Object],“perceivable” performance of multi-user systems (even on a single-processor platform),[object Object]
Concurrency Practice,[object Object],Unfortunately ...,[object Object],Developing multi-threaded systems that are faster than single-threaded systems is a surprisingly non-trivial task,[object Object],some multi-threaded systems “only”run slower than their single-threaded counterparts,[object Object],most multi-threaded systems do not run at all, due to deadlocks theyproduce,[object Object]
Architectural Perspective,[object Object],Concurrency is not merely a programmer‘s choice,[object Object],Instead, it covers all abstraction layers:,[object Object],Architecture: every system needs its customized concurrency architecture,[object Object],Design: we must address issues such as synchronization and coordination,[object Object],Implementation: we need to use the right features for the right purpose,[object Object],The more a Concurrency approach supports this, the better!,[object Object],Page 6,[object Object]
Every System needs its Concurrency Architecture,[object Object],Image processing systems such as rendering farms or modalities require Pipes & Filters,[object Object],Home-automation systems work best with Concurrent Reactors,[object Object],Process control is supported by Half Sync/Half Async,[object Object],Logging servers could use self-organizing Leaders/Followers,[object Object],Mobile agents may use the Blackboard Architecture for Information Exchange,[object Object],Page 7,[object Object]
Let‘s start with Object Oriented Concurrent Programming,[object Object],Objects provide services (via methods),[object Object],... and data (members),[object Object],Static members resemble global state – beware of Singletons!,[object Object],In general, objects represent reactive (i.e., passive) entities of control,[object Object],They interoperate by method invocations or state manipulation,[object Object],User-managed threads ,[object Object],leverage multiple cores,[object Object],but handling of threads and shared resources is left to the developer,[object Object],Shared State,[object Object],Thread,[object Object],Page 8,[object Object],data,[object Object],data,[object Object],methods,[object Object],methods,[object Object],Thread,[object Object]
Challenges of (Object-Oriented) Distributed and Concurrent Programming,[object Object],A lot of pitfalls such as deadlocks and race condidions due to,[object Object],Burden of thread management,[object Object],Access to shared state,[object Object],Managing Locks,[object Object],which doesn‘t scale for large distributed systems with high numbers of objects,[object Object],Page 9,[object Object],Shared State,[object Object],data,[object Object],data,[object Object],methods,[object Object],methods,[object Object],Danger Zone,[object Object],Thread,[object Object],Thread,[object Object]
Alternative Solution: Actors ,[object Object],Actors have been introduced in the early 1970s by Hewitt for AI and Distribution:,[object Object],the Actor model is a mathematical model of concurrent computationthat treats "actors" as the universal primitives of concurrent digital computation: in response to a message that it receives, an actor can make local decisions, create more actors, send more messages, and determine how to respond to the next message received. [Hewitt, 73],[object Object],Page 10,[object Object],Available almost everywhere: Scala, Erlang, F#, Axum, Io, Clojure, Java, Akka, Smalltalk, Prolog, AAL (Asynchronous Agents Library in Visual Studio 2010),[object Object]
Properties of Actors,[object Object],According to Gul Agha, an actor,[object Object],is an autonomous, interacting component of a distributed system,[object Object],a concurrency primitive not sharing resources with other actors,[object Object],It comprises: ,[object Object],an immutable identity (name, virtual address),[object Object],a mutable local state ,[object Object],methods to manipulate local state,[object Object],a thread of control (not necessarily an OS thread),[object Object],Page 11,[object Object],Actor,[object Object],State,[object Object],thread,[object Object],method,[object Object],method,[object Object],Actors,[object Object]
Fundamentals of the Actor Model,[object Object],An actor may: ,[object Object],process messages ,[object Object],send messages,[object Object],change local state,[object Object],create new actors,[object Object],Page 12,[object Object],Actor,[object Object],State,[object Object],thread,[object Object],method,[object Object],Interface,[object Object],method,[object Object],<< create >>,[object Object],Actors,[object Object],message,[object Object]
Differences between Objects and Actors,[object Object],Objects encapsulate state and behavior,[object Object],Actors encapsulate state, behavior and execution,[object Object],Page 13,[object Object],State,[object Object],State,[object Object],thread,[object Object],method,[object Object],method,[object Object],Interface,[object Object],Interface,[object Object],method,[object Object],method,[object Object]
Asynchronous And Event-Driven Processing,[object Object],HALF SYNC / HALF ASYNC PATTERN,[object Object],Actor,[object Object],State,[object Object],Actor Mailbox =  Unique Actor Address,[object Object],thread,[object Object],method,[object Object],method,[object Object],In general,,[object Object],[object Object]
Actors react to events (i.e., message arrival),[object Object]
Request/Reply,[object Object],Request/Reply semantics by exchanging messages,[object Object],Actor must know identity of sender to reply,[object Object],Call-by-Value Method invocation semantics:,[object Object],Incoming message contains arguments,[object Object],Outgoing message contains result,[object Object],Manual solution: use tokens to correlate messages,[object Object],Page 16,[object Object],Actor 2,[object Object],Actor 1,[object Object],<<send>>,[object Object],<<send>>,[object Object],ASYNCHRONOUS COMPLETION TOKEN,[object Object]
Actors may implement the Active Object Pattern,[object Object],A client invokes a method on the proxy. The proxy returns a future to the client, and creates a method request which it passes to the scheduler. ,[object Object],The scheduler inserts the method request into the activation list (not shown here). When the method request becomes runnable, the scheduler removes it from the activation list (not shown here) and executes it. ,[object Object],The method request executes the method on the servant and writes results, if any, to the future. Clientsobtain the method’s results via the future.,[object Object],Client,[object Object],Proxy,[object Object],Scheduler,[object Object],Servant,[object Object],method,[object Object],Future,[object Object],MethodRequest,[object Object],insert,[object Object],dispatch,[object Object],call,[object Object],method,[object Object],write,[object Object],read,[object Object],Detour: Active Object Pattern,[object Object]
Futures,[object Object],If the sender needs to coordinate with result, futures represent a powerful concept,[object Object],A future is an object that asynchronously waits for (and receives) the reply message of another actor,[object Object],may occur explicitly or implicitly,[object Object],should involve configurable timeouts ,[object Object],Page 18,[object Object],Akka Example:,[object Object],val future = actor !!! Message,[object Object],// sometimes later:,[object Object],future.await,[object Object],// sometimes later:,[object Object],val result = future.get,[object Object],Note: In Akka you could also use awaitOne() or awaitAll() to wake up until one or all futures contain the awaited results,[object Object]
Possible Strategies in Message Handling,[object Object],Actor implementations can open up the strategy for handling messages BYO (Bring-Your-Own):,[object Object],let developer configure how messages are arranged within message queue  ,[object Object],FIFO, priority based, etc.,[object Object],let developer provide dispatching strategy for handling messages such as using thread pools, single threads, etc.,[object Object],let developers add communication protocols for remote actors,[object Object],Page 19,[object Object],StrategyContext,[object Object],algorithm(),[object Object],strategy(),[object Object],Strategy,[object Object],dispatch(),[object Object],ConcreteStrategyA,[object Object],ConcreteStrategyB,[object Object]
Remote Actors,[object Object],Actors do not need to be constrained to one machine,[object Object],Instead, they may be distributed across different machines,[object Object],In this case, we need middleware mechanisms such as,[object Object],Network-wide identities,[object Object],Repositories for actor registration,[object Object],Client-managed versus server-managed actors (in terms of lifecycle),[object Object],Proxies for transparently accessing remote actors,[object Object],Messaging interop protocols,[object Object],Page 20,[object Object],State,[object Object],Node A,[object Object],Node B,[object Object],State,[object Object],thread,[object Object],thread,[object Object],method,[object Object],Interface,[object Object],method,[object Object],method,[object Object],Interface,[object Object],method,[object Object]
Handling Fault-Tolerance,[object Object],Erlang provides its own philosophy for fault-tolerance: let it crash,[object Object],Also used by some Actor libraries such as Akka,[object Object],Different models possible:,[object Object],One for One: If one actor crashes, only restart the crashed actor,[object Object],All for One: If one actor crashes stop the others too and restart actors,[object Object],One for One more suitable if actors are independent: otherwise use All for One ,[object Object],Can be applied hierarchically, i.e. one supervisor might be supervised by another supervisor,[object Object],Page 21,[object Object],Supervisor,[object Object],link,[object Object],Supervisor,[object Object],link,[object Object]
Sharing Data betweenActors,[object Object],Agents are not a good solution for applications that share data,[object Object],This holds especially when combining multiple actions ,[object Object],In database management systems, transactions come to our rescue,[object Object],Same can be done in memory using STM,[object Object],STM canbeadded to actors to allowsafesharing of commondata,[object Object],Page 22,[object Object]
STM,[object Object],Idea: Separate object from identity,[object Object],If object is going to be modifiedby an actor, let reference (identity) refer to new object,[object Object],Objects themselves remainunchanged (immutability!),[object Object],If anotheractor has changed the object in the meantime,[object Object],roll back change,[object Object],otherwise commit change,[object Object],Page 23,[object Object],Ref,[object Object],Object,[object Object],val x,[object Object],Object‘,[object Object]
AkkaintroducesTransactorsforSimplicity,[object Object],Page 24,[object Object],importakka.transactor.Transactor,[object Object],importakka.stm.Ref,[object Object],caseobjectIncrement,[object Object],classFriendlyCounter(friend: ActorRef) extendsTransactor{,[object Object],valcount = Ref(0),[object Object],overridedefcoordinate = { ,[object Object],caseIncrement => include(friend) // youcould also addseveralactorshere,[object Object],  }                                   // coordinate will send theIncrementmsg,[object Object],                                      // to otheractors - overriddenbySendTo,[object Object],defatomically = {  // entertransaction,[object Object],caseIncrement => count alter (_ + 1),[object Object],  },[object Object],},[object Object]
Example - Actors in Scala: Actor Definition,[object Object],Actors in Scala defined as library, but with an „internal DSL“ look & feel,[object Object],Actors must extend base class and define act() method,[object Object],Page 25,[object Object],import scala.actors._,[object Object],class Starship (val id : String) extends Actor {,[object Object],	def act() {,[object Object],	  println("Engines of USS " + id + " starting"),[object Object],	  for (i <- 1 to 9) println("Warp " + i),[object Object],	  println("Test succeeded"),[object Object],  	},[object Object],},[object Object],object ActorDemo1 extends Application {,[object Object],	new Starship("Enterprise") start,[object Object],},[object Object]
Example - Actors in Scala: Simplified Definition,[object Object],Using the actor method of the Actor companion object makes it even easier to define an actor:,[object Object],Page 26,[object Object],import scala.actors._,[object Object],import scala.actors.Actor._,[object Object],object ActorDemo2 extends Application {,[object Object],        val enterprise = actor {,[object Object],	  println("Engines of USS Enterprise starting"),[object Object],	  for (i <- 1 to 9) println("Warp " + i),[object Object],	  println("Test succeeded"),[object Object],},[object Object],},[object Object]
Example - Actors in Scala: Processing Messages,[object Object],Messages are sent to an actor with the bang operator !,[object Object],Messages are received within a receive block using pattern matching,[object Object],Page 27,[object Object],case object STOP,[object Object],case object ACCELERATE,[object Object],object ActorDemo3 extends Application {,[object Object],val enterprise = actor {,[object Object], var continue = true; var speed = 0,[object Object],while(continue) {,[object Object],      receive {,[object Object],case msg  : String => println("Received: " + msg),[object Object],	case STOP => println("stopping"); continue = false,[object Object],	case ACCELERATE => speed += 1; println("New speed Warp " + speed),[object Object],      } ,[object Object],    },[object Object],  },[object Object],  enterprise ! "Hello, Spock",[object Object],  for (i <- 1 to 9) enterprise ! ACCELERATE ,[object Object], enterprise ! STOP,[object Object],},[object Object],[info] Running ActorDemo3,[object Object],Received: Hello, Spock,[object Object],New speed is Warp 1,[object Object],New speed is Warp 2,[object Object],New speed is Warp 3,[object Object],New speed is Warp 4,[object Object],New speed is Warp 5,[object Object],New speed is Warp 6,[object Object],New speed is Warp 7,[object Object],New speed is Warp 8,[object Object],New speed is Warp 9,[object Object],stopping,[object Object],[info] == run ==,[object Object],[success] Successful.,[object Object]
Example - Actors in Scala: react instead of receive,[object Object],receive uses one thread and can return results ,[object Object],reactmore efficient; does not return so that we need to use loop{while},[object Object],Page 28,[object Object],[info] Running ActorDemo4,[object Object],Received: Hello, Spock,[object Object],New speed is Warp 1,[object Object],New speed is Warp 2,[object Object],New speed is Warp 3,[object Object],New speed is Warp 4,[object Object],New speed is Warp 5,[object Object],New speed is Warp 6,[object Object],New speed is Warp 7,[object Object],New speed is Warp 8,[object Object],New speed is Warp 9,[object Object],stopping,[object Object],[info] == run ==,[object Object],[success] Successful.,[object Object],case object STOP,[object Object],case object ACCELERATE,[object Object],class Starship (val id : String) extends Actor {,[object Object],  private[this] var speed = 0,[object Object],  def act() {,[object Object],    var continue = true,[object Object],    loopWhile(true == continue) {,[object Object],react {,[object Object],        case msg  : String => println("Received: " + msg),[object Object],        case STOP => println("stopping"); continue = false,[object Object],        case ACCELERATE => speed += 1; println("New speed is Warp " + speed),[object Object],      },[object Object],    },[object Object],  },[object Object],},[object Object],object ActorDemo4 extends Application {,[object Object],  val enterprise = new Starship("Enterprise"); enterprise.start,[object Object],  enterprise ! "Hello, Kirk“,[object Object], for (i <- 1 to 9) enterprise ! ACCELERATE; enterprise ! STOP,[object Object],},[object Object]
Example - Actors in Scala: react with reply,[object Object],In this example the actor returns a result using reply,[object Object],The sender receives the result synchronously using !?,[object Object],Page 29,[object Object],case class AddItem (price: Double),[object Object],case object SumUp,[object Object],case object CartDelete,[object Object],object Cart extends Actor {,[object Object],  def act() {,[object Object],    var total = 0.0,[object Object],    loop {,[object Object],      react {,[object Object],        case AddItem(price) => total += price,[object Object],        case CartDelete => total = 0.0,[object Object],case SumUp => reply(total); exit,[object Object],      },[object Object],    },[object Object],  },[object Object],},[object Object],object CartDemo extends Application {,[object Object],  Cart.start,[object Object],  Cart ! AddItem(19.99); Cart ! AddItem(19.99); Cart ! AddItem(2.02),[object Object],println("Please pay" + (Cart !? SumUp)) ,[object Object],},[object Object],[info] == run ==,[object Object],[info] Running CartDemo,[object Object],Please pay 42.0,[object Object],[info] == run ==,[object Object],[success] Successful.,[object Object]
Example - Actors in Scala: react and receive with TIMEOUT,[object Object],If we use react and receive we might block infinitely without receiving a message (especially after not sending any messages anymore),[object Object],Using the versions with with a predefined waiting time is more efficient in these circumstances,[object Object],On timeout a message TIMEOUT is sent to the actor,[object Object],Page 30,[object Object],    loopWhile(true == continue) {,[object Object],reactWithin(1000) {,[object Object],	case msg  : String => println("Received: " + msg),[object Object],case STOP => println("stopping"); continue = false,[object Object],	case ACCELERATE => speed += 1; println("New speed is Warp " + speed),[object Object],      },[object Object],    },[object Object]
Example - Actors in Scala: Actors should not block using the ActiveActor pattern,[object Object],If actors block during processing a message, mutual deadlock conditions might occur. We can prevent this by separating message receipt and processing,[object Object],Page 31,[object Object],object ActorDemo6 extends Application {,[object Object],  val service = actor {,[object Object],def doWork() { // here the actual work is done,[object Object],       val service = self    ,[object Object],       actor {,[object Object],         Thread.sleep(100),[object Object],         service ! "Serve",[object Object],       },[object Object],     },[object Object],     var served = 0,[object Object],     doWork(),[object Object],loop { // here messages are processed,[object Object],       react {,[object Object],         case "Serve" => println("I am serving"); served += 1,[object Object],                         if (served < 3) doWork (),[object Object],         case msg => println(msg),[object Object],       },[object Object],     },[object Object],  },[object Object],  service ! “Serve",[object Object],},[object Object]
Example - Actors in Scala: Using Schedulers,[object Object],Developers may override the scheduler method from the Actor trait,[object Object],For example, SingleThreadedScheduler maps the actor always to the same (main) thread,[object Object],Per default the ForkJoinScheduler is applied,[object Object],Page 32,[object Object],class Starship (val id : String) extends Actor {,[object Object],override def scheduler = scala.actors.scheduler.SingleThreadedScheduler,[object Object],  private[this] var speed = 0,[object Object],  def act() {,[object Object],    var continue = true,[object Object],    loopWhile(true == continue) {,[object Object],      react {,[object Object],        case msg  : String => println("Received: " + msg),[object Object],        case STOP => println("stopping"); continue = false,[object Object],        case ACCELERATE => speed += 1; println("New speed is Warp " + speed),[object Object],      },[object Object],    },[object Object],  },[object Object],},[object Object]
Example - Actors in Scala: Using Daemons,[object Object],Daemon actors provides the same interface such as actors, but,[object Object],The application may exit even if daemon actors are still running,[object Object],On the other hand, an application will wait for running actors to terminate,[object Object],In addition we might use lightweight reactors (do not transmit the sender with each message, may only use react) or ReplyReactors (senders are passed),[object Object],Page 33,[object Object],class Starship (val id : String) extends DaemonActor {,[object Object],  private[this] var speed = 0,[object Object],  def act() {,[object Object],    var continue = true,[object Object],    loopWhile(true == continue) {,[object Object],      react {,[object Object],        case msg  : String => println("Received: " + msg),[object Object],        case STOP => println("stopping"); continue = false,[object Object],        case ACCELERATE => speed += 1; println("New speed is Warp " + speed),[object Object],      },[object Object],    },[object Object],  },[object Object],},[object Object]
Example - Actors in Scala: Back to the Future,[object Object],With Futures we can receive a reply from an actor asynchronously,[object Object],We need to use the !! operator which returns an object,[object Object],Using isSet on this object tells whether result is already available,[object Object],Page 34,[object Object],case object STOP,[object Object],class Echo extends Actor {,[object Object],  def act() {,[object Object],    var continue = true,[object Object],    while(continue) {,[object Object],      receive {,[object Object],        case msg  : String => Thread.sleep(1000); sender ! msg,[object Object],        case STOP => println("stopping"); continue = false,[object Object],      },[object Object],    },[object Object],  },[object Object],},[object Object],object Future extends Application {,[object Object], val echo = new Echo; ,[object Object],  echo.start,[object Object],val replyMsg = echo !! "Hello OOP",[object Object],  println(replyMsg),[object Object],  println(replyMsg()) // get the result,[object Object],  echo ! STOP,[object Object],},[object Object],[info] == run ==,[object Object],[info] Running Future,[object Object],<function0>,[object Object],Hello OOP,[object Object],stopping,[object Object],[info] == run ==,[object Object],[success] Successful..,[object Object]
Example - Actors in Scala: Remote Actors Server,[object Object],Remote Actors can interact across machine or process boundaries,[object Object],The server needs to register itself,[object Object],Page 35,[object Object],import scala.actors.Actor._,[object Object],import scala.actors.remote.RemoteActor._,[object Object],object Server {,[object Object],  def remoteShip(ship : String, name: Symbol) = ,[object Object],actor {,[object Object],      alive(8888),[object Object],      register(name, self),[object Object],      var continue = true; var speed = 0,[object Object],      loopWhile(continue) {,[object Object],        react {,[object Object],case"Stop" => println("Scotty is stopping"); continue = false	,[object Object],case msg : String => println("Uhura received: " + msg),[object Object],case i : Int => speed += i; println("Spock reports warp speed " + speed),[object Object],        } ,[object Object],      }  ,[object Object],    }	,[object Object],   def main(args : Array[String]) {,[object Object],     remoteShip("Enterprise", 'enterprise),[object Object],   },[object Object],},[object Object]
Example - Actors in Scala: Remote Actors Client ,[object Object],The client connects to the remote node, ...,[object Object],... selects an actor on this node,,[object Object],and sends messages to the remote actor,[object Object],Page 36,[object Object],import scala.actors.Actor._,[object Object],import scala.actors.remote._,[object Object],import scala.actors.remote.RemoteActor._,[object Object],object Client extends Application {,[object Object],val node = Node("127.0.0.1", 8888),[object Object],   actor {,[object Object],val ship = select(node, 'enterprise),[object Object],     ship ! "Hello",[object Object],     for (i <- 1 to 9) ship ! i,[object Object],     ship ! "Stop" ,[object Object],   }	,[object Object],},[object Object],[info] Running Server,[object Object],Uhura received: Hello,[object Object],Spock reports warp speed 4,[object Object],Spock reports warp speed 5,[object Object],Spock reports warp speed 1,[object Object],Spock reports warp speed 6,[object Object],Spock reports warp speed 2,[object Object],Spock reports warp speed 7,[object Object],Spock reports warp speed 3,[object Object],Spock reports warp speed 8,[object Object],Spock reports warp speed 9,[object Object],Scotty is stopping,[object Object],[info] == run ==,[object Object],[success] Successfull.,[object Object]
Example - Actors in Scala: Concurrency Example (1),[object Object],Example taken from Programming Scala by Venkat Subramaniam,[object Object],Task: find if number is perfect ,[object Object],It is perfect  its factors sum up to be twice the number,[object Object],Instead of using a single-threaded algorithm to check we are using multiple actors,[object Object],The number is partitioned into n ranges each of which an actor analyzes,[object Object],Kind of Map-Reduce / Master-Slave approach ,[object Object],Page 37,[object Object],..........,[object Object],1    to   1000,[object Object],2001 to 3000,[object Object],1001 to 2000,[object Object]
Example - Actors in Scala: Concurrency Example (2),[object Object],Page 38,[object Object],def sumOfFactors(number: Int) = {,[object Object],  (0 /: (1 to number)) { (sum, i) => if (number % i == 0) sum + i else sum },[object Object],},[object Object],def isPerfect(candidate: Int) = { 2 * candidate == sumOfFactors(candidate) },[object Object],def sumOfFactorsInRange(lower: Int, upper: Int, number: Int) = {,[object Object],  (0 /: (lower to upper)) { (sum, i) => if (number % i == 0) sum + i else sum },[object Object],},[object Object],def isPerfectConcurrent(candidate: Int) = {,[object Object],  val RANGE = 1000000,[object Object],  val numberOfPartitions = (candidate.toDouble / RANGE).ceil.toInt,[object Object],  val caller = self,[object Object],  for (i <- 0 until numberOfPartitions) { ,[object Object],    val lower = i * RANGE + 1;,[object Object],    val upper = candidate min (i + 1) * RANGE,[object Object],    actor { ,[object Object],      caller ! sumOfFactorsInRange(lower, upper, candidate) ,[object Object],    },[object Object],},[object Object],  val sum = (0 /: (0 until numberOfPartitions)) { (partialSum, i) =>,[object Object],    receive { ,[object Object],      case sumInRange : Int => partialSum + sumInRange,[object Object],    },[object Object],}          ,[object Object],  2 * candidate == sum,[object Object],},[object Object]
Actors to the Limits - Akka for Scala,[object Object],Akka provides a much more extensive Actor library developed by Jonas Bonér,[object Object],Offers typed and untyped actors,[object Object],Supports STM and Transactors,[object Object],Allows searching for actors in its registry,[object Object],Provides Oz-like Dataflow concurrency,[object Object],And more,[object Object],Erlang-like Fault Tolerance,[object Object],Serialization of actors and their references,[object Object],Add-on modules for OSGi, Camel, JTA, ...,[object Object],Page 39,[object Object]
Example - Actors in F#,[object Object],The functional programming language F# (standard language in Visual Studio 2010) also supports Actor-based programming,[object Object],Page 40,[object Object],open System,[object Object],let mailbox =,[object Object],   MailboxProcessor.Start(fun mb ->,[object Object],    let rec loop x =,[object Object],      async { let! msg = mb.Receive(),[object Object],              printfn "I received: %s"  msg,[object Object],              return! loop x },[object Object],    loop 0),[object Object],mailbox.Post("Hallo"),[object Object],mailbox.Post(“OOP“),[object Object],Console.ReadLine() |> ignore,[object Object]
Example - Actors in Erlang,[object Object],Erlang - the first commercially relevant language that introduced actors (language feature),[object Object],Scala inherited this approach,[object Object],Page 41,[object Object],module_as_actor(E) when is_record(E, event) ->,[object Object],    case lists:keysearch(mfa, 1, E#event.contents) of,[object Object],        {value, {mfa, {M, F, _A}}} ->,[object Object],            case lists:keysearch(pam_result, 1, E#event.contents) of,[object Object],                {value, {pam_result, {M2, _F2, _A2}}} ->,[object Object],                    {true, E#event{label = F, from = M2, to = M}};,[object Object],                _ ->,[object Object],                    {true, E#event{label = F, from = M, to = M}},[object Object],            end;,[object Object],        _ ->,[object Object],            false,[object Object],    end.,[object Object]
Alternative Approach: Using a DSL such as Microsoft Axum,[object Object],Page 42,[object Object],Available for .NET,[object Object],Incubator project,[object Object],Actor definition in Axum, Code also in other .NET languages,[object Object],Domain,[object Object],Domain,[object Object],Shared State,[object Object],Shared State,[object Object],channel ChAddition,[object Object],{,[object Object],     input int Add;,[object Object],     output int Sum;,[object Object],     Start: { Add -> S1; },[object Object],     S1: { Sum -> End; },[object Object],},[object Object],Reader Agent,[object Object],WriterAgent,[object Object],Agent:Reader,[object Object],WriterAgent,[object Object],Channel w/ protocol,[object Object],Agent:Reader,[object Object],domain A,[object Object],{,[object Object],intaccu;  ,[object Object],int sum(int op) { },[object Object],     agent Z : ChAddition{ },[object Object],},[object Object],Reader Agents,[object Object],WriterAgent,[object Object],WriterAgent,[object Object],WriterAgent,[object Object],Schema,[object Object],Schema,[object Object],Microsoft C++ developers should look at the AAL (Asynchronous Agents Library),[object Object]
Different Actor Frameworks for Java available,[object Object],Akka,[object Object],ActorFoundry,[object Object],Actor‘s Guild ,[object Object],Jetlang,[object Object],Kilim,[object Object],Page 43,[object Object],Example from Akka Web site http://akkasource.org/,[object Object],// server code,[object Object],class HelloWorldActor extends UntypedActor {,[object Object],  public void onReceive(Object msg) {,[object Object],    getContext().reply(msg + " World");,[object Object],  },[object Object],},[object Object],RemoteNode.start("localhost", 9999).register(,[object Object],  "hello-service", ,[object Object],   actorOf(HelloWorldActor.class);,[object Object],// client code,[object Object],ActorRef actor = RemoteClient.actorFor(,[object Object],  "hello-service", "localhost", 9999);,[object Object],Object res = actor.sendRequestReply("Hello");,[object Object]
Some Possible Liabilities of Actors*,[object Object],In the pure actor model there is no notion of behavior inheritance,[object Object],Dynamic creation of new actors leads to ,[object Object],expansion of state,[object Object],necessity to decide about where to run and store a new actor,[object Object],maybe new communication channels,[object Object],Note: in a purely actor-based model entities such as integers would be actors,[object Object],Difficulty to replace behavior in an actor,[object Object],What about stream-based media?,[object Object],Fortunately, most of these liabilities can be avoided in hybrid OO/Actor models,[object Object],Page 44,[object Object],*see http://www.doc.ic.ac.uk/~nd/surprise_97/journal/vol2/pjm2/,[object Object]
Summary,[object Object],Multi-core revolution is pushing developers hard; using self-managed threads and synchronization leads to accidental complexity,[object Object],The Actor model seems to be a promising alternative for Concurrent Programming,[object Object],New languages and frameworks mix functional, object-oriented concepts with actors,[object Object],Actors are not the right solution for all problems, e.g., for really stateful tasks,[object Object],Introduction of actors should follow design of software architecture, especially its concurrency and distribution architecture. Still valid: A fool with a tool is still a fool,[object Object],Page 45,[object Object]

Mais conteúdo relacionado

Mais procurados

Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
 
C++ Object Oriented Programming
C++  Object Oriented ProgrammingC++  Object Oriented Programming
C++ Object Oriented ProgrammingGamindu Udayanga
 
Generic Programming in java
Generic Programming in javaGeneric Programming in java
Generic Programming in javaGarik Kalashyan
 
Object Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part IIIObject Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part IIIAjit Nayak
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence APIIlio Catallo
 
A (too) Short Introduction to Scala
A (too) Short Introduction to ScalaA (too) Short Introduction to Scala
A (too) Short Introduction to ScalaRiccardo Cardin
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)jeffz
 
ParaSail
ParaSail  ParaSail
ParaSail AdaCore
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programmingRiccardo Cardin
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++M Hussnain Ali
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelRamrao Desai
 

Mais procurados (19)

Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
C++ Object Oriented Programming
C++  Object Oriented ProgrammingC++  Object Oriented Programming
C++ Object Oriented Programming
 
Generic Programming in java
Generic Programming in javaGeneric Programming in java
Generic Programming in java
 
Javascript
JavascriptJavascript
Javascript
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
 
Object Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part IIIObject Oriented Programming using C++ Part III
Object Oriented Programming using C++ Part III
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence API
 
pebble - Building apps on pebble
pebble - Building apps on pebblepebble - Building apps on pebble
pebble - Building apps on pebble
 
A (too) Short Introduction to Scala
A (too) Short Introduction to ScalaA (too) Short Introduction to Scala
A (too) Short Introduction to Scala
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 
ParaSail
ParaSail  ParaSail
ParaSail
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
 
A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++A COMPLETE FILE FOR C++
A COMPLETE FILE FOR C++
 
DIWE - Fundamentals of PHP
DIWE - Fundamentals of PHPDIWE - Fundamentals of PHP
DIWE - Fundamentals of PHP
 
C++ oop
C++ oopC++ oop
C++ oop
 
Modern C++
Modern C++Modern C++
Modern C++
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 

Semelhante a Oop2011 actor presentation_stal

PATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelPATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelMichael Heron
 
Developing Actors in Azure with .net
Developing Actors in Azure with .netDeveloping Actors in Azure with .net
Developing Actors in Azure with .netMarco Parenzan
 
The Actor Model - Towards Better Concurrency
The Actor Model - Towards Better ConcurrencyThe Actor Model - Towards Better Concurrency
The Actor Model - Towards Better ConcurrencyDror Bereznitsky
 
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?Azure Service Fabric and the Actor Model: when did we forget Object Orientation?
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?João Pedro Martins
 
Nt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language AnalysisNt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language AnalysisNicole Gomez
 
M03 1 Structuraldiagrams
M03 1 StructuraldiagramsM03 1 Structuraldiagrams
M03 1 StructuraldiagramsDang Tuan
 
Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...
Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...
Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...Codemotion
 
Beyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor ProgrammingBeyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor ProgrammingFabio Tiriticco
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And DesignYaroslav Tkachenko
 
Case Study On System Requirement Modeling
Case Study On System Requirement ModelingCase Study On System Requirement Modeling
Case Study On System Requirement ModelingLaura Scott
 
M03 2 Behavioral Diagrams
M03 2 Behavioral DiagramsM03 2 Behavioral Diagrams
M03 2 Behavioral DiagramsDang Tuan
 
Object oriented design-UNIT V
Object oriented design-UNIT VObject oriented design-UNIT V
Object oriented design-UNIT VAzhar Shaik
 
PowerPoint
PowerPointPowerPoint
PowerPointVideoguy
 

Semelhante a Oop2011 actor presentation_stal (20)

PATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event ModelPATTERNS06 - The .NET Event Model
PATTERNS06 - The .NET Event Model
 
Developing Actors in Azure with .net
Developing Actors in Azure with .netDeveloping Actors in Azure with .net
Developing Actors in Azure with .net
 
Unit 1
Unit  1Unit  1
Unit 1
 
The Actor Model - Towards Better Concurrency
The Actor Model - Towards Better ConcurrencyThe Actor Model - Towards Better Concurrency
The Actor Model - Towards Better Concurrency
 
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?Azure Service Fabric and the Actor Model: when did we forget Object Orientation?
Azure Service Fabric and the Actor Model: when did we forget Object Orientation?
 
Nt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language AnalysisNt1310 Unit 3 Language Analysis
Nt1310 Unit 3 Language Analysis
 
Ch14
Ch14Ch14
Ch14
 
M03 1 Structuraldiagrams
M03 1 StructuraldiagramsM03 1 Structuraldiagrams
M03 1 Structuraldiagrams
 
Ch08
Ch08Ch08
Ch08
 
Ch08
Ch08Ch08
Ch08
 
Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...
Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...
Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...
 
Beyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor ProgrammingBeyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor Programming
 
Sysprog 10
Sysprog 10Sysprog 10
Sysprog 10
 
Sysprog 10
Sysprog 10Sysprog 10
Sysprog 10
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
 
Case Study On System Requirement Modeling
Case Study On System Requirement ModelingCase Study On System Requirement Modeling
Case Study On System Requirement Modeling
 
M03 2 Behavioral Diagrams
M03 2 Behavioral DiagramsM03 2 Behavioral Diagrams
M03 2 Behavioral Diagrams
 
Object oriented design-UNIT V
Object oriented design-UNIT VObject oriented design-UNIT V
Object oriented design-UNIT V
 
MCA NOTES.pdf
MCA NOTES.pdfMCA NOTES.pdf
MCA NOTES.pdf
 
PowerPoint
PowerPointPowerPoint
PowerPoint
 

Último

AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxiammrhaywood
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...Nguyen Thanh Tu Collection
 
How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17Celine George
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17Celine George
 
The Singapore Teaching Practice document
The Singapore Teaching Practice documentThe Singapore Teaching Practice document
The Singapore Teaching Practice documentXsasf Sfdfasd
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfMohonDas
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.raviapr7
 
How to Solve Singleton Error in the Odoo 17
How to Solve Singleton Error in the  Odoo 17How to Solve Singleton Error in the  Odoo 17
How to Solve Singleton Error in the Odoo 17Celine George
 
5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...CaraSkikne1
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.EnglishCEIPdeSigeiro
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICESayali Powar
 
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfMaximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfTechSoup
 
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptx
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptxPractical Research 1: Lesson 8 Writing the Thesis Statement.pptx
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptxKatherine Villaluna
 
How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17Celine George
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphNetziValdelomar1
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and stepobaje godwin sunday
 
M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxDr. Santhosh Kumar. N
 

Último (20)

AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
 
Prelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quizPrelims of Kant get Marx 2.0: a general politics quiz
Prelims of Kant get Marx 2.0: a general politics quiz
 
How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17How to Add a New Field in Existing Kanban View in Odoo 17
How to Add a New Field in Existing Kanban View in Odoo 17
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17
 
Finals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quizFinals of Kant get Marx 2.0 : a general politics quiz
Finals of Kant get Marx 2.0 : a general politics quiz
 
The Singapore Teaching Practice document
The Singapore Teaching Practice documentThe Singapore Teaching Practice document
The Singapore Teaching Practice document
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdf
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.
 
How to Solve Singleton Error in the Odoo 17
How to Solve Singleton Error in the  Odoo 17How to Solve Singleton Error in the  Odoo 17
How to Solve Singleton Error in the Odoo 17
 
5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...5 charts on South Africa as a source country for international student recrui...
5 charts on South Africa as a source country for international student recrui...
 
Personal Resilience in Project Management 2 - TV Edit 1a.pdf
Personal Resilience in Project Management 2 - TV Edit 1a.pdfPersonal Resilience in Project Management 2 - TV Edit 1a.pdf
Personal Resilience in Project Management 2 - TV Edit 1a.pdf
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.
 
Quality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICEQuality Assurance_GOOD LABORATORY PRACTICE
Quality Assurance_GOOD LABORATORY PRACTICE
 
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdfMaximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
Maximizing Impact_ Nonprofit Website Planning, Budgeting, and Design.pdf
 
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptx
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptxPractical Research 1: Lesson 8 Writing the Thesis Statement.pptx
Practical Research 1: Lesson 8 Writing the Thesis Statement.pptx
 
How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17
 
Presentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a ParagraphPresentation on the Basics of Writing. Writing a Paragraph
Presentation on the Basics of Writing. Writing a Paragraph
 
General views of Histopathology and step
General views of Histopathology and stepGeneral views of Histopathology and step
General views of Histopathology and step
 
M-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptxM-2- General Reactions of amino acids.pptx
M-2- General Reactions of amino acids.pptx
 

Oop2011 actor presentation_stal

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.