6.4. Custom sites

For services beyond those available as library sites, Java sites, and Web service sites, Orc programs may call sites developed specifically as Orc sites. The calling Orc program names the site with an import site declaration. This declaration causes the Orc engine to load the Java class of the given name from the Orc site classpath or JVM classpath. Calls to this site are dispatched via Orc's site interface, which permit the site to interact with the calling program natively.

6.4.1. Implementing new custom sites

Orc sites may be implemented in any language that can produce Java class files. However, the Orc team rec ommends the Scala programming language from Martin Odersky and his team at EPFL (École Polytechnique Fédérale de Lausanne). For information on Scala, see http://www.scala-lang.org/.

The Orc runtime engine provides a basic Site interface which a site must implement. This interface specifies an abstract call method that receives a call handle for the site to respond to the site call. The Handle interface provides methods to respond by either:

Additionally, sites may notify the Orc runtime engine of events via the Handle, such as the need to write a string to the standard output stream.

Site call arguments and return values are not subject to Orc-Java conversions, so the site must work with native Orc values. Sites are also responsible for enforcing arity and type requirements on the argument lists of calls.

Orc provides a number of convenience mix-in traits for site implementors:

Site interface mix-in traits

orc.values.sites.Site

The basic site trait -- a site that can be called. Implement the call method.

orc.values.sites.TotalSite

A site that always publishes. Implement the evaluate method instead of the call method.

orc.values.sites.PartialSite

A site that sometimes publishes and sometimes halts silently. Implement the evaluate method instead of the call method. evaluate should return an Option, Some(x) to publish x, or None to halt.

orc.values.sites.UnimplementedSite

A site that throws orc.error.NotYetImplementedException when called or type checked.

orc.values.sites.TypedSite

A site that declares its type to the Orc type checker.

orc.values.sites.UntypedSite

A site that does not participate in type checking. Use sparingly.

For a detailed description of the Orc-site interface, refer to the Orc implementation Javadoc.

6.4.2. Related Links

Related Reference Topics

Related Tutorial Sections