Active object
   HOME

TheInfoList



OR:

The active object
design pattern A design pattern is the re-usable form of a solution to a design problem. The idea was introduced by the architect Christopher Alexander and has been adapted for various other disciplines, particularly software engineering. The "Gang of Four" boo ...
decouples method execution from method invocation for objects that each reside in their own thread of control. The goal is to introduce concurrency, by using asynchronous method invocation and a
scheduler A schedule or a timetable, as a basic time-management tool, consists of a list of times at which possible tasks, events, or actions are intended to take place, or of a sequence of events in the chronological order in which such things are i ...
for handling requests. The pattern consists of six elements: * A
proxy Proxy may refer to: * Proxy or agent (law), a substitute authorized to act for another entity or a document which authorizes the agent so to act * Proxy (climate), a measured variable used to infer the value of a variable of interest in climate ...
, which provides an interface towards clients with publicly accessible methods. * An interface which defines the method request on an active object. * A list of pending requests from clients. * A
scheduler A schedule or a timetable, as a basic time-management tool, consists of a list of times at which possible tasks, events, or actions are intended to take place, or of a sequence of events in the chronological order in which such things are i ...
, which decides which request to execute next. * The implementation of the active object method. * A
callback Callback may refer to: * Callback (comedy), a joke which refers to one previously told * Callback (computer programming), executable code that is passed as a parameter to other code * Callback (telecommunications), the telecommunications event th ...
or
variable Variable may refer to: * Variable (computer science), a symbolic name associated with a value and whose associated value may be changed * Variable (mathematics), a symbol that represents a quantity in a mathematical expression, as used in many ...
for the client to receive the result.


Example


Java

An example of active object pattern in
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's mos ...
. Firstly we can see a standard class that provides two methods that set a double to be a certain value. This class does NOT conform to the active object pattern. class MyClass The class is dangerous in a multithreading scenario because both methods can be called simultaneously, so the value of val (which is not atomic—it's updated in multiple steps) could be undefined—a classic race condition. You can, of course, use synchronization to solve this problem, which in this trivial case is easy. But once the class becomes realistically complex, synchronization can become very difficult. To rewrite this class as an active object, you could do the following: class MyActiveObject


Java 8 (alternative)

Another example of active object pattern in Java instead implemented in Java 8 providing a shorter solution. public class MyClass


See also

* Concurrent object-oriented programming * Actor model *
Futures and promises In computer science, future, promise, delay, and deferred refer to constructs used for synchronizing program execution in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially unknown, ...
*
Live distributed object Live distributed object (also abbreviated as ''live object'') refers to a running instance of a distributed multi-party (or peer-to-peer) protocol, viewed from the object-oriented perspective, as an entity that has a distinct identity, may encaps ...


References


External links


Ultra-high performance middleware based on Disruptor Active Object in C++14

Active Object implementation in C++11
Software design patterns Concurrency (computer science) Articles with example Java code {{Compu-prog-stub