Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES

## Package org.modeshape.graph.request.function

The `Function` interface provides a way to inject custom logic into a connector, where it can be executed close to the actual data and where it can make decisions about what changes should be made to the content.

See:
Description

Interface Summary
FunctionContext | The context in which a `Function` is executed.

Class Summary
Function | A serializable function that is to be called within a connector during a single atomic operation.

## Package org.modeshape.graph.request.function Description

The `Function` interface provides a way to inject custom logic into a connector, where it can be executed close to the actual data and where it can make decisions about what changes should be made to the content. The `FunctionContext` interface encapsulates the context in which a function is `run`, including the input parameters, output parameters, location in the graph, and ways of building and executing other requests.

To use a `Function`, simply subclass it, implement the `Function.run(FunctionContext)` method, and then used it via the `Graph API`, either through direct (immediately) interaction:

         Graph graph = ...
         Function myFunction = ...
         Map output = graph.applyFunction(myFunction)
                                                .with("a","val1")
                                                .and("b",3)
                                                .to("/");
         Object count = output.get("count");

or via batch invocation:

         Graph graph = ...
         Function myFunction = ...
         Graph.Batch batch = graph.batch();
         batch.applyFunction(myFunction)
              .with("a","val1")
              .and("b",3)
              .to("/")
              .and()
              .read("/myNode");
         Results results = batch.execute();
         List requests = results.getRequests();
         FunctionRequest functRequest = requests.get(0);
         ReadNodeRequest readRequest = requests.get(1);

         // use the results in the requests ...
         long count = functRequest.output("success",PropertyType.LONG,new Long(0)).longValue();

         for ( Property prop : readRequest.getProperties() ) {
            // do something ...
         }

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES

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