Service Combinators

We can imagine that many things can go wrong with a computation on such a large distributed scale as the World Wide Web. For example, part of a WebL computation might fail because of a failed web server or missing web page. Thus the unpredictable nature of the web causes many more exceptions than in a non-distributed environment. To counteract this problem, WebL provides a few convenient ways to handle exceptions. The exception handling mechanism is based on a formalism called service combinators. In this formalism we talk about services -- computations that depend on remote web servers -- that complete successfully or fail (throw an exception).

The service combinators allow several services to be combined in ways that can make a computation more reliable and in some cases even improve its speed. Note that by service we mean any WebL computation. WebL supports several service combinators: sequential execution, concurrent execution, time-out, repetition and non-termination.

One of the most basic services involves fetching a page from the Web. To make the examples that follow more realistic, we are going to use two of these built-in functions. More details about the exact behavior of these functions can be found in See Retrieving Page Objects. Note that any WebL computation can be regarded as a service.

Services

GetURL(url, [. param1=val1, param2=val2, ... .])

PostURL(url, [. param1=val1, param2=val2, ... .])

 

The GetURL function fetches with the HTTP GET protocol the resource associated with the URL. It returns a page object that encapsulates the resource. The function fails if the fetch fails. The second argument to GetURL provides the server with query arguments. A similar function called PostURL uses the HTTP POST protocol, used to fill in Web-based input forms.

// This program simply attempts to fetch the named URL.

page = GetURL("http://www.digital.com")

 

// This program looks up the word "java" on the

// AltaVista search engine.

page = GetURL(

"http://www.altavista.digital.com/cgi-bin/query",

[. pg="q", what="web", q="java" .])

 

Sequential execution S ? T

The "?" combinator allows a secondary service to be consulted in case the primary service fails for some reason. Thus, the service S ? T acts like the service S except that if S fails then it executes the service T.

// This program first attempts to connect to AltaVista

// in California, and in the case of failure,

// attempts to connect to a mirror in Australia.

page = GetURL("http://www.altavista.digital.com") ?

GetURL("http://www.altavista.yellowpages.com.au")

 

Concurrent execution S | T

The "|" combinator allows two services to be executed concurrently. The service S | T starts both services S and T at the same time and returns the result of whichever succeeds first. If both S and T fail, then the combined service also fails. Should one service complete before the other, the slower service is stopped. Stopping the slower service is performed in a controlled manner, to ensure the run-time remains in a consistent state. Typical checkpoints at which WebL will stop a service is at function or method call boundaries, and at the beginning or end of programmed loops.

// This program attempts to fetch a page from one

// of the two alternate sites. Both sites are

// attempted concurrently, and the

// result is that from whichever site

// successfully completes first.

page = GetURL("http://www.altavista.digital.com") |

GetURL("http://www.altavista.yellowpages.com.au")

 

Time-out timeout(t, S)

The time-out combinator allows a time limit to be placed on a service. The service Timeout(t, S) acts like S except that it fails after t milliseconds if S has not completed within that time. S will be stopped in controlled manner when it times-out (see the concurrent execution description above for details on how services are stopped).

// This program attempts to connect to

// alternative AltaVista mirror sites,

// but gives a limit of 10 seconds to succeed.

page = Timeout(10000,

GetURL("http://www.altavista.digital.com") |

GetURL("http://www.altavista.yellowpages.com.au "))

 

Repetition Retry(S)

The repetition combinator provides a way to repeatedly invoke a service until it succeeds. The service Retry(S) acts like S, except that if S fails then S starts again. The loop can be terminated by writing Timeout(t, Retry(S)).

// This program makes repeated attempts in the

// case of failure, alternating between two services.

page = Retry(

GetURL("http://www.x.com") ?

GetURL("http://www.y.com"))

 

Non-termination Stall()

The stall combinator never completes or fails.

// This program repeatedly tries to fetch the URL, but

// waits 10 seconds between attempts.

page = Retry(getpage("http://www.digital.com") ?

Timeout(10000, Stall())


Up Previous Next