SondaInvocazione.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.impl;

  21. import java.sql.Connection;
  22. import java.text.SimpleDateFormat;
  23. import java.util.Date;
  24. import java.util.HashSet;
  25. import java.util.Properties;
  26. import java.util.Set;

  27. import org.openspcoop2.utils.TipiDatabase;
  28. import org.openspcoop2.utils.sonde.ParametriSonda;
  29. import org.openspcoop2.utils.sonde.Sonda;
  30. import org.openspcoop2.utils.sonde.SondaException;

  31. /**
  32.  * Classe di implementazione della Sonda per le code
  33.  *
  34.  *
  35.  * @author Bussu Giovanni (bussu@link.it)
  36.  * @author $Author$
  37.  * @version $Rev$, $Date$
  38.  */

  39. public class SondaInvocazione extends Sonda {

  40.     /**
  41.      * Costruttore per la classe SondaCoda
  42.      * @param param parametri costruttivi della sonda
  43.      * @throws Exception
  44.      */
  45.     public SondaInvocazione(ParametriSonda param) {
  46.         super(param);
  47.         Set<String> reserved = new HashSet<String>();
  48.         reserved.add(RICHIESTA_OK);
  49.         this.getParam().setReserved(reserved);

  50.     }

  51.     private static final String RICHIESTA_OK = "richiestaOk";
  52.     @Override
  53.     public StatoSonda getStatoSonda(){
  54.        
  55.         boolean richiestaOK = false;
  56.         if(super.getParam().getDatiCheck().containsKey(RICHIESTA_OK)) {
  57.             try {
  58.                 richiestaOK = Boolean.parseBoolean(super.getParam().getDatiCheck().getProperty(RICHIESTA_OK));
  59.             } catch(Exception e) {
  60.                 super.getParam().getDatiCheck().remove(RICHIESTA_OK);
  61.             }
  62.         }
  63.        
  64.         StatoSonda statoSonda = new StatoSonda();
  65.         SimpleDateFormat format = new SimpleDateFormat(PATTERN);

  66.         //non esiste stato warning
  67.         if(richiestaOK) {
  68.             statoSonda.setStato(0);
  69.             statoSonda.setDescrizione(null);
  70.         } else {
  71.             if(this.getParam().getDataError() == null) {
  72.                 this.getParam().setDataError(new Date());
  73.             }
  74.             statoSonda.setStato(2);
  75.             statoSonda.setDescrizione("Invocazione richiesta dal check "+super.getParam().getNome()+" fallita dal "+format.format(this.getParam().getDataError()));
  76.         }
  77.  
  78.         return statoSonda;
  79.     }

  80.     /**
  81.      * @param dimensioneCoda dimensione attuale della coda
  82.      * @param connection connessione per il DB
  83.      * @param tipoDatabase tipo database
  84.      * @return lo stato attuale della sonda
  85.      * @throws SondaException
  86.      */
  87.     public StatoSonda aggiornaStatoSonda(boolean richiestaOk, Properties params, Connection connection, TipiDatabase tipoDatabase) throws SondaException {
  88.         // inserisce i dati nel properties
  89.         super.getParam().putAllCheck(params);
  90.        
  91.         super.getParam().getDatiCheck().put(RICHIESTA_OK, richiestaOk + "");
  92.         return updateSonda(connection, tipoDatabase);
  93.     }


  94. }