|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.modeshape.graph.request.function.Function
public abstract class Function
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; @Override 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()) { context.setError(readSubgraph.getError()); } 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); } } }
Constructor Summary | |
---|---|
Function()
|
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)
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 connectorpublic boolean isReadOnly()
This method always returns 'false'.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |