|
|
|
|
@ -5,9 +5,12 @@
|
|
|
|
|
|
|
|
|
|
package phaselistener;
|
|
|
|
|
|
|
|
|
|
import com.evolute.utils.date.DateUtils;
|
|
|
|
|
import com.evolute.utils.error.ErrorLogger;
|
|
|
|
|
import com.evolute.utils.timer.TimedEvent;
|
|
|
|
|
import com.evolute.utils.timer.Timer;
|
|
|
|
|
import db.DBConstants.DB;
|
|
|
|
|
import db.providers.EvoBaseProvider;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import javax.servlet.ServletContextEvent;
|
|
|
|
|
@ -23,29 +26,11 @@ import utils.PlanosActuacaoLogger;
|
|
|
|
|
public class ContextListener implements ServletContextListener
|
|
|
|
|
{
|
|
|
|
|
private static final int IMPORT_INTERVAL = 300;
|
|
|
|
|
|
|
|
|
|
private static Boolean loggerIsLoaded = Boolean.FALSE;
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if ( ! loggerIsLoaded )
|
|
|
|
|
{
|
|
|
|
|
System.out.println( "\nInitializing PA logger ..." );
|
|
|
|
|
PlanosActuacaoLogger.init();
|
|
|
|
|
loggerIsLoaded = Boolean.TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch ( Throwable e )
|
|
|
|
|
{
|
|
|
|
|
e.printStackTrace( System.err );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private long startedTime = 0L;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private TimedEvent importEvent = null;
|
|
|
|
|
|
|
|
|
|
public void contextInitialized( ServletContextEvent sce )
|
|
|
|
|
{
|
|
|
|
|
startedTime = System.currentTimeMillis();
|
|
|
|
|
@ -53,19 +38,38 @@ public class ContextListener implements ServletContextListener
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
System.out.println( "\tReading app.properties ..." );
|
|
|
|
|
System.out.println( "\n\tReading app.properties ..." );
|
|
|
|
|
SIPRPPropertiesLoader props = SIPRPPropertiesLoader.getInstance();
|
|
|
|
|
props.load();
|
|
|
|
|
}
|
|
|
|
|
catch ( Exception e )
|
|
|
|
|
{
|
|
|
|
|
ErrorLogger.logException( e );
|
|
|
|
|
// ErrorLogger.logException( e );
|
|
|
|
|
System.out.println( "\n\n<---- ERROR ! " + e.getMessage() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
System.out.println( "\nInitializing db ..." );
|
|
|
|
|
EvoBaseProvider.getInstance();
|
|
|
|
|
}
|
|
|
|
|
catch ( Exception e )
|
|
|
|
|
{
|
|
|
|
|
ErrorLogger.logException( e );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
System.out.println( "\nInitializing PA logger ..." );
|
|
|
|
|
PlanosActuacaoLogger.init();
|
|
|
|
|
}
|
|
|
|
|
catch ( Throwable e )
|
|
|
|
|
{
|
|
|
|
|
e.printStackTrace( System.err );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println( "\nScheduling Import Event ... " );
|
|
|
|
|
TimedEvent importEvent = new TimedEvent()
|
|
|
|
|
importEvent = new TimedEvent()
|
|
|
|
|
{
|
|
|
|
|
public void executeAction() throws Exception
|
|
|
|
|
{
|
|
|
|
|
@ -82,36 +86,36 @@ public class ContextListener implements ServletContextListener
|
|
|
|
|
};
|
|
|
|
|
Timer.scheduleEvent( importEvent, IMPORT_INTERVAL );
|
|
|
|
|
System.out.println( "\tExecuting Import each " + ( IMPORT_INTERVAL / 60 ) + " minutes." );
|
|
|
|
|
|
|
|
|
|
// if ( ! getApplicationBean1().isTimerStarted() )
|
|
|
|
|
// {
|
|
|
|
|
// Timer.scheduleEvent( new TimedEvent()
|
|
|
|
|
// {
|
|
|
|
|
// public void executeAction() throws Exception
|
|
|
|
|
// {
|
|
|
|
|
// try
|
|
|
|
|
// {
|
|
|
|
|
// PlanosActuacao planos = new PlanosActuacao();
|
|
|
|
|
// }
|
|
|
|
|
// catch( Exception ex )
|
|
|
|
|
// {
|
|
|
|
|
// ErrorLogger.logException( ex );
|
|
|
|
|
// }
|
|
|
|
|
// Timer.resetEvent( this );
|
|
|
|
|
// }
|
|
|
|
|
// }, 300 );
|
|
|
|
|
// getApplicationBean1().setTimerStarted( true );
|
|
|
|
|
// }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void contextDestroyed( ServletContextEvent sce )
|
|
|
|
|
{
|
|
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
|
|
System.out.println( "\ncontextDestroyed() : " );
|
|
|
|
|
|
|
|
|
|
if ( importEvent != null )
|
|
|
|
|
{
|
|
|
|
|
System.out.println( "\tStopping import timer ..." );
|
|
|
|
|
Timer.abortEvent( importEvent );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
System.out.println( "\nClosing provider connections" );
|
|
|
|
|
EvoBaseProvider.getInstance().getProvider( DB.SIPRP ).close();
|
|
|
|
|
EvoBaseProvider.getInstance().getProvider( DB.SIPRP_LOCAL ).close();
|
|
|
|
|
EvoBaseProvider.getInstance().getDbManager( DB.SIPRP_LOCAL ).close();
|
|
|
|
|
EvoBaseProvider.getInstance().getDbManager( DB.SIPRP ).close();
|
|
|
|
|
}
|
|
|
|
|
catch ( Exception e )
|
|
|
|
|
{
|
|
|
|
|
ErrorLogger.logException( e );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
|
|
SimpleDateFormat D_F = new SimpleDateFormat( "dd-MM-yyyy HH:mm:ss" );
|
|
|
|
|
Date startDate = new Date( startedTime );
|
|
|
|
|
Date endDate = new Date( endTime );
|
|
|
|
|
|
|
|
|
|
System.out.println( "\ncontextDestroyed : " + D_F.format( startDate ) + " -> " + D_F.format( endDate ) + " = " + ( (endTime - startedTime) / 1000 ) + " s" );
|
|
|
|
|
String timePassed = DateUtils.getTimePassed( startedTime, endTime );
|
|
|
|
|
System.out.println( "\trunning for: " + D_F.format( startDate ) + " -> " + D_F.format( endDate ) + " = " + ( (endTime - startedTime) / 1000 ) + " s ; " + timePassed );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|