Active objects are a design pattern used in computer programming to ensure that a service is always available in a multi-threaded system. They allow for input processing without blocking concurrent processes and are wrapped in a publicly accessible interface called a proxy. This creates a design pattern where objects send messages to active objects and then continue their processing until the active object processes the message and informs the calling objects of the results. This is in contrast to passive objects, which can cause execution blocking problems.
In computer programming and engineering, an active object is a type of design pattern that can be used to ensure that some service is always available in a multi-threaded or concurrent system. An active object is an object that implements a mechanism so that it can receive and process input from external objects without forcing the external objects to wait for execution to complete. This mechanism also allows many objects that may all be running at the same time to use active objects without the possibility of long block times where concurrent processes have to stop and wait for access. This is most often accomplished by wrapping active objects in a publicly accessible interface, called a proxy, and then implementing some type of queue system inside the objects so that messages are archived for later processing. This creates a design pattern where objects send messages to active objects and then continue their processing until the active object processes the message and then subsequently informs the calling objects of the results so they can update their states accordingly.
Outside of an active object design pattern, a normal object might be called a passive object. In a simple program example, a passive object could act as a chat relay server, where remote objects contact the passive object to relay a message to everyone else on the server. Whenever the passive server object receives a chat message from a remote object, it must immediately handle the request and then send the output immediately, all while the remote object stops executing until the process is finished, an effect known as a block. Creating different threads within the program may fix the execution blocking problem, but then it starts problems with synchronization.
In an active object design pattern, the same server object in the previous example would run in its own separate thread from other objects. It would also be wrapped in a type of interface known as a proxy which is also running in a separate thread, sometimes the main program’s execution thread. When a remote object wants the server object to send a chat message, it contacts the proxy object, passes it all the requested information, and then returns to its normal running state instead of waiting.
The proxy interface then converts the information from the remote object into a message that it passes to a queue for processing on the active object. At this point, both the proxy interface and the remote object are free to continue running and are not blocked. Meanwhile, the active object works to keep the queue empty, processing each incoming message. If the calling object requests that some information be returned from the active object, a callback structure can be used to inform the remote object of any state changes.
Protect your devices with Threat Protection by NordVPN