Advertisement
Guest User

Blocking ViewerPipe

a guest
May 28th, 2013
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. import org.graphstream.graph.Graph;
  2. import org.graphstream.stream.thread.ThreadProxyPipe;
  3. import org.graphstream.ui.swingViewer.Viewer;
  4. import org.graphstream.ui.swingViewer.ViewerPipe;
  5. import org.miv.mbox.MBoxStandalone;
  6.  
  7. public class BlockingViewerPipe extends ViewerPipe {
  8.     public BlockingViewerPipe(Viewer viewer) {
  9.         super(String.format("viewer_%d", (int) (Math.random() * 10000)),
  10.                 new BlockingThreadProxyPipe(viewer.getGraphicGraph(), false));
  11.     }
  12.  
  13.     private static class BlockingThreadProxyPipe extends ThreadProxyPipe {
  14.         public BlockingThreadProxyPipe(Graph g, boolean replayGraph) {
  15.             super(g, replayGraph);
  16.             ((MBoxStandalone) events).setNotifyOnPost(true);
  17.         }
  18.  
  19.         @Override
  20.         public void pump() {
  21.             if (((MBoxStandalone) events).getMessageCount() == 0)
  22.                 try {
  23.                     synchronized (events) {
  24.                         events.wait();
  25.                     }
  26.                 } catch (InterruptedException e) {
  27.                     e.printStackTrace();
  28.                 }
  29.  
  30.             super.pump();
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement