简体   繁体   中英

Streaming Graph to Gephi using toolkit : NullPointerException

I'm trying to create a normal graph and stream it to Gephi GUI using the Gephi toolkit. I am following the the toolkit and the streaming plugin tutorials. I am having difficulty getting my code to work because the lookup API is not returning valid values. On debug, I could find that both the Lookup methods below return null values because of which I am having trouble in accessing other methods using these objects.

StreamingServer server = Lookup.getDefault().lookup(StreamingServer.class);

ServerControllerFactory controllerFactory = Lookup.getDefault().lookup(ServerControllerFactory.class);

As both 'server' or 'controllerFactory' are null, accessing any methods using 'server' or 'controllerFactory' objects would then throw NullPointerException. For example, at :

ServerController serverController = controllerFactory.createServerController(graph); server.register(serverController, context);

This is the code I have:

//Init a project - and therefore a workspace
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
    pc.newProject();
    Workspace workspace = pc.getCurrentWorkspace();

    // Get the graph instance
    GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
    GraphModel graphModel = graphController.getModel();
    Graph graph = graphModel.getGraph();

    //Add sample graph structure data
       Node n1;
       Node n2;
       n1 = graphModel.factory().newNode();
       n2 = graphModel.factory().newNode();
       Edge edge = graphModel.factory().newEdge(n1, n2);

       graph.addNode(n1);
       graph.addNode(n2);
       graph.addEdge(edge);

       n1.getNodeData().setLabel("Node 1");
       n2.getNodeData().setLabel("Node 2");
       edge.getEdgeData().setLabel("Edge 1");

       System.out.println(graph.getNodeCount() + " nodes");
       System.out.println(graph.getEdgeCount() + " edges");
       System.out.println();


    StreamingServer server = Lookup.getDefault().lookup(StreamingServer.class);

    ServerControllerFactory controllerFactory = Lookup.getDefault().lookup(ServerControllerFactory.class);
    ServerController serverController = controllerFactory.createServerController(graph);

    String context = "/mycontext";
    server.register(serverController, context);

Any inputs to solve this would be helpful.

This could happen if META-inf/services folder of gephi toolkit is not accessible; eg when you merge jars; etc. especially common when you try to do server side deployment.

ps The class files are there; so no Class Not Found exception is thrown; but services are not being able to be located; for more info see http://docs.oracle.com/javase/7/docs/api/java/util/ServiceLoader.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM