Class Function

  extended by org.modeshape.graph.request.function.Function
All Implemented Interfaces:
Direct Known Subclasses:

public abstract class Function
extends Object
implements Serializable

A serializable function that is to be called within a connector during a single atomic operation. Implementations subclass and implement the run(FunctionContext) method, where the supplied FunctionContext has all the information necessary for the function to run: the supplied input parameters, a way to invoke read and change requests on the content, a place to write the output, etc.

Here is a sample implementation of the Function interface that merely counts the number of nodes in a subgraph.

 protected static class CountNodesFunction extends Function {
     private static final long serialVersionUID = 1L;
     public void run( FunctionContext context ) {
         // Read the input parameter(s) ...
         int maxDepth = context.input("maxDepth", PropertyType.LONG, new Long(Integer.MAX_VALUE)).intValue();
         // Read the subgraph under the location ...
         ReadBranchRequest readSubgraph = context.builder().readBranch(context.appliedAt(), context.workspace(), maxDepth);
         // Process that request ...
         if (readSubgraph.hasError()) {
         } else {
             // And count the number of nodes within the subgraph ...
             int counter = 0;
             for (Location location : readSubgraph) {
                 if (location != null) ++counter;
             // And write the count as an output parameter ...
             context.setOutput("nodeCount", counter);

See Also:
Serialized Form

Constructor Summary
Method Summary
 boolean isReadOnly()
          Return whether this function only reads information.
abstract  void run(FunctionContext context)
          The method called to invoke the function.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public Function()
Method Detail


public abstract void run(FunctionContext context)
The method called to invoke the function. The implementation can obtain from the supplied FunctionContext the inputs to the function, a FunctionContext.builder() that can be used to create and immediately execute other requests, the context of execution, the location in the graph where the function is being applied, and other information needed during execution. The implementation even uses the supplied FunctionContext to write output parameters.

context - the context in which the function is being invoked, and which contains the inputs, the outputs, and methods to create and invoke other requests on the connector


public boolean isReadOnly()
Return whether this function only reads information.

This method always returns 'false'.

true if this function reads information, or false if it requests that the repository content be changed in some way

Copyright © 2008-2011 JBoss, a division of Red Hat. All Rights Reserved.