[jboss-cvs] JBossCache/src/org/jboss/cache/demo ...

Galder Zamarreno galder.zamarreno at jboss.com
Fri May 18 15:38:28 EDT 2007


  User: gzamarreno
  Date: 07/05/18 15:38:28

  Modified:    src/org/jboss/cache/demo   JBossCacheView.java
                        JBossCacheGUI.java
  Log:
  [JBCACHE-1041] GUI updates originating from clicking on nodes in the tree structure and mouse clicks are now handled in a separate thread to avoid locking the GUI. TimeoutExceptions that could be thrown from these code areas provide a hint on what might the cause of the exception.
  
  Revision  Changes    Path
  1.2       +2 -2      JBossCache/src/org/jboss/cache/demo/JBossCacheView.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JBossCacheView.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/demo/JBossCacheView.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- JBossCacheView.java	16 May 2007 12:33:59 -0000	1.1
  +++ JBossCacheView.java	18 May 2007 19:38:28 -0000	1.2
  @@ -27,7 +27,7 @@
    *
    * @author Manik Surtani
    * @author <a href="mailto:galder.zamarreno at jboss.com">Galder Zamarreno</a>
  - * @version $Revision: 1.1 $
  + * @version $Revision: 1.2 $
    */
   public class JBossCacheView
   {
  @@ -71,7 +71,7 @@
      public void setCacheModelDelegate(CacheModelDelegate cacheModelDelegate)
      {
         this.cacheModelDelegate = cacheModelDelegate;
  -      if (gui != null) gui.setCacheDelegate(cacheModelDelegate);
  +      if (gui != null) gui.setCacheModelDelegate(cacheModelDelegate);
      }
   
      /**
  
  
  
  1.2       +86 -35    JBossCache/src/org/jboss/cache/demo/JBossCacheGUI.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JBossCacheGUI.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/demo/JBossCacheGUI.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- JBossCacheGUI.java	16 May 2007 12:33:59 -0000	1.1
  +++ JBossCacheGUI.java	18 May 2007 19:38:28 -0000	1.2
  @@ -7,6 +7,7 @@
   package org.jboss.cache.demo;
   
   import org.jboss.cache.*;
  +import org.jboss.cache.lock.TimeoutException;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.jgroups.Address;
  @@ -46,7 +47,7 @@
   {
      private static final long serialVersionUID = -1242167331988194987L;
   
  -   private CacheModelDelegate cacheDelegate;
  +   private CacheModelDelegate cacheModelDelegate;
      private Cache cache;
      private DefaultTreeModel tree_model = null;
      private Log log = LogFactory.getLog(getClass());
  @@ -67,6 +68,12 @@
      private Address coordinator = null;
      private boolean useConsole = false;
   
  +   /**
  +    * Run any work that happens in this interface in a separate thread.  This is good practise. Initialised to 3
  +    * threads based on the number of concurrent actions that could be happening at the same time (view change,
  +    * click on node,...etc) 
  +    */
  +   private Executor executor = Executors.newFixedThreadPool(3);
   
      public JBossCacheGUI(CacheModelDelegate cacheDelegate, boolean useConsole) throws Exception
      {
  @@ -138,12 +145,20 @@
   
         MouseListener ml = new MouseAdapter()
         {
  -         public void mouseClicked(MouseEvent e)
  +         public void mouseClicked(final MouseEvent e)
            {
  -            int selRow = jtree.getRowForLocation(e.getX(), e.getY());
  -            TreePath selPath = jtree.getPathForLocation(e.getX(), e.getY());
  +            if (log.isTraceEnabled()) { log.trace("clicked GUI"); };
  +                        
  +            final int selRow = jtree.getRowForLocation(e.getX(), e.getY());
  +            final TreePath selPath = jtree.getPathForLocation(e.getX(), e.getY());
               if (selRow != -1)
               {
  +               Runnable r = new Runnable()
  +               {
  +                  public void run()
  +                  {
  +                     try
  +                     {
                  selected_node = getNode(selPath.getPath());
                  jtree.setSelectionPath(selPath);
   
  @@ -152,6 +167,21 @@
                     operationsPopup.show(e.getComponent(), e.getX(), e.getY());
                  }
               }
  +                     catch (TimeoutException te)
  +                     {
  +                        String message = "Unable to update GUI due to a timeout trying to acquire lock on a node." +
  +                                "This might be due to clicking on a node which is currently locked by an ongoing " +
  +                                "transaction: ";
  +                        printAndLogStacktrace(message, te);
  +                     }
  +                     catch (Exception e)
  +                     {
  +                        printAndLogStacktrace("Updating GUI failed: ", e);
  +                     }
  +                  }
  +               };
  +               executor.execute(r);
  +            }
            }
         };
   
  @@ -162,7 +192,7 @@
         setSize(getInsets().left + getInsets().right + 800, getInsets().top + getInsets().bottom + 800);
   
         // make sure we set the cache BEFORE initialising this!!
  -      setCacheDelegate(cacheDelegate);
  +      setCacheModelDelegate(cacheDelegate);
         init();
         setVisible(true);
   
  @@ -173,12 +203,12 @@
         }
      }
   
  -   public void setCacheDelegate(final CacheModelDelegate cacheDelegate)
  +   public void setCacheModelDelegate(final CacheModelDelegate cacheModelDelegate)
      {
  -      this.cacheDelegate = cacheDelegate;
  -      cache = this.cacheDelegate.getGenericCache();
  +      this.cacheModelDelegate = cacheModelDelegate;
  +      cache = this.cacheModelDelegate.getGenericCache();
   
  -      if (this.cacheDelegate != null)
  +      if (this.cacheModelDelegate != null)
         {
            Runtime.getRuntime().addShutdownHook(
                  new Thread()
  @@ -258,6 +288,8 @@
   
      public void tableChanged(TableModelEvent evt)
      {
  +      if (log.isTraceEnabled()) { log.trace("table contents changed: " + evt ); };
  +
         int row, col;
         String key, val;
   
  @@ -286,12 +318,18 @@
      }
   
   
  -   public void valueChanged(TreeSelectionEvent evt)
  +   public void valueChanged(final TreeSelectionEvent evt)
      {
  -      TreePath path = evt.getPath();
  -      Map<String, String> data;
  +      if (log.isTraceEnabled()) { log.trace("node was selected in GUI: " + evt.getPath()); }
   
  -      selected_node = getNode(path.getPath());
  +      Runnable r = new Runnable()
  +      {
  +         public void run()
  +         {
  +            try
  +            {
  +               Map<String, String> data;
  +               selected_node = getNode(evt.getPath().getPath());
         data = selected_node.getData();
         if (data != null)
         {
  @@ -306,6 +344,21 @@
            validate();
         }
      }
  +            catch (TimeoutException te)
  +            {
  +               String message = "Unable to update GUI due to a timeout trying to acquire lock on a node." +
  +                       "This might be due to clicking on a node which is currently locked by an ongoing " +
  +                       "transaction: ";
  +               printAndLogStacktrace(message, te);
  +            }
  +            catch (Exception e)
  +            {
  +               printAndLogStacktrace("Updating GUI failed: ", e);
  +            }
  +         }
  +      };
  +      executor.execute(r);
  +   }
   
      protected DefaultTableModel getTableModel()
      {
  @@ -336,10 +389,6 @@
   
      /* ------------------ CacheListener interface ------------ */
   
  -   // run any work that happens in this interface in a separate thread.  This is good practise.
  -   private Executor executor = Executors.newFixedThreadPool(1);
  -
  -
      public void nodeCreated(final Fqn fqn, final boolean pre, boolean isLocal)
      {
         Runnable r = new Runnable()
  @@ -1021,6 +1070,8 @@
   
         public void actionPerformed(ActionEvent e)
         {
  +         if (log.isTraceEnabled()) { log.trace("node added/modified, updating GUI: " + e); }
  +
            clearTable();
            Map<String, String> data = selected_node.getData();
            if (data == null || data.isEmpty())
  
  
  



More information about the jboss-cvs-commits mailing list