StatisticsLibrary.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.monitor.engine.statistic;

  21. import org.openspcoop2.generic_project.dao.jdbc.JDBCServiceManagerBase;

  22. /**
  23.  * StatisticsLibrary
  24.  *
  25.  * @author Poli Andrea (apoli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */
  29. public class StatisticsLibrary {

  30.     private StatisticsConfig config;
  31.     private org.openspcoop2.core.statistiche.dao.IServiceManager statisticheSM;
  32.     private org.openspcoop2.core.transazioni.dao.IServiceManager transazioniSM;
  33.     private org.openspcoop2.monitor.engine.config.statistiche.dao.IServiceManager pluginsStatisticheSM;
  34.     private org.openspcoop2.core.plugins.dao.IServiceManager pluginsBaseSM;
  35.     private org.openspcoop2.core.commons.search.dao.IServiceManager utilsSM;
  36.     private org.openspcoop2.monitor.engine.config.transazioni.dao.IServiceManager pluginsTransazioniSM;
  37.    
  38.     private static final String ERRORE = "Errore durante la generazione delle statistiche: ";
  39.    
  40.     public StatisticsLibrary(StatisticsConfig config,
  41.             org.openspcoop2.core.statistiche.dao.IServiceManager statisticheSM,
  42.             org.openspcoop2.core.transazioni.dao.IServiceManager transazioniSM,
  43.             org.openspcoop2.monitor.engine.config.statistiche.dao.IServiceManager pluginsStatisticheSM,
  44.             org.openspcoop2.core.plugins.dao.IServiceManager pluginsBaseSM,
  45.             org.openspcoop2.core.commons.search.dao.IServiceManager utilsSM,
  46.             org.openspcoop2.monitor.engine.config.transazioni.dao.IServiceManager pluginsTransazioniSM){
  47.         this.config = config;
  48.         this.statisticheSM = statisticheSM;
  49.         this.transazioniSM = transazioniSM;
  50.         this.pluginsStatisticheSM = pluginsStatisticheSM;
  51.         this.pluginsBaseSM = pluginsBaseSM;
  52.         this.utilsSM = utilsSM;
  53.         this.pluginsTransazioniSM = pluginsTransazioniSM;
  54.     }
  55.    
  56.     public void close() {
  57.         if(this.statisticheSM instanceof JDBCServiceManagerBase) {
  58.             closeEngine((JDBCServiceManagerBase)this.statisticheSM,"Statistiche");
  59.         }
  60.         if(this.transazioniSM instanceof JDBCServiceManagerBase) {
  61.             closeEngine((JDBCServiceManagerBase)this.transazioniSM,"Transazioni");
  62.         }
  63.         if(this.utilsSM instanceof JDBCServiceManagerBase) {
  64.             closeEngine((JDBCServiceManagerBase)this.utilsSM,"Utils");
  65.         }
  66.         if(this.pluginsBaseSM instanceof JDBCServiceManagerBase) {
  67.             closeEngine((JDBCServiceManagerBase)this.pluginsBaseSM,"PluginBase");
  68.         }
  69.         if(this.pluginsStatisticheSM instanceof JDBCServiceManagerBase) {
  70.             closeEngine((JDBCServiceManagerBase)this.pluginsStatisticheSM,"PluginStatistiche");
  71.         }
  72.         if(this.pluginsTransazioniSM instanceof JDBCServiceManagerBase) {
  73.             closeEngine((JDBCServiceManagerBase)this.pluginsTransazioniSM,"PluginTransazioni");
  74.         }
  75.     }
  76.     private void closeEngine(JDBCServiceManagerBase serviceManager, String tipo) {
  77.         try {
  78.             serviceManager.close();
  79.         }catch(Exception t) {
  80.             String msgError = "Rilascio connessione '"+tipo+"' fallita: "+t.getMessage();
  81.             if(this.config.getLogSql()!=null) {
  82.                 this.config.getLogSql().error(msgError, t);
  83.             }
  84.             else if(this.config.getLogCore()!=null) {
  85.                 this.config.getLogCore().error(msgError, t);
  86.             }
  87.             else {
  88.                 t.printStackTrace(System.err);
  89.             }
  90.         }
  91.     }
  92.    
  93.     public void generateStatistics(IStatisticsEngine engine, String name) {
  94.         try{
  95.            
  96.             if(engine.isEnabled(this.config)){
  97.                 if(this.config.isDebug()){
  98.                     this.config.getLogCore().debug("Esecuzione thread {} ....", name);
  99.                 }
  100.                 engine.init( this.config,
  101.                         this.statisticheSM, this.transazioniSM,
  102.                         this.pluginsStatisticheSM, this.pluginsBaseSM, this.utilsSM, this.pluginsTransazioniSM );
  103.                 engine.generate();
  104.                 if(this.config.isDebug()){
  105.                     this.config.getLogCore().debug("Esecuzione thread {} terminata", name);
  106.                 }
  107.             }else{
  108.                 if(this.config.isDebug()){
  109.                     this.config.getLogCore().debug("Thread {} disabilitato", name);
  110.                 }
  111.             }
  112.            
  113.         }catch(Exception e){
  114.             String msg = ERRORE+e.getMessage();
  115.             this.config.getLogCore().error(msg,e);
  116.         }
  117.     }

  118.    
  119.     public void generateStatisticaOraria(){
  120.         generateStatistics(new StatisticheOrarie(), "per generazione statistiche orarie");
  121.     }
  122.    
  123.     public void generateStatisticaGiornaliera(){
  124.         generateStatistics(new StatisticheGiornaliere(), "per generazione statistiche giornaliere");
  125.     }
  126.            
  127.     public void generateStatisticaSettimanale(){
  128.         generateStatistics(new StatisticheSettimanali(), "per generazione statistiche settimanali");
  129.     }
  130.            
  131.     public void generateStatisticaMensile(){
  132.         generateStatistics(new StatisticheMensili(), "per generazione statistiche mensili");
  133.     }
  134.    
  135.     public void generatePdndGenerazioneTracciamento(){
  136.         generateStatistics(new PdndGenerazioneTracciamento(), "generazione pdnd tracciamento");
  137.     }
  138.    
  139.     public void generatePdndPubblicazioneTracciamento(){
  140.         generateStatistics(new PdndPublicazioneTracciamento(), "pubblicazione pdnd tracciamento");
  141.     }
  142.    
  143. }