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 generateStatisticaOraria(){
  94.         try{
  95.            
  96.             if(this.config.isStatisticheOrarie()){
  97.                 if(this.config.isDebug()){
  98.                     this.config.getLogCore().debug("Esecuzione thread per generazione statistiche orarie ....");
  99.                 }
  100.                 StatisticheOrarie sg = new StatisticheOrarie( this.config.getLogCore(), this.config.isDebug(),
  101.                         this.config.isUseUnionForLatency(),
  102.                         this.config.isGenerazioneStatisticheCustom(),
  103.                         this.config.isAnalisiTransazioniCustom(),
  104.                         this.config.getForceIndexConfig(),
  105.                         this.statisticheSM, this.transazioniSM,
  106.                         this.pluginsStatisticheSM, this.pluginsBaseSM, this.utilsSM, this.pluginsTransazioniSM );
  107.                 sg.generaStatistiche( this.config.isStatisticheOrarieGestioneUltimoIntervallo(),
  108.                         this.config.getWaitMsBeforeNextInterval(),
  109.                         this.config.isWaitStatiInConsegna());
  110.                 if(this.config.isDebug()){
  111.                     this.config.getLogCore().debug("Esecuzione thread per generazione statistiche orarie  terminata");
  112.                 }
  113.             }else{
  114.                 if(this.config.isDebug()){
  115.                     this.config.getLogCore().debug("Thread per generazione statistiche orarie disabilitato");
  116.                 }
  117.             }
  118.            
  119.         }catch(Exception e){
  120.             String msg = ERRORE+e.getMessage();
  121.             this.config.getLogCore().error(msg,e);
  122.         }
  123.     }
  124.    
  125.     public void generateStatisticaGiornaliera(){
  126.         try{
  127.            
  128.             if(this.config.isStatisticheGiornaliere()){
  129.                 if(this.config.isDebug()){
  130.                     this.config.getLogCore().debug("Esecuzione thread per generazione statistiche giornaliere ....");
  131.                 }
  132.                 StatisticheGiornaliere sg = new StatisticheGiornaliere( this.config.getLogCore(), this.config.isDebug(),
  133.                         this.config.isUseUnionForLatency(),
  134.                         this.config.isGenerazioneStatisticheCustom(),
  135.                         this.config.isAnalisiTransazioniCustom(),
  136.                         this.config.getForceIndexConfig(),
  137.                         this.statisticheSM, this.transazioniSM,
  138.                         this.pluginsStatisticheSM, this.pluginsBaseSM, this.utilsSM, this.pluginsTransazioniSM );
  139.                 sg.generaStatistiche( this.config.isStatisticheGiornaliereGestioneUltimoIntervallo(),
  140.                         this.config.getWaitMsBeforeNextInterval(),
  141.                         this.config.isWaitStatiInConsegna() );
  142.                 if(this.config.isDebug()){
  143.                     this.config.getLogCore().debug("Esecuzione thread per generazione statistiche giornaliere  terminata");
  144.                 }
  145.             }else{
  146.                 if(this.config.isDebug()){
  147.                     this.config.getLogCore().debug("Thread per generazione statistiche giornaliere disabilitato");
  148.                 }
  149.             }
  150.            
  151.         }catch(Exception e){
  152.             this.config.getLogCore().error(ERRORE+e.getMessage(),e);
  153.         }
  154.     }
  155.            
  156.     public void generateStatisticaSettimanale(){
  157.         try{
  158.             if(this.config.isStatisticheSettimanali()){
  159.                 if(this.config.isDebug()){
  160.                     this.config.getLogCore().debug("Esecuzione thread per generazione statistiche settimanali ....");
  161.                 }
  162.                 StatisticheSettimanali sg = new StatisticheSettimanali( this.config.getLogCore(), this.config.isDebug(),
  163.                         this.config.isUseUnionForLatency(),
  164.                         this.config.isGenerazioneStatisticheCustom(),
  165.                         this.config.isAnalisiTransazioniCustom(),
  166.                         this.config.getForceIndexConfig(),
  167.                         this.statisticheSM, this.transazioniSM,
  168.                         this.pluginsStatisticheSM, this.pluginsBaseSM, this.utilsSM, this.pluginsTransazioniSM );
  169.                 sg.generaStatistiche( this.config.isStatisticheSettimanaliGestioneUltimoIntervallo(),
  170.                         this.config.getWaitMsBeforeNextInterval(),
  171.                         this.config.isWaitStatiInConsegna() );
  172.                 if(this.config.isDebug()){
  173.                     this.config.getLogCore().debug("Esecuzione thread per generazione statistiche settimanali  terminata");
  174.                 }
  175.             }else{
  176.                 if(this.config.isDebug()){
  177.                     this.config.getLogCore().debug("Thread per generazione statistiche settimanali disabilitato");
  178.                 }
  179.             }
  180.         }catch(Exception e){
  181.             this.config.getLogCore().error(ERRORE+e.getMessage(),e);
  182.         }
  183.     }
  184.            
  185.     public void generateStatisticaMensile(){
  186.         try{
  187.             if(this.config.isStatisticheMensili()){
  188.                 if(this.config.isDebug()){
  189.                     this.config.getLogCore().debug("Esecuzione thread per generazione statistiche mensili ....");
  190.                 }
  191.                 StatisticheMensili sg = new StatisticheMensili( this.config.getLogCore(), this.config.isDebug(),
  192.                         this.config.isUseUnionForLatency(),
  193.                         this.config.isGenerazioneStatisticheCustom(),
  194.                         this.config.isAnalisiTransazioniCustom(),
  195.                         this.config.getForceIndexConfig(),
  196.                         this.statisticheSM, this.transazioniSM,
  197.                         this.pluginsStatisticheSM, this.pluginsBaseSM, this.utilsSM, this.pluginsTransazioniSM );
  198.                 sg.generaStatistiche( this.config.isStatisticheMensiliGestioneUltimoIntervallo(),
  199.                         this.config.getWaitMsBeforeNextInterval(),
  200.                         this.config.isWaitStatiInConsegna() );
  201.                 if(this.config.isDebug()){
  202.                     this.config.getLogCore().debug("Esecuzione thread per generazione statistiche mensili  terminata");
  203.                 }
  204.             }else{
  205.                 if(this.config.isDebug()){
  206.                     this.config.getLogCore().debug("Thread per generazione statistiche mensili disabilitato");
  207.                 }
  208.             }
  209.            
  210.         }catch(Exception e){
  211.             this.config.getLogCore().error(ERRORE+e.getMessage(),e);
  212.         }
  213.     }
  214.    
  215. }