leif 2002/10/26 01:52:25 Modified: instrument-client/src/java/org/apache/excalibur/instrument/client InstrumentableNodeData.java InstrumentManagerConnection.java InstrumentManagerTreeModel.java InstrumentNodeData.java InstrumentSampleNodeData.java NodeData.java Log: Make the client take advantage of state versions from the InstrumentManager. It makes the refresh action much more efficient and responsive. Revision Changes Path 1.2 +18 -5 jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/InstrumentableNodeData.java Index: InstrumentableNodeData.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/InstrumentableNodeData.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- InstrumentableNodeData.java 22 Aug 2002 16:50:38 -0000 1.1 +++ InstrumentableNodeData.java 26 Oct 2002 08:52:25 -0000 1.2 @@ -140,16 +140,29 @@ return m_registered; } + /** + * Collect latest property values from the server. Each call is remote so this + * allows us to use cached values locally to speed things up. + */ boolean update() { boolean changed = false; - changed |= update( m_descriptor.getName(), m_descriptor.getDescription() ); + changed |= update( m_descriptor.getName(), m_descriptor.getDescription(), + m_descriptor.getStateVersion() ); - changed |= ( m_descriptor.isConfigured() == m_configured ); - m_configured = m_descriptor.isConfigured(); + boolean newConfigured = m_descriptor.isConfigured(); + if ( newConfigured != m_configured ) + { + changed = true; + m_configured = newConfigured; + } - changed |= ( m_descriptor.isRegistered() == m_registered ); - m_registered = m_descriptor.isRegistered(); + boolean newRegistered = m_descriptor.isRegistered(); + if ( newRegistered != m_registered ) + { + changed = true; + m_registered = newRegistered; + } return changed; } 1.8 +3 -2 jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/InstrumentManagerConnection.java Index: InstrumentManagerConnection.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/InstrumentManagerConnection.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- InstrumentManagerConnection.java 25 Oct 2002 15:42:26 -0000 1.7 +++ InstrumentManagerConnection.java 26 Oct 2002 08:52:25 -0000 1.8 @@ -304,7 +304,8 @@ lease.getLeaseDuration(), lease.getType() ); // Refresh the Tree Model - m_treeModel.updateInstrument( instrumentDescriptor, instrumentTreeNode ); + m_treeModel.updateInstrument( instrumentDescriptor, instrumentTreeNode, + -1 /* Force Update */ ); } catch ( AltrmiInvocationException e ) { 1.5 +89 -15 jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/InstrumentManagerTreeModel.java Index: InstrumentManagerTreeModel.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/InstrumentManagerTreeModel.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- InstrumentManagerTreeModel.java 25 Oct 2002 15:42:26 -0000 1.4 +++ InstrumentManagerTreeModel.java 26 Oct 2002 08:52:25 -0000 1.5 @@ -34,7 +34,12 @@ implements InstrumentManagerConnectionListener, TreeModel { private final InstrumentManagerConnection m_connection; + + /** The last InstrumentManagerClient referenced. Used to tell when it changes. */ private InstrumentManagerClient m_lastClient; + + /** The state version of the last client. */ + private int m_lastClientStateVersion; private DefaultMutableTreeNode m_root; @@ -432,11 +437,16 @@ (DefaultMutableTreeNode)leasedSampleArray[i].getParent(); InstrumentDescriptor instrumentDescriptor = ((InstrumentNodeData)instrumentTreeNode.getUserObject()).getDescriptor(); - updateInstrument( instrumentDescriptor, instrumentTreeNode ); + updateInstrument( instrumentDescriptor, instrumentTreeNode, -1 /*Force update*/ ); } } } + /** + * Refreshes the entire Tree Model with the latest information from the server. + * This should be called whenever a refresh is needed, or whenever the status + * of the connection to the server changes. + */ void refreshModel() { // Is the connection open or not? @@ -453,6 +463,7 @@ m_elementMap.clear(); m_leasedSampleMap.clear(); m_leasedSampleArray = null; + m_lastClientStateVersion = -1; fireTreeStructureChanged( new TreeModelEvent( this, m_root.getPath() ) ); } } @@ -465,13 +476,14 @@ m_elementMap.clear(); m_leasedSampleMap.clear(); m_leasedSampleArray = null; + m_lastClientStateVersion = -1; fireTreeStructureChanged( new TreeModelEvent( this, new Object[] { m_root } ) ); } // Need to update the child nodes. (Root Instrumentables) try { - updateInstrumentables( client, m_root ); + updateInstrumentModelClient( client, m_root, m_lastClientStateVersion ); } catch ( AltrmiInvocationException e ) { @@ -483,15 +495,37 @@ m_lastClient = client; } - private void updateInstrumentables( InstrumentManagerClient client, - DefaultMutableTreeNode rootTreeNode ) + /** + * Called to update the local view of the InstrumentManagerClient in the TreeeModel. + * + * @param client The InstrumentModelClient to use for the update. + * @param roorTreeNode The TreeNode representing the client. + * @param oldStateVersion The state version at the time of the last update. + */ + private void updateInstrumentModelClient( InstrumentManagerClient client, + DefaultMutableTreeNode rootTreeNode, + int oldStateVersion ) { + int stateVersion = client.getStateVersion(); + if ( stateVersion == oldStateVersion ) + { + // Already up to date. + return; + } + + if ( getLogger().isDebugEnabled() ) + { + getLogger().debug( "update client(" + client.getName() + ") " + + "state new=" + stateVersion + ", old=" + oldStateVersion ); + } + // The latest Instrumentables will be in the correct order. InstrumentableDescriptor[] descriptors = client.getInstrumentableDescriptors(); int i; for ( i = 0; i < descriptors.length; i++ ) { InstrumentableDescriptor descriptor = descriptors[i]; + int oldInstrumentableStateVersion = -1; DefaultMutableTreeNode newChild = null; int childCount = rootTreeNode.getChildCount(); if ( i < childCount ) @@ -505,7 +539,10 @@ if ( cmp == 0 ) { // This is the same object. - if ( ((InstrumentableNodeData)oldChild.getUserObject()).update() ) + InstrumentableNodeData nodeData = + (InstrumentableNodeData)oldChild.getUserObject(); + oldInstrumentableStateVersion = nodeData.getStateVersion(); + if ( nodeData.update() ) { // The contents of the node changed. fireTreeNodesChanged( new TreeModelEvent( this, @@ -555,7 +592,7 @@ getName(), newChild ); } - updateInstrumentable( descriptor, newChild ); + updateInstrumentable( descriptor, newChild, oldInstrumentableStateVersion ); } // Remove any remaining old nodes while ( i < rootTreeNode.getChildCount() ) @@ -570,6 +607,8 @@ m_elementMap.remove( ((InstrumentableNodeData)oldChild.getUserObject()). getName() ); } + + m_lastClientStateVersion = stateVersion; } /** @@ -577,11 +616,25 @@ * update. * @param instrumentableTreeNode The tree node of the Instrumentable to * update. + * @param oldStateVersion The state version at the time of the last update. */ - private void updateInstrumentable( - InstrumentableDescriptor instrumentableDescriptor, - DefaultMutableTreeNode instrumentableTreeNode ) + private void updateInstrumentable( InstrumentableDescriptor instrumentableDescriptor, + DefaultMutableTreeNode instrumentableTreeNode, + int oldStateVersion ) { + int stateVersion = instrumentableDescriptor.getStateVersion(); + if ( stateVersion == oldStateVersion ) + { + // Already up to date. + return; + } + + if ( getLogger().isDebugEnabled() ) + { + getLogger().debug( "update instrumentable(" + instrumentableDescriptor.getName() + ") " + + "state new=" + stateVersion + ", old=" + oldStateVersion ); + } + // The latest Instrumentables will be in the correct order. InstrumentableDescriptor[] descriptors = instrumentableDescriptor.getChildInstrumentableDescriptors(); @@ -590,6 +643,7 @@ for ( i = 0; i < descriptors.length; i++ ) { InstrumentableDescriptor descriptor = descriptors[i]; + int oldInstrumentableStateVersion = -1; //System.out.println(" " + descriptor.getName() ); DefaultMutableTreeNode newChild = null; int childCount = instrumentableTreeNode.getChildCount(); @@ -613,7 +667,10 @@ if ( cmp == 0 ) { // This is the same object. - if ( ((InstrumentableNodeData)oldChild.getUserObject()).update() ) + InstrumentableNodeData nodeData = + (InstrumentableNodeData)oldChild.getUserObject(); + oldInstrumentableStateVersion = nodeData.getStateVersion(); + if ( nodeData.update() ) { // The contents of the node changed. fireTreeNodesChanged( new TreeModelEvent( this, @@ -666,7 +723,7 @@ getName(), newChild ); } - updateInstrumentable( descriptor, newChild ); + updateInstrumentable( descriptor, newChild, oldInstrumentableStateVersion ); } // Remove any remaining old Instrumentable nodes while ( i < instrumentableTreeNode.getChildCount() ) @@ -696,6 +753,7 @@ for ( i = descriptors.length; i < instrumentDescriptors.length + descriptors.length; i++ ) { InstrumentDescriptor descriptor = instrumentDescriptors[i - descriptors.length]; + int oldInstrumentStateVersion = -1; //System.out.println(" " + descriptor.getName() ); DefaultMutableTreeNode newChild = null; int childCount = instrumentableTreeNode.getChildCount(); @@ -719,7 +777,9 @@ if ( cmp == 0 ) { // This is the same object. - if ( ((InstrumentNodeData)oldChild.getUserObject()).update() ) + InstrumentNodeData nodeData = (InstrumentNodeData)oldChild.getUserObject(); + oldInstrumentStateVersion = nodeData.getStateVersion(); + if ( nodeData.update() ) { // The contents of the node changed. fireTreeNodesChanged( new TreeModelEvent( this, @@ -772,7 +832,7 @@ getName(), newChild ); } - updateInstrument( descriptor, newChild ); + updateInstrument( descriptor, newChild, oldInstrumentStateVersion ); } // Remove any remaining old Instrument nodes while ( i < instrumentableTreeNode.getChildCount() ) @@ -801,7 +861,7 @@ getInstrumentTreeNode( instrumentDescriptor.getName() ); if ( instrumentTreeNode != null ) { - updateInstrument( instrumentDescriptor, instrumentTreeNode ); + updateInstrument( instrumentDescriptor, instrumentTreeNode, -1 /* Force update */ ); } } @@ -810,8 +870,22 @@ * @param instrumentTreeNode The tree node of the Instrument to update. */ void updateInstrument( InstrumentDescriptor instrumentDescriptor, - DefaultMutableTreeNode instrumentTreeNode ) + DefaultMutableTreeNode instrumentTreeNode, + int oldStateVersion ) { + int stateVersion = instrumentDescriptor.getStateVersion(); + if ( stateVersion == oldStateVersion ) + { + // Already up to date. + return; + } + + if ( getLogger().isDebugEnabled() ) + { + getLogger().debug( "update instrument(" + instrumentDescriptor.getName() + ") " + + "state new=" + stateVersion + ", old=" + oldStateVersion ); + } + // The latest Instrument Samples will be in the correct order. InstrumentSampleDescriptor[] descriptors = instrumentDescriptor.getInstrumentSampleDescriptors(); 1.2 +20 -7 jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/InstrumentNodeData.java Index: InstrumentNodeData.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/InstrumentNodeData.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- InstrumentNodeData.java 22 Aug 2002 16:50:38 -0000 1.1 +++ InstrumentNodeData.java 26 Oct 2002 08:52:25 -0000 1.2 @@ -260,16 +260,29 @@ boolean update() { boolean changed = false; - changed |= update( m_descriptor.getName(), m_descriptor.getDescription() ); + changed |= update( m_descriptor.getName(), m_descriptor.getDescription(), + m_descriptor.getStateVersion() ); - changed |= ( m_descriptor.isConfigured() == m_configured ); - m_configured = m_descriptor.isConfigured(); + boolean newConfigured = m_descriptor.isConfigured(); + if ( newConfigured != m_configured ) + { + changed = true; + m_configured = newConfigured; + } - changed |= ( m_descriptor.isRegistered() == m_registered ); - m_registered = m_descriptor.isRegistered(); + boolean newRegistered = m_descriptor.isRegistered(); + if ( newRegistered != m_registered ) + { + changed = true; + m_registered = newRegistered; + } - changed |= ( m_descriptor.getType() == m_type ); - m_type = m_descriptor.getType(); + int newType = m_descriptor.getType(); + if ( newType != m_type ) + { + changed = true; + m_type = newType; + } return changed; } 1.2 +32 -16 jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/InstrumentSampleNodeData.java Index: InstrumentSampleNodeData.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/InstrumentSampleNodeData.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- InstrumentSampleNodeData.java 22 Aug 2002 16:50:38 -0000 1.1 +++ InstrumentSampleNodeData.java 26 Oct 2002 08:52:25 -0000 1.2 @@ -387,27 +387,43 @@ boolean update() { boolean changed = false; - changed |= update( m_descriptor.getName(), m_descriptor.getDescription() ); + changed |= update( m_descriptor.getName(), m_descriptor.getDescription(), + m_descriptor.getStateVersion() ); - boolean configured = m_descriptor.isConfigured(); - changed |= ( configured == m_configured ); - m_configured = configured; + boolean newConfigured = m_descriptor.isConfigured(); + if ( newConfigured != m_configured ) + { + changed = true; + m_configured = newConfigured; + } - long leaseExpireTime = m_descriptor.getLeaseExpirationTime(); - changed |= ( leaseExpireTime == m_leaseExpireTime ); - m_leaseExpireTime = leaseExpireTime; + long newLeaseExpireTime = m_descriptor.getLeaseExpirationTime(); + if ( newLeaseExpireTime != m_leaseExpireTime ) + { + changed = true; + m_leaseExpireTime = newLeaseExpireTime; + } - int type = m_descriptor.getType(); - changed |= ( type == m_type ); - m_type = type; + int newType = m_descriptor.getType(); + if ( newType != m_type ) + { + changed = true; + m_type = newType; + } - int size = m_descriptor.getSize(); - changed |= ( size == m_size ); - m_size = size; + int newSize = m_descriptor.getSize(); + if ( newSize != m_size ) + { + changed = true; + m_size = newSize; + } - long interval = m_descriptor.getInterval(); - changed |= ( interval == m_interval ); - m_interval = interval; + long newInterval = m_descriptor.getInterval(); + if ( newInterval != m_interval ) + { + changed = true; + m_interval = newInterval; + } return changed; } 1.2 +10 -1 jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/NodeData.java Index: NodeData.java =================================================================== RCS file: /home/cvs/jakarta-avalon-excalibur/instrument-client/src/java/org/apache/excalibur/instrument/client/NodeData.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- NodeData.java 22 Aug 2002 16:50:38 -0000 1.1 +++ NodeData.java 26 Oct 2002 08:52:25 -0000 1.2 @@ -18,6 +18,7 @@ private String m_name; private String m_description; + private int m_stateVersion; /*--------------------------------------------------------------- * Constructors @@ -44,6 +45,11 @@ m_description = description; } + int getStateVersion() + { + return m_stateVersion; + } + /** * Get the icon to display for the node. * @@ -102,7 +108,7 @@ } - boolean update( String name, String description ) + boolean update( String name, String description, int stateVersion ) { boolean changed = false; @@ -111,6 +117,9 @@ changed |= description.equals( m_description ); m_description = description; + + changed |= stateVersion == m_stateVersion; + m_stateVersion = stateVersion; return changed; }
-- To unsubscribe, e-mail: <mailto:avalon-cvs-unsubscribe@;jakarta.apache.org> For additional commands, e-mail: <mailto:avalon-cvs-help@;jakarta.apache.org>