Wait until filter finishes?

Visual manipulations and refinements
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
Apple Cider
Posts:4
Joined:17 May 2013 20:54
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
Wait until filter finishes?

Post by Apple Cider » 20 Aug 2013 18:52

Hello,

I've got a function which filters the graph and auto-lays it out. The trouble is, the filtering doesn't complete before it starts the layout. This is probably very basic, but what would be a good way to wait for filtering to complete before proceeding with the autolayout? It seems with FilterController's filterVisible(Query) method it spins off a new Thread, but I'm not sure how to deal with it. Here's what I've got going:

Code: Select all

public void filter() {
            Partition<Node> categoryPartition = partitionController.buildPartition(nodeCategory, graph);
            
            String[] categories = new String[]{"SOURCE", "SCORED", "BRIDGE"};
            Query categoryQuery = FilterUtils.createNodeQuery(categoryPartition, categories);
            Query distQuery = FilterUtils.createNeighborhoodQuery(source, 1);
            
            Query query = FilterUtils.unionQueries(new Query[]{categoryQuery, distQuery});
            
            filterController.filterVisible(query);
        }

public void layout() {
            AutoLayout layout = new AutoLayout(1, TimeUnit.SECONDS);
            layout.setGraphModel(graphModel);
            
            ForceAtlasLayout forceDirectedLayout = new ForceAtlasLayout(null);
            AutoLayout.DynamicProperty repulsionProperty = 
                AutoLayout.createDynamicProperty("forceAtlas.repulsionStrength.name",
                                                 5000D, 0f);
            layout.addLayout(forceDirectedLayout, 1f, 
                             new AutoLayout.DynamicProperty[]{repulsionProperty});
        
            layout.execute();
}
And it's executed as a LongTask in this function:

Code: Select all

public void execute() {
        Progress.setDisplayName(progressTicket, "Analytic running...");
        Progress.start(progressTicket);
        
        Progress.progress(progressTicket, "Loading graph into Gephi...");
        performImport();
        
        Progress.progress(progressTicket, "Filtering graph...");
        filter();
        
        Progress.progress(progressTicket, "Laying out graph...");
        layout();
        //and so forth...
}
I'm not sure if this is more of a Toolkit question, so apologies if it belongs there! Thanks for the help!

User avatar
seinecle
Gephi Community Support
Posts:546
Joined:08 Feb 2010 16:55
Location:Lyon, France
Contact:

Re: Wait until filter finishes?

Post by seinecle » 24 Aug 2013 08:43

I'm not a pro Java dev so this answer might be plain wrong, but at least it will take you 2 seconds to test:
=> put a return variable to your filter method:

Code: Select all

public [b]String[/b] filter() {
            Partition<Node> categoryPartition = partitionController.buildPartition(nodeCategory, graph);
            
            String[] categories = new String[]{"SOURCE", "SCORED", "BRIDGE"};
            Query categoryQuery = FilterUtils.createNodeQuery(categoryPartition, categories);
            Query distQuery = FilterUtils.createNeighborhoodQuery(source, 1);
            
            Query query = FilterUtils.unionQueries(new Query[]{categoryQuery, distQuery});
            
            filterController.filterVisible(query);

            [b]return "filtered!";[/b]
       }
Then in your execute method:

Code: Select all

          String result = filter();
This should definitely make the layout() function wait for the filter() function to return a result before getting initiated. Still I am a bit surprised because I thought Java was synchronous all the way - but it would seem that void methods are run asynchronously?

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable