at:tutorial:distribution
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
at:tutorial:distribution [2007/04/26 20:02] – elisag | at:tutorial:distribution [2008/09/16 17:28] – added tvcutsem | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | |||
====== Distributed Programming ====== | ====== Distributed Programming ====== | ||
- | This section | + | Building on the actor-based concurrency model explained in the [[actors|previous chapter]], this chapter |
- | The integration | + | |
+ | These requirements correspond | ||
+ | |||
+ | Before delving in these topics, we illustrate | ||
- | ===== Starting the Network.. | + | ===== Going Online |
AmbientTalk provides an unique native object, named '' | AmbientTalk provides an unique native object, named '' | ||
- | When the virtual machine goes online, | + | When the virtual machine goes online, the built-in |
+ | |||
+ | Taking a virtual machine | ||
< | < | ||
Line 19: | Line 23: | ||
AmbientTalk provides language support to make some objects available to other objects residing in remote actors by means of the '' | AmbientTalk provides language support to make some objects available to other objects residing in remote actors by means of the '' | ||
< | < | ||
- | defstripe | + | deftype |
def service := object: { | def service := object: { | ||
- | def print(aDoc) { | + | |
- | system.println(" | + | system.println(" |
- | } | + | } |
}; | }; | ||
export: service as: Printer; | 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 | + | 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 type tag. 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 type tag, 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 |
< | < | ||
- | defstripe | + | deftype |
</ | </ | ||
Line 42: | Line 46: | ||
< | < | ||
when: InstantMessenger discovered: { |messenger| | when: InstantMessenger discovered: { |messenger| | ||
- | when: (messenger< | + | |
- | buddyList.put(name, | + | buddyList.put(name, |
- | system.println(" | + | 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, '' | + | 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 '' | ||
- | The observer installed with the '' | ||
- | |||
===== Partial Failure Handling ===== | ===== Partial Failure Handling ===== | ||
- | Let us consider again the example instant messenger application described in previous | + | Let us consider again the example instant messenger application described in previous |
+ | |||
+ | When an object discovers a service type, the '' | ||
- | - Objects are always passed by far reference, except for isolate objects which are passed by copy. | + | - Objects are always passed |
- Native data types are always 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, | 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 | + | 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: InstantMessenger discovered: { |messenger| | when: InstantMessenger discovered: { |messenger| | ||
- | ... | + | |
- | when: messenger disconnected: | + | |
- | system.println(" | + | system.println(" |
- | }; | + | }; |
- | when: messenger reconnected: | + | |
- | system.println(" | + | system.println(" |
- | }; | + | }; |
}; | }; | ||
</ | </ | ||
- | Such observers can be also installed for the inter-actor far references. Such inter-actor far references are local to a virtual | + | This code illustrate how the instant messenger application notifies when a buddy goes online or offline. In the above code, '' |
+ | |||
+ | In order to cope with partial failures, AmbientTalk also allows developers to retract all currently unsent messages from the far reference outbox by means of the '' | ||
+ | |||
+ | The '' | ||
+ | |||
+ | < | ||
+ | when: Service discovered: { | reference | | ||
+ | when: reference disconnected: | ||
+ | messages := retract: reference; | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The construct returns a table containing copies of all messenges that were sent to this far reference, but not yet transmitted by the far reference to the remote object pointed to. Note that this has the side effect that the returned messages will not be sent automatically anymore; the programmer is thus responsible to explicitly resend all messages that were retracted but still need to be sent. | ||
+ | |||
+ | The function '' | ||
+ | |||
+ | ===== Garbage collecting remote references ===== | ||
+ | |||
+ | < | ||
+ | This is an advanced topic and probably does not belong in the tutorial. Moreover, it discusses features to be used only by implementors of reflective language constructs. | ||
+ | </ | ||
+ | |||
+ | As explained in the previous section, AmbientTalk' | ||
+ | |||
+ | < | ||
+ | takeOffline: | ||
+ | </ | ||
+ | |||
+ | The construct removes from the export table of the actor where the code is executed the object passed as argument. When the object is removed from the export table, it no longer belongs to the set of root objects and as such, it can be reclaimed by the local garbage collector once when it is no longer locally referenced. Although the actual reclamation of an unexported object may be trigger at a later point in time, any attempt to access it via a far reference will result in a '' | ||
+ | |||
+ | < | ||
+ | As you may have noticed, the '' | ||
+ | </ | ||
+ | |||
+ | On the client side, taking offline an object results in a permanent disconnection of the remote references pointing to it. In other words, despite having network connection, unexporting an object renders remote far references permanently disconnected. This implies that client have to deal explicitly with unexported objects. To this end, '' | ||
+ | |||
+ | < | ||
+ | when: messenger takenOffline: | ||
+ | system.println(" | ||
+ | //clean certain resources associated to the buddy | ||
+ | }; | ||
+ | </ | ||
+ | |||
+ | Be aware that unexporting a object will not only trigger the takenOffline observers but also the disconnected observers since the taking offline event is also considered as a logical disconnection between two devices. Unlike the network observers, the block of code of a takenOffline observer will be triggered only once. The remote object becomes then subject to be eventually reclaimed by the garbage collector. As a result, the disconnected and reconnected observers will be no longer trigger for such remote reference. | ||
+ | |||
+ | Note that disconnection, | ||
< | < | ||
- | The complete implementation of the instant messenger application explained along this chapter can be found in the file at/ | + | The complete implementation of the instant messenger application explained along this chapter can be found in the file '' |
</ | </ |
at/tutorial/distribution.txt · Last modified: 2009/01/30 16:13 by tvcutsem