未加星标

Writing a Neo4J extension

字体大小 | |
[数据库(综合) 所属分类 数据库(综合) | 发布者 店小二05 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

This post is part of a multipart series about creating a graph off all available Maven dependencies.

This article describes the drivers behind and the implementation of the Unmanaged Neo4j Extension written for our Maven graph analysis.

When a the processing cluster is sending the sub graphs that need to be merged into a single database locking issues will occur. We opted to use a queuing mechanism to prevent. From the choices we had to implement this as a component for the Neo4J server we choose to this as a unmanaged extension.

Graph representation

Dependencies can be described as a graph by means of its vertices and edges. The following image show a simple graph with the vertices and edges in the table next to it.


Writing a Neo4J extension

as you can see each of the Vertices has an ID and properties associated with it. The Maven dependencies for a single artifact are stored in a similar fashion. As an example a simple table that describes the artifacts and its dependencies.

For example the following dependency tree: (partial output from a mvn dependency:tree command)

[INFO] +- javax:javaee-api:jar:7.0:provided [INFO] | \- com.sun.mail:javax.mail:jar:1.5.0:provided [INFO] | \- javax.activation:activation:jar:1.1:provided

would result in the following tables:


Writing a Neo4J extension

For the exchange of data between the Spark based resolvers and the plugin we opted for a Json representation.

JSon format

A (Sub) Graph message is defined as follows and is very similar to the formatting of the previous table.

{ "vertices": [ { "id": -1624024821, "groupId": "com.sun.mail", "artifactId": "javax.mail", "version": "1.5.0", "type": "Jar" }, { "id": 1561955024, "groupId": "javax.activation", "artifactId": "activation", "version": "1.1", "type": "Jar" }, { "id": -1466729092, "groupId": "javax", "artifactId": "javaee-api", "version": "7.0", "type": "Jar" } ], "edges": [ { "source": -1466729092, "destination": -1624024821, "relationType": "Provided" }, { "source": -1624024821, "destination": 1561955024, "relationType": "Compile" } ] } Queueing

In order to decouple the receiving of the subgraphs to a single thread the Java concurrency libraries are used.

Executer service

The executor service is used in a non standard manner. The Executer service is started with a single Thread and a pool size of 1. This ensures that only a single thread can do the actual inserts to the DB.

ExecutorService executorService = new ThreadPoolExecutor(1, 1, 1, TimeUnit.HOURS, queue, new ThreadPoolExecutor.CallerRunsPolicy()); Neo4J extension

The Neo4J extension is the most flexible way to extend the functionality of the server. The main reason for using this type is that we have complete control over the endpoints since its just a REST service that you implement.

This snippet shows the basic implementation of a extension:

@Path( "/dependency" ) public class HelloWorldResource { private final GraphDatabaseService database; public HelloWorldResource( @Context GraphDatabaseService database ) { this.database = database; } @Post @Produces( MediaType.TEXT_PLAIN ) @Consumes(MediaType.APPLICATION_JSON) @Path( "/graphs" ) public Response hello(final DependencyGrap grap ) { //Send data to queue return Response.ok().build(); } } Implementation

The implementation of this extension can be found in the Github repository

本文数据库(综合)相关术语:系统安全软件

主题: RESTGitSparkJavaTI
分页:12
转载请注明
本文标题:Writing a Neo4J extension
本站链接:http://www.codesec.net/view/480593.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 数据库(综合) | 评论(0) | 阅读(46)