TimerGestoreRepositoryBusteThread.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 TimerGestoreRepositoryBusteThread extends BaseThread{

  39.     /**
  40.      * Timeout che definisce la scadenza di un messaggio
  41.      */
  42.     private long scadenzaMessaggio = 60l * 24l * 5l; // cablato a 5 giorni (60m * 24h * 5giorni).
  43.     /** Properties Reader */
  44.     private OpenSPCoop2Properties propertiesReader;
  45.     /** MsgDiagnostico */
  46.     private MsgDiagnostico msgDiag;
  47.     /** Logger */
  48.     private Logger logTimer;

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

  71.         this.logTimer = OpenSPCoop2Logger.getLoggerOpenSPCoopTimers();
  72.        
  73.         try {
  74.             this.msgDiag = MsgDiagnostico.newInstance(TimerGestoreRepositoryBuste.ID_MODULO);
  75.             this.msgDiag.setPrefixMsgPersonalizzati(MsgDiagnosticiProperties.MSG_DIAG_TIMER_GESTORE_REPOSITORY_BUSTE);
  76.             this.msgDiag.addKeyword(CostantiPdD.KEY_TIMER_GESTORE_REPOSITORY_BUSTE, TimerGestoreRepositoryBuste.ID_MODULO);
  77.         } catch (Exception e) {
  78.             String msgErrore = "Riscontrato Errore durante l'inizializzazione del MsgDiagnostico";
  79.             this.logTimer.error(msgErrore,e);
  80.             throw new TimerException(msgErrore,e);
  81.         }

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

  93.         this.setTimeout((int)this.propertiesReader.getRepositoryIntervalloEliminazioneMessaggi());
  94.         String sec = "secondi";
  95.         if(this.getTimeout() == 1)
  96.             sec = "secondo";
  97.         this.msgDiag.addKeyword(CostantiPdD.KEY_TIMEOUT, this.getTimeout()+" "+sec);
  98.        
  99.         this.scadenzaMessaggio = this.propertiesReader.getRepositoryIntervalloScadenzaMessaggi();
  100.         String s = "minuti";
  101.         if(this.scadenzaMessaggio == 1)
  102.             s = "minuto";
  103.         this.msgDiag.addKeyword(CostantiPdD.KEY_SCADENZA_MESSAGGIO, this.scadenzaMessaggio+" "+s);
  104.        
  105.         this.logQuery = this.propertiesReader.isTimerGestoreRepositoryBusteAbilitatoLog();
  106.         this.orderByQuery = this.propertiesReader.isTimerGestoreRepositoryBusteAbilitatoOrderBy();
  107.        
  108.         this.limit = this.propertiesReader.getTimerGestoreRepositoryBusteLimit();
  109.         if(this.limit<=0){
  110.             this.limit = CostantiPdD.LIMIT_MESSAGGI_GESTORI;
  111.         }
  112.         this.msgDiag.addKeyword(CostantiPdD.KEY_LIMIT, this.limit+"");
  113.        
  114.         this.msgDiag.logPersonalizzato("avvioEffettuato");
  115.         this.logTimer.info(this.msgDiag.getMessaggio_replaceKeywords("avvioEffettuato"));
  116.     }
  117.    
  118.     @Override
  119.     public void process(){
  120.         try{
  121.             // Prendo la gestione
  122.             TimerGestoreRepositoryBusteLib gestoreMessaggiLib =
  123.                 new TimerGestoreRepositoryBusteLib(this.msgDiag,this.logTimer,this.propertiesReader,this.logQuery,this.limit,this.orderByQuery);
  124.            
  125.             gestoreMessaggiLib.check();
  126.            
  127.         }catch(Exception e){
  128.             this.msgDiag.logErroreGenerico(e,"TimerGestoreRepositoryBusteLib.check()");
  129.             this.logTimer.error("Errore generale: "+e.getMessage(),e);
  130.         }finally{
  131.         }
  132.     }
  133. }