This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
at:tutorial:distribution [2007/04/26 20:13] elisag |
at:tutorial:distribution [2009/01/30 16:13] tvcutsem *fixed |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Distributed Programming ====== | ||
- | |||
- | This section discusses how AmbientTalk virtual machines can discover and communicate with each other over the network. | ||
- | The integration of distribution was one of the main concerns in the design of AmbientTalk programming model. More specifically, | ||
- | |||
- | ===== Starting the Network.. ===== | ||
- | |||
- | AmbientTalk provides an unique native object, named '' | ||
- | |||
- | When the virtual machine goes online, this allows the built-in discovery lookup mechanism to export the local objects and let local objects to find other remote objects. AmbientTalk' | ||
- | |||
- | < | ||
- | Be aware that by default the network access is shut down. | ||
- | </ | ||
- | |||
- | ===== Exporting and discovering objects ===== | ||
- | |||
- | AmbientTalk provides language support to make some objects available to other objects residing in remote actors by means of the '' | ||
- | < | ||
- | defstripe Printer; | ||
- | def service := object: { | ||
- | def print(aDoc) { | ||
- | system.println(" | ||
- | } | ||
- | }; | ||
- | export: service as: Printer; | ||
- | </ | ||
- | |||
- | When an object its exported by its actor, it becomes discoverable by other actors by means of the service type. Internally, this means that the object is placed in the export table of its actor. As shown in the example, a service type is represented by a stripe. This means that services types are not associated with a set of methods, but they denote an abstract publication topic that objects exports. As a stripe, a service type can thus be a subtype of one or more other service types. For example, an object could offer a color printing services by exporting the following stripe: | ||
- | < | ||
- | defstripe ColorPrinter <: Printer; | ||
- | </ | ||
- | |||
- | The '' | ||
- | |||
- | ==== Discovering objects ==== | ||
- | |||
- | AmbientTalk has a built-in peer-to-peer discovery lookup mechanism based on a publish-subscribe scheme that was designed to be able to discover objects in mobile ad hoc network interactions where no centralized lookup infrastructure may be available. | ||
- | |||
- | As previously explained, objects broadcast to the network the service types they offer using the export statement. AmbientTalk also provides language constructs to install an observer whose block of code will be triggered when a remote object of a certain service type becomes available in the network. For example, one can discover a proximate buddy of an instant messenger application by means of the '' | ||
- | < | ||
- | when: InstantMessenger discovered: { |messenger| | ||
- | when: (messenger< | ||
- | buddyList.put(name, | ||
- | system.println(" | ||
- | }; | ||
- | }; | ||
- | </ | ||
- | |||
- | The code block to execute when the service type becomes available is parameterized with the actual remote reference to the discovered service object. In the example above, '' | ||
- | < | ||
- | We are using a future to get the return value of the '' | ||
- | </ | ||
- | |||
- | The '' | ||
- | |||
- | As '' | ||
- | |||
- | |||
- | ===== Partial Failure Handling ===== | ||
- | |||
- | Let us consider again the example instant messenger application described in previous subsection to further explain the semantics of AmbientTalk' | ||
- | |||
- | When an object discovers a service type, the '' | ||
- | |||
- | - Objects are always passed by far reference, except for isolate objects which are passed by copy. | ||
- | - Native data types are always passed by copy. | ||
- | |||
- | |||
- | When a remote far reference receives a messages, it flushes the message to the remote object providing that it is connected. If the remote far reference is disconnected, | ||
- | |||
- | Therefore, a remote far reference abstracts a client object from the actual network connection state. However, it is often useful for an application to be informed when a connection to a remote object is lost or reconnected. To this end, AmbientTalk offers language constructs to install observers on a far reference which are triggered when the reference becomes disconnected or reconnected. For example, the instant messenger application can notify the user whenever a buddy moves in and out of the communication range as follows: | ||
- | |||
- | < | ||
- | when: InstantMessenger discovered: { |messenger| | ||
- | ... | ||
- | when: messenger disconnected: | ||
- | | ||
- | }; | ||
- | when: messenger reconnected: | ||
- | | ||
- | }; | ||
- | }; | ||
- | </ | ||
- | |||
- | Such observers can be also installed for the inter-actor far references. Such inter-actor far references are local to a virtual machines and as such, network failures cannot happen. In that case, the disconnection observer are triggered when the object pointed to by the far reference is taken offline. In other words, when the object is removed from the export table of an actor. However, note that the reconnected observers won't be never triggered since an object unexported is subject to be eventually reclaimed by the local garbage collector. | ||
- | |||
- | < | ||
- | The complete implementation of the instant messenger application explained along this chapter can be found in the file at/ | ||
- | </ |