We use neo4j for transport db storage and for find routes. Find routes process is large task, and so we want find routes via server plugin.
It's some step to create plugin for neo4j-server:
1) The plugin class must like as follows:
/**
* License information
*/
// package name - for keeping structure and your convenience
package ru.companyName.neo4j.plugins;
// import classes from neo4j
import org.neo4j.graphdb.GraphDatabaseService;
...
// import standard java classes
import java.util.ArrayList;
...
// decorator description of plugin pluginclass
@Description"AnextensiontotheNeo4jServerforfindroutesbetweentwonodes"
// your plugin class must extension ServerPlugin class
public class MyPlugin extends ServerPlugin {
// follow - standard structure of the class thereisimplementationofyouralgorithms
Set<String> trueTypes;
// create class method
public TransportRouter {
this.trueTypes = new HashSet<String>Arrays.asList("type1","type2");
}
// http-query method
@Name"getpaths"
@Description"Getpathsfromnodetonode"
// from this class you will call your plugin class
@PluginTargetGraphDatabaseService.class
public Representation getPaths(
@Source GraphDatabaseService graphDb,
@Description"Theidofthenodefrom"
@Parametername="idfrom" Node nodeFrom,
@Description"Theidofthenodeto"
@Parametername="idto" Node nodeTo
) throws Exception
{
// implementation of your algorithms
...
// returnable type Representation allow type String initweputstringinjson;alsopluginmethodcanreturnIterable<Node>andIterable<Relationship>
return ValueRepresentation.stringresult.toString();
}
}
2) Then plugin class must be compiled Eclipse,javac,etc., and then all compiled classes ∗.class put into JAR.
Directories tree in JAR-archive must like as name of package:
/ru/companyName/neo4j/plugins/<there are compiled classes>
JAR also must contain file:
/META-INF/services/org.neo4j.server.plugins.ServerPlugin
In this file you must write name of your package: ru.companyName.neo4j.plugins.TransportRouter
3) put resulting JAR in folder .../neo4j-server/plugins
4) restart server
5) get plugin list in server inbash:
curl http://localhost:7474/db/data/ext/
6) Then we can query our plugin class method:
curl -X POST http://localhost:7474/db/data/ext/MyPlugin/graphdb/get_path -H "Content-Type: application/json" -d '{"id_from": "http://localhost:7474/db/data/node/1", "id_to": "http://localhost:7474/db/data/node/2"}'
In this string after plugin name "MyPlugin" we write "graphdb", because in decorator @PluginTargetGraphDatabaseService.class we difine this class as parent class. Parameter -d define dictionary Map, which consider all input parameters for our plugin method whichdefinevia@Parameter.
There is problem in process of test plugin: DB wasn't see my plugin. This problem may occur by some reason ifyourcompilationclasseswasaccess:
- there isn't file /META-INF/services/org.neo4j.server.plugins.ServerPlugin or wrong string in it;
- there is error while initialization plugin class. You can try to create you class from other application to see this errors.
If your plugin was contained in the list of plugins, you may try query class method frombash. And you will see all errors in the tail.
Комментариев нет:
Отправить комментарий