Sonda.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.utils.sonde;

  21. import java.sql.Connection;
  22. import java.util.Date;

  23. import org.openspcoop2.utils.TipiDatabase;

  24. /**
  25.  * Classe astratta per le Sonde
  26.  *
  27.  *
  28.  * @author Bussu Giovanni (bussu@link.it)
  29.  * @author $Author$
  30.  * @version $Rev$, $Date$
  31.  */

  32. public abstract class Sonda {

  33.     private ParametriSonda param;
  34.     protected static final String PATTERN = "dd/MM/yyyy HH:mm:ss.sss";

  35.    
  36.     /**
  37.      * @param param
  38.      */
  39.     public Sonda(ParametriSonda param) {
  40.         this.param = param;
  41.     }
  42.    
  43.     /**
  44.      * @author Bussu Giovanni (bussu@link.it)
  45.      * @author  $Author$
  46.      * @version $Rev$, $Date$
  47.      *
  48.      */
  49.     public class StatoSonda {
  50.         private int stato;
  51.         private String descrizione;
  52.         public int getStato() {
  53.             return this.stato;
  54.         }
  55.         public void setStato(int stato) {
  56.             this.stato = stato;
  57.         }
  58.         public String getDescrizione() {
  59.             return this.descrizione;
  60.         }
  61.         public void setDescrizione(String descrizione) {
  62.             this.descrizione = descrizione;
  63.         }

  64.     }

  65.     /**
  66.      * Metodo che, utilizzando i dati_check, restituisce lo stato attuale della sonda
  67.      * @return lo stato attuale della Sonda
  68.      */
  69.     public abstract StatoSonda getStatoSonda();

  70.     /**
  71.      * @param connection connessione al database
  72.      * @param tipoDatabase tipo di database
  73.      * @return lo stato attuale della sonda
  74.      * @throws SondaException
  75.      */
  76.     protected StatoSonda updateSonda(Connection connection, TipiDatabase tipoDatabase) throws SondaException {

  77.         this.param.setDataUltimoCheck(new Date());

  78.         StatoSonda statoSonda = getStatoSonda();

  79.         int statoNew = statoSonda.getStato();

  80.         if(this.param.getStatoUltimoCheck() != statoNew) {
  81.            
  82.             // Aggiorna ad adesso il data_warn se lo statoSonda.stato e' passato ad 1 da 0
  83.             if(this.param.getStatoUltimoCheck() == 0 && statoNew == 1) {
  84.                 this.param.setDataWarn(new Date());
  85.                 this.param.setDataError(null);
  86.                 this.param.setDataOk(null);
  87.             }
  88.             // Aggiorna ad adesso il data_error se lo statoSonda.stato e' passato a 2
  89.             if(statoNew == 2) {
  90.                 this.param.setDataError(new Date());
  91.                 this.param.setDataWarn(null);
  92.                 this.param.setDataOk(null);
  93.             }
  94.             // Aggiorna ad adesso il data_ok se lo statoSonda.stato e' passato a 0
  95.             if(statoNew == 0) {
  96.                 this.param.setDataOk(new Date());
  97.                 this.param.setDataError(null);
  98.                 this.param.setDataWarn(null);
  99.             }
  100.         }

  101.         this.param.setStatoUltimoCheck(statoNew);

  102.         SondaFactory.updateStatoSonda(this.param.getNome(), this, connection, tipoDatabase);

  103.         return statoSonda;
  104.     }

  105.     public ParametriSonda getParam() {
  106.         return this.param;
  107.     }

  108. }