TimerGestorePuliziaMessaggiAnomaliThread.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */



  20. package org.openspcoop2.pdd.timers;

  21. import org.slf4j.Logger;
  22. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  23. import org.openspcoop2.pdd.core.CostantiPdD;
  24. import org.openspcoop2.pdd.logger.MsgDiagnosticiProperties;
  25. import org.openspcoop2.pdd.logger.MsgDiagnostico;
  26. import org.openspcoop2.pdd.logger.OpenSPCoop2Logger;
  27. import org.openspcoop2.pdd.services.OpenSPCoop2Startup;
  28. import org.openspcoop2.utils.Utilities;
  29. import org.openspcoop2.utils.threads.BaseThread;

  30. /**
  31.  * Thread per la gestione del Threshold
  32.  *
  33.  *  
  34.  * @author Poli Andrea (apoli@link.it)
  35.  * @author $Author$
  36.  * @version $Rev$, $Date$
  37.  */
  38. public class TimerGestorePuliziaMessaggiAnomaliThread extends BaseThread{

  39.     /** Properties Reader */
  40.     private OpenSPCoop2Properties propertiesReader;
  41.     /** MsgDiagnostico */
  42.     private MsgDiagnostico msgDiag;
  43.    
  44.     /** Logger utilizzato per debug. */
  45.     private Logger logTimer = null;

  46.     /** Indicazione se deve essere effettuato il log delle query */
  47.     private boolean logQuery = false;
  48.     /** Numero di messaggi prelevati sulla singola query */
  49.     private int limit = CostantiPdD.LIMIT_MESSAGGI_GESTORI;
  50.     /** Indicazione se deve essere effettuato l'order by nelle query */
  51.     private boolean orderByQuery = false;
  52.    
  53.    
  54.     /** Costruttore */
  55.     public TimerGestorePuliziaMessaggiAnomaliThread() throws TimerException{
  56.        
  57.         // Aspetto inizializzazione di OpenSPCoop (aspetto mezzo minuto e poi segnalo errore)
  58.         int attesa = 90;
  59.         int secondi = 0;
  60.         while( (OpenSPCoop2Startup.initialize==false) && (secondi<attesa) ){
  61.             Utilities.sleep(1000);
  62.             secondi++;
  63.         }
  64.         if(secondi>= 90){
  65.             throw new TimerException("Riscontrata inizializzazione OpenSPCoop non effettuata");
  66.         }  

  67.         this.logTimer = OpenSPCoop2Logger.getLoggerOpenSPCoopTimers();
  68.        
  69.         try {
  70.             this.msgDiag = MsgDiagnostico.newInstance(TimerGestorePuliziaMessaggiAnomali.ID_MODULO);
  71.             this.msgDiag.setPrefixMsgPersonalizzati(MsgDiagnosticiProperties.MSG_DIAG_TIMER_GESTORE_MESSAGGI_INCONSISTENTI);
  72.             this.msgDiag.addKeyword(CostantiPdD.KEY_TIMER_GESTORE_MESSAGGI_INCONSISTENTI, TimerGestorePuliziaMessaggiAnomali.ID_MODULO);
  73.         } catch (Exception e) {
  74.             String msgErrore = "Riscontrato Errore durante l'inizializzazione del MsgDiagnostico";
  75.             this.logTimer.error(msgErrore,e);
  76.             throw new TimerException(msgErrore,e);
  77.         }

  78.         this.msgDiag.logPersonalizzato("avvioInCorso");
  79.         this.logTimer.info(this.msgDiag.getMessaggio_replaceKeywords("avvioInCorso"));
  80.        
  81.         try {
  82.             this.propertiesReader = OpenSPCoop2Properties.getInstance();
  83.         } catch (Exception e) {
  84.             this.msgDiag.logErroreGenerico(e,"InizializzazioneTimer");
  85.             String msgErrore = "Riscontrato errore durante l'inizializzazione del Reader delle Properties di OpenSPCoop: "+e.getMessage();
  86.             this.logTimer.error(msgErrore,e);
  87.             throw new TimerException(msgErrore,e);
  88.         }

  89.         this.setTimeout((int) this.propertiesReader.getRepositoryIntervalloEliminazioneMessaggi());
  90.         String s = "secondi";
  91.         if(this.getTimeout() == 1)
  92.             s = "secondo";
  93.         this.msgDiag.addKeyword(CostantiPdD.KEY_TIMEOUT, this.getTimeout()+" "+s);
  94.        
  95.         this.logQuery = this.propertiesReader.isTimerGestorePuliziaMessaggiAnomaliAbilitatoLog();
  96.         this.orderByQuery = this.propertiesReader.isTimerGestorePuliziaMessaggiAnomaliAbilitatoOrderBy();
  97.        
  98.         this.limit = this.propertiesReader.getTimerGestorePuliziaMessaggiAnomaliLimit();
  99.         if(this.limit<=0){
  100.             this.limit = CostantiPdD.LIMIT_MESSAGGI_GESTORI;
  101.         }
  102.         this.msgDiag.addKeyword(CostantiPdD.KEY_LIMIT, this.limit+"");
  103.        
  104.         this.msgDiag.logPersonalizzato("avvioEffettuato");
  105.         this.logTimer.info(this.msgDiag.getMessaggio_replaceKeywords("avvioEffettuato"));
  106.     }
  107.    
  108.     @Override
  109.     public void process(){
  110.         try{
  111.             // Prendo la gestione
  112.             TimerGestorePuliziaMessaggiAnomaliLib gestoreMessaggiLib =
  113.                 new TimerGestorePuliziaMessaggiAnomaliLib(this.msgDiag,this.logTimer,this.propertiesReader,this.logQuery,this.limit,this.orderByQuery);
  114.            
  115.             gestoreMessaggiLib.check();
  116.            
  117.         }catch(Exception e){
  118.             this.msgDiag.logErroreGenerico(e,"TimerGestorePuliziaMessaggiAnomaliLib.check()");
  119.             this.logTimer.error("Errore generale: "+e.getMessage(),e);
  120.         }finally{
  121.         }
  122.     }
  123. }