Repainting issue caused by java.util.ConcurrentModificationException

57 views
Skip to first unread message

Juan Garcia

unread,
May 2, 2017, 6:10:55 PM5/2/17
to cytoscape-helpdesk
Hi all,

I have been facing a problem when trying to repaint the cytoscape network. In response to some interaction, I need to update some 
The problem starts when I try to repaint the graph in response of some events. If the repainting is so exhaustive, then I get the network as shown in the screenshot below:





The exception trace is shown below:


2017-05-02 11:14:47,191 [pool-3-thread-1] ERROR org.cytoscape.event.internal.CyListenerAdapter - Unexpected exception while handling listener: org.cytoscape.model.events.RowsSetListener
java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.cytoscape.event.internal.CyListenerAdapter.fireEvent(CyListenerAdapter.java:120)
at org.cytoscape.event.internal.CyEventHelperImpl.flushPayloadEvents(CyEventHelperImpl.java:177)
at org.cytoscape.ding.impl.DGraphView.updateView(DGraphView.java:1098)
at org.cytoscape.internal.view.NetworkViewManager.updateView(NetworkViewManager.java:884)
at org.cytoscape.internal.view.NetworkViewManager.handleEvent(NetworkViewManager.java:614)
at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.cytoscape.event.internal.CyListenerAdapter.fireEvent(CyListenerAdapter.java:120)
at org.cytoscape.event.internal.CyEventHelperImpl.flushPayloadEvents(CyEventHelperImpl.java:177)
at org.cytoscape.event.internal.CyEventHelperImpl$1.run(CyEventHelperImpl.java:70)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.ConcurrentModificationException
at java.util.IdentityHashMap$IdentityHashMapIterator.nextIndex(IdentityHashMap.java:734)
at java.util.IdentityHashMap$EntryIterator.next(IdentityHashMap.java:842)
at java.util.IdentityHashMap$EntryIterator.next(IdentityHashMap.java:836)
at org.cytoscape.ding.impl.AbstractDViewModel.clearVisualProperties(AbstractDViewModel.java:236)
at org.cytoscape.view.vizmap.internal.ApplyToNetworkHandler.apply(ApplyToNetworkHandler.java:80)
at org.cytoscape.view.vizmap.internal.VisualStyleImpl.apply(VisualStyleImpl.java:172)
at org.cytoscape.internal.view.NetworkViewManager.updateView(NetworkViewManager.java:883)
at org.cytoscape.internal.view.NetworkViewManager.handleEvent(NetworkViewManager.java:614)
... 21 more
2017-05-02 11:14:47,220 [pool-3-thread-1] ERROR org.cytoscape.event.internal.CyListenerAdapter - Unexpected exception while handling listener: org.cytoscape.model.events.RowsSetListener
java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.cytoscape.event.internal.CyListenerAdapter.fireEvent(CyListenerAdapter.java:120)
at org.cytoscape.event.internal.CyEventHelperImpl.flushPayloadEvents(CyEventHelperImpl.java:177)
at org.cytoscape.event.internal.CyEventHelperImpl$1.run(CyEventHelperImpl.java:70)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.ConcurrentModificationException
at java.util.IdentityHashMap$IdentityHashMapIterator.nextIndex(IdentityHashMap.java:734)
at java.util.IdentityHashMap$EntryIterator.next(IdentityHashMap.java:842)
at java.util.IdentityHashMap$EntryIterator.next(IdentityHashMap.java:836)
at org.cytoscape.ding.impl.AbstractDViewModel.clearVisualProperties(AbstractDViewModel.java:236)
at org.cytoscape.view.vizmap.internal.ApplyToNetworkHandler.apply(ApplyToNetworkHandler.java:80)
at org.cytoscape.view.vizmap.internal.VisualStyleImpl.apply(VisualStyleImpl.java:172)
at org.cytoscape.internal.view.NetworkViewManager.updateView(NetworkViewManager.java:883)
at org.cytoscape.internal.view.NetworkViewManager.handleEvent(NetworkViewManager.java:614)
... 13 more



The interaction modifies some of the visual settings on the vertices:

       CyRow row = network.getRow(node);
        row.set(CyNetwork.NAME, nodeName);
        row.set(NODE_SIZE_, size);
        row.set(NODE_SHAPE_, shape);
        row.set(NODE_FILL_COLOR_, color);
        row.set(NODE_VISIBLE, visible);
        row.set(NODE_TRANSPARENCY, transparency);
        row.set(NODE_LABEL, nodeLabel);
        row.set(NODE_TYPE, type);
        row.set(NODE_BORDER_COLOR_, borderColor);
        row.set(NODE_BORDER_LINE_TYPE_, borderLineType);
        row.set(NODE_BORDER_WIDTH_, borderWidth);
...
nodeView.setVisualProperty(BasicVisualLexicon.NODE_SHAPE,shape);
        nodeView.setVisualProperty(BasicVisualLexicon.NODE_FILL_COLOR,nodeColor);
        nodeView.setVisualProperty(BasicVisualLexicon.NODE_TRANSPARENCY,transparency);
        nodeView.setVisualProperty(BasicVisualLexicon.NODE_BORDER_PAINT,borderColor);
        nodeView.setVisualProperty(BasicVisualLexicon.NODE_BORDER_LINE_TYPE,lineType);
        nodeView.setVisualProperty(BasicVisualLexicon.NODE_BORDER_WIDTH, borderWidth);
        nodeView.setVisualProperty(BasicVisualLexicon.NODE_SIZE,size);
        nodeView.setVisualProperty(BasicVisualLexicon.NODE_HEIGHT,size);
        nodeView.setVisualProperty(BasicVisualLexicon.NODE_WIDTH,size);
        nodeView.setVisualProperty(BasicVisualLexicon.NODE_LABEL_TRANSPARENCY, transparency);
        nodeView.setVisualProperty(BasicVisualLexicon.NODE_LABEL_FONT_SIZE,labelFontSize);
...
networkView.updateView();



To fix this problem, I have to force the repaint either with the option [Select] -> [Show all nodes and edges] on Cytoscape v3.2.1, or programatically for Cytoscape v3.4.0 with the following code:

...
nodeView.setVisualProperty(BasicVisualLexicon.NODE_VISIBLE,false);
...
nodeView.setVisualProperty(BasicVisualLexicon.NODE_VISIBLE,true);


The repainting process is ugly, due to it repaints so many times. My question is if is this ConcurrentModificationException a bug? or is there a way to do this repainting  process smoothly and correct?, Am I following the correct approach?

Thanks,


Juan










cytoscapeException.png

Scooter Morris

unread,
May 2, 2017, 6:19:36 PM5/2/17
to cytoscape...@googlegroups.com
Hi Juan,
    Obviously, it's a little hard to debug just looking at the snippet of code, but since you are modifying a bunch of row values, and your getting an exception in RowsSetLIstener, I would suggest calling silenceEventSource on the table before you do all of your settings, then unsilenceEventSource when you've changed everything.

-- scooter
--
You received this message because you are subscribed to the Google Groups "cytoscape-helpdesk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cytoscape-helpd...@googlegroups.com.
To post to this group, send email to cytoscape...@googlegroups.com.
Visit this group at https://groups.google.com/group/cytoscape-helpdesk.
For more options, visit https://groups.google.com/d/optout.


Juan Garcia

unread,
Aug 10, 2017, 5:50:44 PM8/10/17
to cytoscape-helpdesk
Hi Dr. Scooter,

Fortunately, I have been able to remove this exception, but I'd like to know of there is a way to improve the interaction with Cytoscape I need.
The flow that I'm following is that I have a graph (most of times a huge one) in a DB but it is not shown all at a time, due to it cannot be fitted. Instead, I just show some nodes according to a set of criteria. Then, the most basic operation is "expansion", which means to query and retrieve the connected nodes and edges from the selected nodes displayed in Cytoscape. This is when programatically I add the new nodes/edges into Cytoscape. I have only one network and network view where I add the new elements as follows:

CyNetworkView networkView = this.adapter.getCyApplicationManager().getCurrentNetworkView();

  CyNetwork network = this.adapter.getCyApplicationManager().getCurrentNetwork();


PropertyGraph.cyEventHelper.silenceEventSource(network.getDefaultNodeTable());
CyNode node = network.addNode();
CyRow row = network.getRow(node);
        row.set(CyNetwork.NAME, nodeName);
        row.set(NODE_SIZE_, size);
        row.set(NODE_SHAPE_, shape);
        row.set(NODE_FILL_COLOR_, color);
        row.set(NODE_TRANSPARENCY, transparency);
        row.set(NODE_LABEL, nodeLabel);
        row.set(NODE_TYPE, type);
        row.set(NODE_BORDER_COLOR_, borderColor);
        row.set(NODE_BORDER_LINE_TYPE_, borderLineType);
        row.set(NODE_BORDER_WIDTH_, borderWidth);
        row.set(NODE_VISIBLE, visible);

...
// moving the nodes...
View<CyNode> nodeView = networkView.getNodeView(cyNode);
nodeView.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION,x);
                nodeView.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION,y);

PropertyGraph.cyEventHelper.unsilenceEventSource(network.getDefaultNodeTable());



This is the most important fragment of code and the flow I'm following. Right now, there is a flashing effect when the nodes are being added into Cytoscape, the effect is the same, the red circles appear while the network is being repainted, and the visual settings are applied to the vertices. I'd like to have all the new elements appearing smoothly in the network without this flashing behaviour. Is there a way to achieve this?, is there any way to get this smoothly transition in the network?

I'd appreciate your comments.

Thanks,

Juan

Scooter Morris

unread,
Aug 24, 2017, 10:36:57 AM8/24/17
to cytoscape-helpdesk
Hi Juan,
   OK, couple of suggestions.  First, make sure to add all of your nodes before getting any node views.   That might help a little.  Second, I'm not sure why you're writing all of your visual property information into the node row.  You can just set the visual properties directly using setLockedValue and that will minimize the time in the loop, I think.

-- scooter
Reply all
Reply to author
Forward
0 new messages