User Tools

Site Tools


at:tutorial:distribution

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
at:tutorial:distribution [2007/07/26 11:03] – Updated stijnmat:tutorial:distribution [2009/01/28 11:27] elisag
Line 1: Line 1:
-<note> 
-This tutorial is under heavy construction! 
-</note> 
- 
 ====== Distributed Programming ====== ====== Distributed Programming ======
  
-Building on the actor-based concurrency model explained in the [[actors|previous chapter]], this chapter discusses the distribution provisions of AmbientTalk. For actors to communicate across the boundaries of a single device, actor'need to be capable of discovering one another's presence and need to be resilient to intermittent disconnections of their communication partners.+Building on the actor-based concurrency model explained in the [[actors|previous chapter]], this chapter discusses the distribution provisions of AmbientTalk. For actors to communicate across the boundaries of a single device, actors need to be capable of discovering one another's presence and need to be resilient to intermittent disconnections of their communication partners.
  
-These requirements correspond to the cornerstones of the  Ambient-Oriented Programming paradigm. The seamless integration of language support for dealing with partial failures and performing service discovery, hinge on AmbientTalk's concurrency model based on actors and far references. This chapter will explore the discovery mechanisms to create far references which span different devices, and illustrate how such far references are able to deal with intermittent disconnections in mobile ad hoc networks. +These requirements correspond to the cornerstones of the  Ambient-Oriented Programming paradigm. The seamless integration of language support for dealing with partial failures and performing service discovery, hinge on AmbientTalk's concurrency model based on actors and far references. This chapter will explore the discovery mechanisms to create far references which span different devices, and illustrate how such //remote// far references are able to deal with partial failures in mobile ad hoc networks. 
  
 Before delving in these topics, we illustrate how to activate the network facilities of AmbientTalk in the next section. Before delving in these topics, we illustrate how to activate the network facilities of AmbientTalk in the next section.
  
-===== Starting the Network.. =====+===== Going Online =====
    
 AmbientTalk provides an unique native object, named ''network'',  that responds to two methods that control the network access to an AmbientTalk virtual machine. More specifically, ''network.online()'' and ''network.offline()'' make a virtual machine go online and offline, respectively.  AmbientTalk provides an unique native object, named ''network'',  that responds to two methods that control the network access to an AmbientTalk virtual machine. More specifically, ''network.online()'' and ''network.offline()'' make a virtual machine go online and offline, respectively. 
Line 29: Line 25:
 deftype Printer; deftype Printer;
 def service := object: {  def service := object: { 
- def print(aDoc) { +  def print(aDoc) { 
- system.println("printing " +aDoc); +    system.println("printing " +aDoc); 
-    }+  }
 }; };
 export: service as: Printer; export: service as: Printer;
Line 50: Line 46:
 <code> <code>
 when: InstantMessenger discovered: { |messenger| when: InstantMessenger discovered: { |messenger|
-     when: (messenger<-getName()) becomes: { |name| +  when: (messenger<-getName()) becomes: { |name| 
- buddyList.put(name, messenger); +    buddyList.put(name, messenger); 
- system.println("Added buddy: " + name);   +    system.println("Added buddy: " + name); 
-     };+  };
 }; };
 </code> </code>
Line 66: Line 62:
  
 As ''export:as'', both constructs returns a subscription object that responds to a ''cancel'' method that can be used to cancel the subscription so that the block of code is no longer invoked. Note that objects exported by an actor do not trigger the actor's own ''when:discovered:'' nor ''whenever:discovered:'' observers. As ''export:as'', both constructs returns a subscription object that responds to a ''cancel'' method that can be used to cancel the subscription so that the block of code is no longer invoked. Note that objects exported by an actor do not trigger the actor's own ''when:discovered:'' nor ''whenever:discovered:'' observers.
-  
  
 ===== Partial Failure Handling ===== ===== Partial Failure Handling =====
  
-Let us consider again the example instant messenger application described in previous section to further explain the semantics of AmbientTalk's remote object references and how they deal with transient disconnections. +Let us consider again the example instant messenger application described in previous section to further explain the semantics of AmbientTalk's remote object references, which we call //remote far references//, and how they deal with transient disconnections. 
  
-When an object discovers a service type, the ''when:becomes:'' observers are triggered receiving as parameter a remote far reference to the remote object discovered. As explained in previous sections, far references operates asynchronously. When a client object sends a message via a remote reference, the message is buffered in the remote far reference and the client does not even wait for the message to be delivered. This is crucial in distributed computing in order to prevent race conditions. The parameter passing semantics for messages sent to remote objects works similar to the inter-actor message sending semantics:+When an object discovers a service type, the ''when:becomes:'' observers are triggered receiving as parameter a far reference to the remote object discovered. As explained in previous sections, far references operates asynchronously. When a client object sends a message via a remote far reference, the message is buffered in the far reference and the client does not even wait for the message to be delivered. This is crucial in distributed computing in order to prevent race conditions. The parameter passing semantics for messages sent to remote objects works similar to the inter-actor message sending semantics:
  
   - Objects are always passed //by far reference//, except for isolate objects which are passed by copy.   - Objects are always passed //by far reference//, except for isolate objects which are passed by copy.
Line 79: Line 74:
 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, messages are accumulate in its inbox in order to be transmitted once the reference becomes reconnected at a later point in time once the network connection is restored.  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, messages are accumulate in its inbox in order to be transmitted once the reference becomes reconnected at a later point in time once the network connection is restored. 
  
-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:+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 whenever 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:
  
 <code> <code>
 when: InstantMessenger discovered: { |messenger| when: InstantMessenger discovered: { |messenger|
- ... +  ... 
- when: messenger disconnected:+  whenever: messenger disconnected:
-     system.println("Buddy offline: " + name); +    system.println("Buddy offline: " + name); 
- }; +  }; 
- when: messenger reconnected:+  whenever: messenger reconnected:
-     system.println("Buddy online: " + name); +    system.println("Buddy online: " + name); 
- };+  };
 }; };
 </code> </code>
Line 95: Line 90:
 This code illustrate how the instant messenger application notifies when a buddy goes online or offline. In the above code, ''messenger'' is a remote reference to another remote buddy discovered. Note that installing disconnected observers also allows developers to clean certain resources when a remote reference becomes disconnected. However, when an instant messengers disconnects, the remote object referred to by ''messenger'' remains exported. This implies that remote objects remains pointed by a disconnected remote reference which prevents them from being garbage collected. In fact, ''messenger'' are never garbage unlesss explicit cancelation of the subscription. But other types of objects which are only relevant within the context of an interaction should become eventually candidates for garbage collection. In the next section, we detail how AmbientTalk deals with distributed memory management.  This code illustrate how the instant messenger application notifies when a buddy goes online or offline. In the above code, ''messenger'' is a remote reference to another remote buddy discovered. Note that installing disconnected observers also allows developers to clean certain resources when a remote reference becomes disconnected. However, when an instant messengers disconnects, the remote object referred to by ''messenger'' remains exported. This implies that remote objects remains pointed by a disconnected remote reference which prevents them from being garbage collected. In fact, ''messenger'' are never garbage unlesss explicit cancelation of the subscription. But other types of objects which are only relevant within the context of an interaction should become eventually candidates for garbage collection. In the next section, we detail how AmbientTalk deals with distributed memory management. 
  
-In other to cope with partial failures, AmbientTalk also allows developers to retract all currently unsent messages from the far reference outbox by means of the ''retract'' language construct. This is specially useful in the context of distribution, since developers can have explicit control on the messages that are buffered but have not been sent while the remote far reference is disconnected. Any undelivered messages accumulated by the remote reference can be then for example forwarded to another remote object or simply cancelled. +In order to cope with partial failures, AmbientTalk also allows developers to retract all currently unsent messages from the remote far reference outbox by means of the ''retract'' language construct. This is specially useful in the context of distribution, since developers can have explicit control on the messages that are buffered but have not been sent while the remote far reference is disconnected. Any undelivered messages accumulated by the remote reference can be then for example forwarded to another remote object or simply cancelled. 
  
 The ''retract'' language construct takes as argument the far reference of which to retract outgoing message send. One can store the unsent messages upon disconnection of a service type ''Service'' as follows: The ''retract'' language construct takes as argument the far reference of which to retract outgoing message send. One can store the unsent messages upon disconnection of a service type ''Service'' as follows:
Line 101: Line 96:
 <code> <code>
 when: Service discovered: { | reference | when: Service discovered: { | reference |
-    when: reference disconnected:+  when: reference disconnected:
-         messages := retract: reference; +    messages := retract: reference; 
-    }+  }
 } }
 </code> </code>
  
 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 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 ''when:disconnected:'' behaves like the previously discussed function ''whenever:disconnected:'', except it triggers the associated closure at most once, not upon //every// disconnect.
  
 ===== Garbage collecting remote references ===== ===== Garbage collecting remote references =====
 +
 +<note>
 +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. It would better be replaced by a thorough explanation of leased object references.
 +</note>
  
 As explained in the previous section, AmbientTalk's remote references are by default resilient to disconnections. This has significant repercussions at a distributed memory management level. The main impact is that an exported object cannot be reclaimed when all of its clients are disconnected since the remote references remain pointing to the server object. In other words, servers objects are kept alive even though there are only remotely accessible by a disconnected remote reference. AmbientTalk provides built-in support to unexport explicitly remotely accessible objects by means of the ''takeOffline'' language construct. The construct look as follows: As explained in the previous section, AmbientTalk's remote references are by default resilient to disconnections. This has significant repercussions at a distributed memory management level. The main impact is that an exported object cannot be reclaimed when all of its clients are disconnected since the remote references remain pointing to the server object. In other words, servers objects are kept alive even though there are only remotely accessible by a disconnected remote reference. AmbientTalk provides built-in support to unexport explicitly remotely accessible objects by means of the ''takeOffline'' language construct. The construct look as follows:
Line 127: Line 128:
 <code> <code>
 when: messenger takenOffline: { when: messenger takenOffline: {
-   system.println("Buddy offline: " + name); +  system.println("Buddy offline: " + name); 
-   //clean certain resources associated to the buddy+  //clean certain resources associated to the buddy
 }; };
 </code> </code>
at/tutorial/distribution.txt · Last modified: 2009/01/30 16:13 by tvcutsem