I have a LinkTree where the nodes represent systems, servers, or services
within a system. The nodes have specific images associated with their
semantics and their health, and the health is polled at intervals to see if
I need to change the resource, e.g., to represent if a server is down. I
have the code working but there's a lot of flicker whenever the timer goes
off. It looks like under the scenes, the table repaints itself completely,
contracts to the root node and expands again to its previous state. The
timers are associated with each node, so I don't see why the whole tree
should repaint.
I've added logic so we only change the image resource references when the
health actually changes, so theoretically the tree should never repaint if
it's just sitting there without anyone clicking it and the health doesn't
change.
Here is some of my code. Is it obvious what I'm doing wrong? Thanks for
your time.
public class SystemLinkTree extends LinkTree
{
...
protected Component newNodeComponent(java.lang.String id, IModel model)
{
return new LinkIconPanel(id, model, SystemLinkTree.this)
{
private static final long serialVersionUID = 1L;
@Override
protected Component newImageComponent(java.lang.String
componentId, BaseTree tree, IModel model)
{
Object obj = ( ( DefaultMutableTreeNode
)model.getObject()
).getUserObject();
if ( obj instanceof PlatformInfoBean )
{
PlatformInfoBean.eRole role =
((PlatformInfoBean)obj).getRole();
switch ( role )
{
case system:
{
final Image img = new Image(
componentId, getSystemStatusIcon(((PlatformInfoBean)obj).getSystemHealth())
);
img.setOutputMarkupId(true);
hashImageToHealth.put( img.getMarkupId(
true ), ((PlatformInfoBean)obj).getSystemHealth() );
img.add( new
AjaxSelfUpdatingTimerBehavior(standardUpdateDuration)
{
@Override
protected void
onPostProcessTarget(AjaxRequestTarget target)
{
final String strRole =
((SignInSession)Session.get()).getRoleName();
ServiceHealth.Health previousHealth =
hashImageToHealth.get( img.getMarkupId( true ) );
ServiceHealth.Health currentHealth =
getSystemHealth( strRole );
if ( previousHealth != currentHealth )
{
hashImageToHealth.put(
img.getMarkupId(), currentHealth );
img.setImageResourceReference(
getSystemStatusIcon( currentHealth ) );
}
}
});
return img;
}
case access:
case storage:
final Image img = new Image( componentId,
getPlatformStatusIcon(((PlatformInfoBean)obj).getSystemHealth()) );
img.setOutputMarkupId( true );
hashImageToHealth.put( img.getMarkupId( true ),
((PlatformInfoBean)obj).getSystemHealth() );
hashPlatformImages.put( img.getMarkupId( true ),
(PlatformInfoBean)obj);
img.add( new
AjaxSelfUpdatingTimerBehavior(standardUpdateDuration)
{
@Override
protected void
onPostProcessTarget(AjaxRequestTarget target)
{
final String clientRole =
((SignInSession)Session.get()).getRoleName();
ServiceHealth.Health previousHealth =
hashImageToHealth.get( img.getMarkupId( true ) );
try
{
ServiceHealth.Health currentHealth =
PlatformAdapter.getPlatformAggregateHealth( clientRole,
hashPlatformImages.get( img.getMarkupId( true ) ).getId()
).getSystemHealth();
if ( previousHealth !=
currentHealth )
{
hashImageToHealth.put(
img.getMarkupId(), currentHealth );
img.setImageResourceReference(
getPlatformStatusIcon( currentHealth ) );
}
}
catch( Throwable t )
{
logger.warn( t.getMessage(), t);
}
}
});
return img;
}
}
else if ( obj instanceof ServiceBean )
{
final Image img = new Image( componentId,
getServiceStatusIcon( ( (ServiceBean)obj).getHealth() ) );
img.setOutputMarkupId(true);
hashImageToHealth.put( img.getMarkupId( true ),
( (
ServiceBean )obj ).getHealth() );
hashServiceImages.put( img.getMarkupId( true ),
(
ServiceBean )obj );
img.add( new
AjaxSelfUpdatingTimerBehavior(standardUpdateDuration)
{
@Override
protected void
onPostProcessTarget(AjaxRequestTarget
target)
{
final String strRole =
((SignInSession)Session.get()).getRoleName();
ServiceHealth.Health previousHealth =
hashImageToHealth.get( img.getMarkupId( true ) );
ServiceHealth.Health currentHealth =
getServiceHealth( strRole, hashServiceImages.get( img.getMarkupId( true )
).getId() ).health;
try
{
if ( previousHealth != currentHealth )
{
hashImageToHealth.put(
img.getMarkupId(), currentHealth );
img.setImageResourceReference(
getServiceStatusIcon( currentHealth ) );
}
}
catch( Throwable t )
{
logger.warn( t.getMessage(), t );
}
}
});
return img;
}
// case root
return super.newImageComponent(componentId, tree,
model);
}
--
View this message in context:
http://www.nabble.com/Flicker-on-AJAX-tree-updates-tp21730509p21730509.html
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]