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.
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
"http://www.altavista.digital.com/cgi-bin/query",
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") ?
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.
// 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") |
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.
// This program attempts to connect to
// alternative AltaVista mirror sites,
// but gives a limit of 10 seconds to succeed.
GetURL("http://www.altavista.digital.com") |
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
The stall combinator never completes or fails.
// This program repeatedly tries to fetch the URL, but
// waits 10 seconds between attempts.