1

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.

user1727270
  • 303
  • 1
  • 3
  • 10
  • I am using Lookup.getDefault().lookup() of org.openide.util.Lookup which is used for finding instances of objects. The general pattern is to pass a Class object and get back an instance of that class or null.Since no istances are found, null is returned for each of these, 'server', 'controllerFactory', 'controller'. I need to handle this situation. – user1727270 May 14 '14 at 00:18
  • However, lookup for classes from the toolkit works fine. ProjectController pc = Lookup.getDefault().lookup(ProjectController.class); GraphController graphController = Lookup.getDefault().lookup(GraphController.class) I am running my project in Eclipse and have referenced the API's adding the org-gephi-streaming-server.jar and org-gephi-streaming-api.jar files in the build path. – user1727270 May 14 '14 at 00:19

1 Answers1

0

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

p.s. 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

Neil
  • 7,482
  • 6
  • 50
  • 56