Databases Reference
In-Depth Information
extensions enable us to run arbitrary Java code inside the server (see “Server ex‐
tensions” ), the use of server extensions may impact the server's GC behavior.
When using Neo4j in server mode, we should bear in mind the following:
Network overhead
There is some communication overhead to each HTTP request, though it's fairly
minimal. After the first client request, the TCP connection remains open until
closed by the client.
Per-request transactions
Each client request is executed in the context of a separate transaction, though there
is some support in the REST API for batch operations. For more complex, multistep
operations requiring a single transactional context, we should consider using a
server extension (see “Server extensions” ).
Access to Neo4j server is typically by way of its REST API, as discussed previously. The
REST API comprises JSON-formatted documents over HTTP. Using the REST API we
can submit Cypher queries, configure named indexes, and execute several of the built-
in graph algorithms. We can also submit JSON-formatted traversal descriptions, and
perform batch operations. For the majority of use cases the REST API is sufficient;
however, if we need to do something we cannot currently accomplish using the REST
API, we should consider developing a server extension.
Server extensions
Server extensions enable us to run Java code inside the server. Using server extensions,
we can extend the REST API, or replace it entirely.
Extensions take the form of JAX-RS annotated classes. JAX-RS is a Java API for building
RESTful resources. Using JAX-RS annotations, we decorate each extension class to in‐
dicate to the server which HTTP requests it handles. Additional annotations control
request and response formats, HTTP headers, and the formatting of URI templates.
Here's an implementation of a simple server extension that allows a client to request the
distance between two members of a social network:
@Path ( "/distance" )
public class SocialNetworkExtension
{
private final ExecutionEngine executionEngine ;
public SocialNetworkExtension ( @Context GraphDatabaseService db )
{
this . executionEngine = new ExecutionEngine ( db );
}
@GET
@Produces ( "text/plain" )
Search WWH ::




Custom Search