An Implementation of Active Objects in Java By
An Implementation of Active Objects in Java By George Oprean Matt Pedersen University of Nevada, Las Vegas
Outline n n n n Introduction Active Objects Related Work Asynchronous Active Objects in Java Implementation Results Conclusions Future Work 1/18/2022 University of Nevada, Las Vegas 2
Introduction n Object Oriented paradigm n widely used in the last two decades n models how objects interact in the real world n objects are passive n friend. borrow. Money(20); n would reach into friends pocket and get the money n methods are executed synchronously n wait until friend gives me the $20 n more than one thread can have a reference to an object, thus the object can be put in an inconsistent state 1/18/2022 University of Nevada, Las Vegas 3
Objects Considered Harmful Each single thread of control snakes around objects in the system, bringing them to life transiently as their methods are executed. Threads cut across object boundaries leaving spaghetti-like trails, paying no regard to the underlying structure. 1/18/2022 University of Nevada, Las Vegas 4
Active Objects n executes method invocations in its own thread n receives the message, perform the computation and return the result to the caller n queues the requests and decide what method to execute next (order of arrival, priority) n only one method executes at one time → object can not be put in an inconsistent state 1/18/2022 University of Nevada, Las Vegas 5
Active Object (2) n methods can be invoked synchronously or asynchronously n asynchronous communication → the uses the ‘waiting time’ for other computations n waiting time = the time it takes the caller to get the result back n preparing breakfast example: n no cereals? Ask the active object to get the cereals n meantime, get the milk, set the spoons and pour orange juice n got back the cereals? Breakfast is served. n waitfor statement used for getting the result of asynchronous calls 1/18/2022 University of Nevada, Las Vegas 6
Related Work n employing patterns n Active Object or Dynamic Proxy Pattern n active object and pattern components have to be implemented n extending the language with new keywords n Java – active, accept, select and waituntil n only synchronous active objects n C++ - active, passive n both synchronous and asynchronous n using external libraries (like MPI for C) n Pro. Active library for Java 1/18/2022 University of Nevada, Las Vegas 7
Asynchronous Active Objects in Java n implemented our system in Java n the language is OO n it has RMI built in n it supports reflection n Java compiler available as open-source n it is platform independent n autoboxing done implicitly (from JDK 1. 5) 1/18/2022 University of Nevada, Las Vegas 8
Asynchonous Active Objects in Java (2) n an asynchronous Java active object characteristics: must be active (use own thread to execute the methods) n can be placed on any reachable machine on the network (ssh, JRE) n allow both synchronous and asynchronous method invocation n provide a way to obtain the result of asynchronous call n 1/18/2022 University of Nevada, Las Vegas 9
New Keywords n a new active modifier n marks a class as being active n an extended object creation n act. Obj = new Active. Class() on “machine_1”; n an extended method invocation expression n act. Obj. foo() async; n a new blocking waitfor statement n waitfor act. Obj var; 1/18/2022 University of Nevada, Las Vegas 10
Restrictions on Using the New Keywords n asynchronous invocation applies only to the last method, if method calls are chained n act. Obj. foo(). bar() async; n asynchronous invocations can only appear on the right side of an expression n illegal: obj. method(act. Obj. foo() async) n waiting for the results of asynchronous invocation on the same object is the same as the order of invocation 1/18/2022 University of Nevada, Las Vegas 11
Implementation Design Overview n communication by exchanging messages n both synchronous and asynchronous Create object Machine 0 Invoke method The code only run on this machine and creates active objects on any Machine 1 to n Machine 1 Send the result Create object Invoke method Machine n Send the result 1/18/2022 University of Nevada, Las Vegas 12
Implementation Creating an Active Object n a = new Active. Class(args) on “server”; n synchronous communication Create. Message client Active. Class arg { ……. server Create an instance of Active. Class a = new Active. Class(arg) on “server” ……. } Instance. Info server Active. Class instance. Id 1/18/2022 University of Nevada, Las Vegas 13
Implementation Invoking Active Object’s Methods n act. Obj. foo(a, b, c) async; n without async → synchronous communication Invoke. Message Instance. Info foo a, b, c client { ……. server return immediately act. Obj. foo(a, b, c) async; ……. } 1/18/2022 send the result University of Nevada, Las Vegas Execute the invocation 14
Implementation Getting the Result of Async Calls n waitfor act. Obj var; n programmer: “I’m waiting for the result of an asynchronous invocation and I want to store the value in var. ” n waitfor is a blocking statement n results of async invocations not waited for? Will be discarded when the method finishes n wait for the result of async calls in the same method as the invocation 1/18/2022 University of Nevada, Las Vegas 15
Implementation Message Ordering n active objects can be passed around n only a reference is passed and not the actual object n partial ordering: invocations from the same machine on the same object will be executed in order client 1 client 2 ……. act. Obj. foo() async ……. call foo method server call foo method The ‘act. Obj’ resides on the server and accepts requests from any machine that has a reference to it. 1/18/2022 University of Nevada, Las Vegas 16
Implementation Client. Manager and Server. Manager n the core components of our system server client act. Obj. foo() async; Resolve the invocation Client. Manager Server. Manager Remote Object Stub Remote Object Skeleton Network 1/18/2022 University of Nevada, Las Vegas 17
Implementation Client. Manager n only one per machine n manages the active invocations from the machine it is running on n manages the results of async invocations n core functionality n n invoke. Constructor – creates an active object invoke. Method – invokes a method on an active object n additional functionality n get. Method. Id – each method has a unique identifier n remove. Unwaited. Calls – removes unwaited results of asynchronous invocations 1/18/2022 University of Nevada, Las Vegas 18
Implementation Server. Manager n similar role as Client. Manager, but on the machine that hosts the active objects n only one per machine n needs to be started before the program is run (through ssh script) n accepts create and invoke messages Invoke. Message Instance_1 foo a, b, c Machine_1 1. message received Active Object ……. . 2. lookup object Instance_n Server. Manager 3. Forward the request 1/18/2022 University of Nevada, Las Vegas 19
Implementation Compiler Modifications n modified Sun’s open-source JDK 1. 6 compiler n new keywords are translated into regular Java code during desugaring phase n active keyword is removed from the class definition 1/18/2022 University of Nevada, Las Vegas 20
Implementation Compiler Modifications (2) n new creation expression n Active. Class act. Obj = new Active. Class() on “server”; will be translated to n 1/18/2022 Instance. Info act. Obj = Client. Manager. invoke. Constructor(“Active. Class”, new Object[]{}, “server”); University of Nevada, Las Vegas 21
Implementation Compiler Modifications(3) n adding the method. Id declaration n Long method. Id = Client. Manager. get. Method. Id(); n modifying the async invocations: n act. Obj. foo(a) async; will be translated to: n 1/18/2022 Client. Manager. invoke. Method(method. Id, ”foo”, new Object[]{a}, true); University of Nevada, Las Vegas 22
Implementation Compiler Modifications (4) n modify the waitfor statement n waitfor act. Obj var; will be translated to n Return. Object r 0 = Client. Manager. wait. For. Thread(method. Id, act. Obj); var = (Integer) r 0. get. Return. Value(); n remove the unwaited async calls n 1/18/2022 Client. Manager. remove. Unwaited. Calls(method. Id) University of Nevada, Las Vegas 23
Example: Subscriber / Distributor public active class Distributor { private Array. List<Subscriber> subscriber(); public void Subscribe(Subscriber s) { subscriber. add(s); } public void post(String message) { for (Subscriber s: subscribers) s. post(message) async; } } public active class Subscriber { private String name; public Subscriber(String name) { this. name = name; } public void post(String message) { System. out. println(name + “ got the message: “ + message); } } 1/18/2022 public class Demo { public static void main(String argv[]) { Distributor d = new Distributor(); Subscriber a = new Subscriber(“a”); d. subscribe(a) async; d. post(“First message”): Subscriber b = new Subscriber(“b”); d. subscribe(b) async; d. post(“Second message”); Subscriber c = new Subscriber(“c”); d. subscribe(c) async; d. post(“Third message”); } } a got the message: First message b got the message: Second message b got the message: Third message c got the message: Third message a got the message: Second message a got the message: Third message University of Nevada, Las Vegas 24
Active Objects for Distributed Computing n active objects used for developing parallel and distributed applications n async invocations → parallel computation n create objects on any machine on the network → distributed computing n implemented Mandelbrot set computation, Matrix multiplication and Pipeline computation 1/18/2022 University of Nevada, Las Vegas 25
Results Mandelbrot Set Computation n speedup= sequential time / parallel time 1/18/2022 University of Nevada, Las Vegas 26
Conclusions n Object Oriented programming increased popularity n n n compared to logical or procedural programming objects are passive active objects better reflection of the world (both passive and active objects) extended the Java language: active, async, on and waitfor develop parallel and distributed applications results demonstrate the feasibility of our proof of concept 1/18/2022 University of Nevada, Las Vegas 27
Future work n our system can be extended n starting/stopping the Server. Manager from code n warning the user if asynchronous calls with a return value do not have a matching waitfor n including an exception mechanism n receiving out of order invocations n keep active objects after the application finished the execution 1/18/2022 University of Nevada, Las Vegas 28
Thank You! 1/18/2022 University of Nevada, Las Vegas 29
- Slides: 29