TimerGestoreCacheChiaviPDND.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.pdnd;


  21. import java.util.List;

  22. import org.openspcoop2.pdd.config.PDNDConfig;
  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.pdd.timers.TimerException;
  29. import org.openspcoop2.utils.Utilities;
  30. import org.openspcoop2.utils.threads.BaseThread;
  31. import org.slf4j.Logger;


  32. /**    
  33.  * TimerGestoreChiaviPDND
  34.  *
  35.  * @author Poli Andrea (poli@link.it)
  36.  * @author $Author$
  37.  * @version $Rev$, $Date$
  38.  */
  39. public class TimerGestoreCacheChiaviPDND extends BaseThread{

  40.     public static final String ID_MODULO = "TimerGestoreCacheChiaviPDND";
  41.    
  42.    
  43.     /** Logger utilizzato per debug. */
  44.     private Logger logTimer = null;
  45.     private void logError(String msgErrore, Exception e) {
  46.         if(this.logTimer!=null) {
  47.             this.logTimer.error(msgErrore,e);
  48.         }
  49.     }
  50.     private MsgDiagnostico msgDiag = null;
  51.    
  52.     private List<PDNDConfig> remoteStores;
  53.    
  54.    
  55.    
  56.     /** Costruttore */
  57.     public TimerGestoreCacheChiaviPDND(long timeout, List<PDNDConfig> remoteStores) throws TimerException{
  58.    
  59.         // Aspetto inizializzazione di OpenSPCoop (aspetto mezzo minuto e poi segnalo errore)
  60.         int attesa = 90;
  61.         int secondi = 0;
  62.         while( (!OpenSPCoop2Startup.initialize) && (secondi<attesa) ){
  63.             Utilities.sleep(1000);
  64.             secondi++;
  65.         }
  66.         if(secondi>= 90){
  67.             throw new TimerException("Riscontrata inizializzazione OpenSPCoop non effettuata");
  68.         }  

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

  80.         this.msgDiag.logPersonalizzato("avvioInCorso");
  81.         this.logTimer.info(this.msgDiag.getMessaggio_replaceKeywords("avvioInCorso"));
  82.        
  83.         this.remoteStores = remoteStores;
  84.        
  85.         this.setTimeout((int)timeout);
  86.         String sec = "secondi";
  87.         if(this.getTimeout() == 1)
  88.             sec = "secondo";
  89.         this.msgDiag.addKeyword(CostantiPdD.KEY_TIMEOUT, this.getTimeout()+" "+sec);
  90.        
  91.         this.msgDiag.logPersonalizzato("avvioEffettuato");
  92.         this.logTimer.info(this.msgDiag.getMessaggio_replaceKeywords("avvioEffettuato"));
  93.     }
  94.    
  95.     @Override
  96.     public void process(){
  97.        
  98.         try{
  99.            
  100.             if(this.remoteStores!=null && !this.remoteStores.isEmpty()) {
  101.                 for (PDNDConfig remoteStore : this.remoteStores) {
  102.                    
  103.                     String remoteStoreName = remoteStore.getRemoteStoreConfig().getStoreName();
  104.                     this.msgDiag.addKeyword(CostantiPdD.KEY_REMOTE_STORE, remoteStoreName);
  105.                    
  106.                     process(remoteStoreName, remoteStore);
  107.                 }
  108.             }
  109.                        
  110.         }catch(Exception e){
  111.             this.msgDiag.logErroreGenerico(e,"TimerGestoreCacheChiaviPDNDLib.check()");
  112.             this.logError("Errore generale: "+e.getMessage(),e);
  113.         }
  114.        
  115.     }
  116.     private void process(String remoteStoreName, PDNDConfig remoteStore){
  117.         try{
  118.            
  119.             // Prendo la gestione
  120.             TimerGestoreCacheChiaviPDNDLib timer =
  121.                 new TimerGestoreCacheChiaviPDNDLib(this.logTimer, this.msgDiag,
  122.                         remoteStore.getRemoteStoreConfig() , remoteStore.getRemoteKeyType());
  123.            
  124.             timer.check();  
  125.        
  126.         }catch(Exception e){
  127.             this.msgDiag.logErroreGenerico(e,"TimerGestoreCacheChiaviPDNDLib.check("+remoteStoreName+")");
  128.             this.logError("Errore generale ("+remoteStoreName+"): "+e.getMessage(),e);
  129.         }
  130.     }
  131.    
  132. }