Modified Global to refresh it's stats in a separate thread to avoid Hibernate Load collisions.

This commit is contained in:
dubtraxis 2003-10-21 20:20:01 +00:00
parent cd65eb18b9
commit 538d753f28
4 changed files with 66 additions and 15 deletions

View file

@ -1,5 +1,5 @@
package org.thdl.lex; package org.thdl.lex;
import java.io.*;
import java.util.*; import java.util.*;
import org.thdl.lex.component.*; import org.thdl.lex.component.*;
@ -27,8 +27,13 @@ public class Global
*/ */
public Date getLastUpdate() throws LexRepositoryException public Date getLastUpdate() throws LexRepositoryException
{ {
ITerm term = (ITerm) getRecentTerms().get( 0 ); Date date = null;
return term.getMeta().getModifiedOn(); if ( null != getRecentTerms() && getRecentTerms().size() > 0 )
{
ITerm term = (ITerm) getRecentTerms().get( 0 );
date = term.getMeta().getModifiedOn();
}
return date;
} }
@ -177,8 +182,8 @@ public class Global
*/ */
public void doRefresh() throws LexRepositoryException public void doRefresh() throws LexRepositoryException
{ {
int limit = getRecentTermsCount(); GlobalRefresher gr = new GlobalRefresher();
setRecentTerms( LexComponentRepository.getRecentTerms( limit ) ); new Thread( gr ).start();
} }
@ -199,5 +204,41 @@ public class Global
setRecentTermsCount( recentItems ); setRecentTermsCount( recentItems );
setRefreshDelay( refreshDelay ); setRefreshDelay( refreshDelay );
} }
/**
* Description of the Class
*
* @author travis
* @created October 21, 2003
*/
class GlobalRefresher implements Runnable
{
/**
* Main processing method for the GlobalRefresher object
*/
public void run()
{
int limit = getRecentTermsCount();
try
{
setRecentTerms( LexComponentRepository.getRecentTerms( limit ) );
}
catch ( Exception e )
{
StringWriter writer = new StringWriter();
e.printStackTrace( new PrintWriter( writer ) );
String stackTrace = writer.getBuffer().toString();
LexLogger.error( "GlobalRefresher Thread caught an Exception: " + stackTrace );
}
}
/**
*Constructor for the GlobalRefresher object
*/
GlobalRefresher() { }
}
} }

View file

@ -96,7 +96,8 @@ public class LexComponentFilter implements Filter
try try
{ {
setBlanks( new HashMap() ); setBlanks( new HashMap() );
getBlanks().put( LexConstants.TERMLABEL_VALUE, new Term() ); ITerm term = new Term();
getBlanks().put( LexConstants.TERMLABEL_VALUE, term );
getBlanks().put( LexConstants.PRONUNCIATIONLABEL_VALUE, new Pronunciation() ); getBlanks().put( LexConstants.PRONUNCIATIONLABEL_VALUE, new Pronunciation() );
getBlanks().put( LexConstants.ETYMOLOGYLABEL_VALUE, new Etymology() ); getBlanks().put( LexConstants.ETYMOLOGYLABEL_VALUE, new Etymology() );
getBlanks().put( LexConstants.FUNCTIONLABEL_VALUE, new GrammaticalFunction() ); getBlanks().put( LexConstants.FUNCTIONLABEL_VALUE, new GrammaticalFunction() );
@ -145,15 +146,15 @@ public class LexComponentFilter implements Filter
{ {
if ( getBlanks().get( labelValue ) != null ) if ( getBlanks().get( labelValue ) != null )
{ {
Class glass = getBlanks().get( labelValue ).getClass(); Class c = getBlanks().get( labelValue ).getClass();
LexComponent component = (LexComponent) glass.newInstance(); LexComponent component = (LexComponent) c.newInstance();
component.populate( req.getParameterMap() ); component.populate( req.getParameterMap() );
component.getMeta().populate( req.getParameterMap() ); component.getMeta().populate( req.getParameterMap() );
req.setAttribute( LexConstants.COMPONENT_REQ_ATTR, component ); req.setAttribute( LexConstants.COMPONENT_REQ_ATTR, component );
} }
else else
{ {
req.setAttribute( "LCFilter says: ", "componentLabel was not in blank components" ); LexLogger.error( "componentLabel was not in blank components" );
} }
} }
catch ( InstantiationException ie ) catch ( InstantiationException ie )
@ -171,7 +172,7 @@ public class LexComponentFilter implements Filter
} }
else else
{ {
req.setAttribute( "LexComponentFilter says: '", LexConstants.LABEL_REQ_PARAM + "' was not specified." ); LexLogger.error( "Required parameter, '" + LexConstants.LABEL_REQ_PARAM + "' was not specified." );
} }
chain.doFilter( request, response ); chain.doFilter( request, response );
@ -187,7 +188,7 @@ public class LexComponentFilter implements Filter
LexLogger.debug( "Checking Request state at end of LexComponentFilter.doFilter()" ); LexLogger.debug( "Checking Request state at end of LexComponentFilter.doFilter()" );
LexLogger.logRequestState( req ); LexLogger.logRequestState( req );
LexLogger.logSessionState( req ); LexLogger.logSessionState( req );
*/ */
long dur = System.currentTimeMillis() - start; long dur = System.currentTimeMillis() - start;
LexLogger.debug( "Total Request took: " + dur / 1000 + " seconds.\n\n" ); LexLogger.debug( "Total Request took: " + dur / 1000 + " seconds.\n\n" );
} }

View file

@ -126,6 +126,17 @@ public class LexLogger
} }
/**
* Description of the Method
*
* @param msg Description of the Parameter
*/
public static void error( String msg )
{
LOGGER.error( msg );
}
/** /**
*Constructor for the debugComponent object *Constructor for the debugComponent object
* *
@ -151,8 +162,6 @@ public class LexLogger
String stackTrace = writer.getBuffer().toString(); String stackTrace = writer.getBuffer().toString();
LOGGER.debug( "LexLogger caught an Exception: " + stackTrace ); LOGGER.debug( "LexLogger caught an Exception: " + stackTrace );
} }
} }
} }

View file

@ -79,12 +79,12 @@ public class DisplayCommand extends LexCommand implements Command
} }
displayHelper.populate( req.getParameterMap() ); displayHelper.populate( req.getParameterMap() );
} }
else else
{ {
setNext( "menu.jsp" ); setNext( "menu.jsp" );
msg = "The component you were trying to display was not a term."; msg = "The component set for display was not a term.";
LexLogger.error( msg );
} }
req.setAttribute( LexConstants.MESSAGE_REQ_ATTR, msg ); req.setAttribute( LexConstants.MESSAGE_REQ_ATTR, msg );