User Tools

Site Tools


at:byexample

Differences

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

Link to this comparison view

Next revision
Previous revision
at:byexample [2008/08/11 20:26]
tvcutsem created
at:byexample [2009/10/08 14:11] (current)
tvcutsem
Line 7: Line 7:
 Here is how to send a message to a remote object, receive a reply, and deal with the exception that the reply was not received in time: Here is how to send a message to a remote object, receive a reply, and deal with the exception that the reply was not received in time:
  
-<code>+<code javascript>
 import /.at.lang.futures; import /.at.lang.futures;
  
-when: lightbulb<-toggleLight()@Due(seconds(10)) becomes: { |lightStatus+when: lightbulb<-toggleLight()@Due(seconds(10)) becomes: { |reply
-  // code to execute when the light bulb switched on +  // code to execute when the message has been 
-  // lightStatus refers to the return value of the toggleLight method.+  // succesfully processed. 
 +  // reply refers to the return value of the 
 +  // toggleLight method.
 } catch: TimeoutException using: { |e| } catch: TimeoutException using: { |e|
-  // code to execute when the light bulb did not respond before 10 seconds +  // code to execute when the light bulb did not 
-  // note: this block may be executed either because the message toggleLight +  // respond before 10 seconds 
-  // could not be sent or was not succesfully acknowledged, or because the message +  // note: this block may be executed either because 
-  // carrying the reply was not received, or has not yet been received (missed the deadline)+  // the message toggleLight could not be sent or was 
 +  // not succesfully acknowledged, or because the message 
 +  // carrying the reply was not received, or has not yet 
 +  // been received (missed the deadline)
 } }
 </code> </code>
Line 33: Line 38:
 where ''obj'' is the object to be exported, and ''Type'' refers to a type tag by means of which the object can be discovered. To unexport the object, execute ''pub.cancel()''. Here's how to discover the object: where ''obj'' is the object to be exported, and ''Type'' refers to a type tag by means of which the object can be discovered. To unexport the object, execute ''pub.cancel()''. Here's how to discover the object:
  
-<code>+<code javascript>
 def sub := when: Type discovered: { |obj| def sub := when: Type discovered: { |obj|
-  ...+  // code to execute upon discovery
 } }
 </code> </code>
  
-Here, ''obj'' is either a far reference to the object (i.e. a remote object reference) if ''obj'' is pass-by-reference, or a copy of the object, if {{{obj}}} is pass-by-copy. To stop looking for a ''Type'' object in the ad hoc network, invoke ''sub.cancel()''.+Here, ''obj'' is either a far reference to the object (i.e. a remote object reference) if ''obj'' is pass-by-reference, or a copy of the object, if ''obj'' is pass-by-copy. ''sub'' refers to a subscription object. To stop looking for a ''Type'' object in the ad hoc network, invoke ''sub.cancel()''.
  
 The above block is triggered upon discovering one object of the appropriate (sub)type. If one wants to trigger a block every time an object of the appropriate type is discovered, execute: The above block is triggered upon discovering one object of the appropriate (sub)type. If one wants to trigger a block every time an object of the appropriate type is discovered, execute:
-<code>+<code javascript>
 whenever: Type discovered: { |obj| whenever: Type discovered: { |obj|
-  ...+  // code to execute upon every discovery
 } }
 </code> </code>
Line 52: Line 57:
 Given a far reference ''ref'' to a remote object, here's how to use AmbientTalk's built in failure detector to react to the object going offline: Given a far reference ''ref'' to a remote object, here's how to use AmbientTalk's built in failure detector to react to the object going offline:
  
-<code>+<code javascript>
 def sub := when: ref disconnected: { def sub := when: ref disconnected: {
-  ...+  // code to execute upon disconnection
 } }
 </code> </code>
Line 60: Line 65:
 And here is how to react to the object becoming available again: And here is how to react to the object becoming available again:
  
-<code>+<code javascript>
 def sub := when: ref reconnected: { def sub := when: ref reconnected: {
-  ...+  // code to execute upon reconnection
 } }
 </code> </code>
Line 74: Line 79:
 Here's how to create a lease for an object: Here's how to create a lease for an object:
  
-<code>+<code javascript>
 import /.at.lang.leasedrefs; import /.at.lang.leasedrefs;
  
Line 82: Line 87:
 Here, ''l'' is a leased reference: a proxy to ''obj'' which remains valid for at least 10 minutes. Every time a message is sent via the lease to the object, the lease gets transparently renewed. When a lease has expired, it no longer acts as a proxy for ''obj'', allowing ''obj'' to be eventually reclaimed if no other objects refer to it. One can react to the expiration of a lease as follows: Here, ''l'' is a leased reference: a proxy to ''obj'' which remains valid for at least 10 minutes. Every time a message is sent via the lease to the object, the lease gets transparently renewed. When a lease has expired, it no longer acts as a proxy for ''obj'', allowing ''obj'' to be eventually reclaimed if no other objects refer to it. One can react to the expiration of a lease as follows:
  
-<code>+<code javascript>
 when: l expired: { when: l expired: {
-  ...+  // code to execute upon lease expiration
 } }
 </code> </code>
Line 92: Line 97:
 Here's how to postpone the execution of a block of code until a certain period of time has elapsed: Here's how to postpone the execution of a block of code until a certain period of time has elapsed:
  
-<code>+<code javascript>
 import /.at.support.timer; import /.at.support.timer;
  
 def sub := when: seconds(10) elapsed: { def sub := when: seconds(10) elapsed: {
-  ...+  // code to execute after 10 seconds
 } }
 </code> </code>
Line 102: Line 107:
 Here, ''sub'' refers to a subscription object. Invoking ''sub.cancel()'' unregisters the block with the timer, such that it will not be executed in the future. If you want to repeatedly execute a block of code, write: Here, ''sub'' refers to a subscription object. Invoking ''sub.cancel()'' unregisters the block with the timer, such that it will not be executed in the future. If you want to repeatedly execute a block of code, write:
  
-<code>+<code javascript>
 whenever: minutes(1) elapsed: { whenever: minutes(1) elapsed: {
-  ...+  // code to execute every minute
 } }
 </code> </code>
at/byexample.1218479179.txt.gz · Last modified: 2008/08/11 20:28 (external edit)