FSRecoveryDiagnosticiImpl.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.fs_recovery;

  21. import java.io.File;
  22. import java.sql.Connection;
  23. import java.util.ArrayList;
  24. import java.util.List;

  25. import org.slf4j.Logger;
  26. import org.openspcoop2.core.diagnostica.ElencoMessaggiDiagnostici;
  27. import org.openspcoop2.core.diagnostica.MessaggioDiagnostico;
  28. import org.openspcoop2.core.diagnostica.utils.serializer.JaxbDeserializer;
  29. import org.openspcoop2.protocol.sdk.diagnostica.IDiagnosticProducer;
  30. import org.openspcoop2.protocol.sdk.diagnostica.MsgDiagnostico;
  31. import org.openspcoop2.utils.UtilsException;
  32. import org.openspcoop2.utils.UtilsMultiException;

  33. /**
  34.  * FSRecoveryDiagnosticiImpl
  35.  *
  36.  * @author Poli Andrea (apoli@link.it)
  37.  * @author $Author$
  38.  * @version $Rev$, $Date$
  39.  */
  40. public class FSRecoveryDiagnosticiImpl extends AbstractFSRecovery {

  41.     private IDiagnosticProducer diagnosticoAppender;

  42.     public FSRecoveryDiagnosticiImpl(
  43.             Logger log,
  44.             boolean debug,
  45.             IDiagnosticProducer diagnosticoAppender,
  46.             File directory, File directoryDLQ,
  47.             int tentativi,
  48.             long msAttesaProcessingFile) {
  49.         super(log, debug, directory, directoryDLQ, tentativi, msAttesaProcessingFile);
  50.         this.diagnosticoAppender = diagnosticoAppender;
  51.     }

  52.     @Override
  53.     public void process(Connection connection) {
  54.         this.log.info("Recovery Diagnostici ...");
  55.         super.process(connection);
  56.         this.log.info("Recovery Diagnostici completato");
  57.     }

  58.     @Override
  59.     public void insertObject(File file, Connection connection) throws UtilsException, UtilsMultiException {
  60.         JaxbDeserializer deserializer = new JaxbDeserializer();
  61.         List<MessaggioDiagnostico> msgDiagnostici = new ArrayList<>();
  62.         try {
  63.             ElencoMessaggiDiagnostici elencoDiagnostici = deserializer.readElencoMessaggiDiagnostici(file);
  64.             if(elencoDiagnostici!=null && elencoDiagnostici.sizeMessaggioDiagnosticoList()>0) {
  65.                 for (MessaggioDiagnostico diagnostico : elencoDiagnostici.getMessaggioDiagnosticoList()) {
  66.                     msgDiagnostici.add(diagnostico);
  67.                 }
  68.             }
  69.         }catch(Exception t) {
  70.             // backward compatibility: si salvavano i singoli messaggi
  71.             try {
  72.                 MessaggioDiagnostico diagnostico = deserializer.readMessaggioDiagnostico(file);
  73.                 msgDiagnostici.add(diagnostico);
  74.             }catch(Exception tInternal) {
  75.                 throw new UtilsMultiException(t,tInternal);
  76.             }
  77.         }
  78.         if(!msgDiagnostici.isEmpty()) {
  79.             for (MessaggioDiagnostico diagnostico : msgDiagnostici) {
  80.                 MsgDiagnostico msgDiagOp2 = new MsgDiagnostico(diagnostico);
  81.                 try {
  82.                     this.diagnosticoAppender.log(connection, msgDiagOp2);
  83.                 }catch(Exception e) {
  84.                     throw new UtilsException(e.getMessage(),e);
  85.                 }
  86.             }
  87.         }
  88.     }


  89. }