TimerGestoreBusteNonRiscontrateLib.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.pdd.timers;

  21. import java.sql.Connection;
  22. import java.sql.Timestamp;
  23. import java.util.ArrayList;
  24. import java.util.Date;
  25. import java.util.List;

  26. import org.slf4j.Logger;
  27. import org.openspcoop2.core.config.PortaDelegata;
  28. import org.openspcoop2.core.config.ServizioApplicativo;
  29. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  30. import org.openspcoop2.core.config.driver.DriverConfigurazioneNotFound;
  31. import org.openspcoop2.core.id.IDPortaDelegata;
  32. import org.openspcoop2.core.id.IDServizio;
  33. import org.openspcoop2.core.id.IDServizioApplicativo;
  34. import org.openspcoop2.core.id.IDSoggetto;
  35. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  36. import org.openspcoop2.pdd.config.ClassNameProperties;
  37. import org.openspcoop2.pdd.config.ConfigurazionePdDManager;
  38. import org.openspcoop2.pdd.config.OpenSPCoop2Properties;
  39. import org.openspcoop2.pdd.config.RichiestaDelegata;
  40. import org.openspcoop2.pdd.core.AbstractCore;
  41. import org.openspcoop2.pdd.core.CostantiPdD;
  42. import org.openspcoop2.pdd.core.EJBUtilsException;
  43. import org.openspcoop2.pdd.core.GestoreMessaggi;
  44. import org.openspcoop2.pdd.core.PdDContext;
  45. import org.openspcoop2.pdd.core.node.INodeSender;
  46. import org.openspcoop2.pdd.core.state.OpenSPCoopStateful;
  47. import org.openspcoop2.pdd.core.state.OpenSPCoopStateless;
  48. import org.openspcoop2.pdd.logger.MsgDiagnostico;
  49. import org.openspcoop2.pdd.mdb.InoltroBuste;
  50. import org.openspcoop2.pdd.mdb.InoltroBusteMessage;
  51. import org.openspcoop2.pdd.services.OpenSPCoop2Startup;
  52. import org.openspcoop2.protocol.engine.ProtocolFactoryManager;
  53. import org.openspcoop2.protocol.engine.constants.Costanti;
  54. import org.openspcoop2.protocol.engine.driver.BustaNonRiscontrata;
  55. import org.openspcoop2.protocol.engine.driver.ProfiloDiCollaborazione;
  56. import org.openspcoop2.protocol.engine.driver.RepositoryBuste;
  57. import org.openspcoop2.protocol.engine.driver.Riscontri;
  58. import org.openspcoop2.protocol.engine.driver.RollbackRepositoryBuste;
  59. import org.openspcoop2.protocol.registry.RegistroServiziManager;
  60. import org.openspcoop2.protocol.sdk.Busta;
  61. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  62. import org.openspcoop2.protocol.sdk.Integrazione;
  63. import org.openspcoop2.protocol.sdk.builder.ProprietaErroreApplicativo;
  64. import org.openspcoop2.protocol.sdk.state.StateMessage;
  65. import org.openspcoop2.protocol.sdk.state.StatelessMessage;
  66. import org.openspcoop2.utils.TipiDatabase;
  67. import org.openspcoop2.utils.Utilities;
  68. import org.openspcoop2.utils.date.DateManager;
  69. import org.openspcoop2.utils.id.serial.InfoStatistics;
  70. import org.openspcoop2.utils.resources.Loader;
  71. import org.openspcoop2.utils.semaphore.Semaphore;
  72. import org.openspcoop2.utils.semaphore.SemaphoreConfiguration;
  73. import org.openspcoop2.utils.semaphore.SemaphoreMapping;

  74. /**
  75.  * Implementazione dell'interfaccia {@link TimerGestoreBusteNonRiscontrate} del Gestore
  76.  * dei threads di servizio di OpenSPCoop.
  77.  *
  78.  *  
  79.  * @author Poli Andrea (apoli@link.it)
  80.  * @author Marcello Spadafora (ma.spadafora@finsiel.it)
  81.  * @author $Author$
  82.  * @version $Rev$, $Date$
  83.  */

  84. public class TimerGestoreBusteNonRiscontrateLib {

  85.     private static TimerState STATE_ONEWAY = TimerState.OFF; // abilitato in OpenSPCoop2Startup al momento dell'avvio
  86.     public static TimerState getSTATE_ONEWAY() {
  87.         return STATE_ONEWAY;
  88.     }
  89.     public static void setSTATE_ONEWAY(TimerState sTATE_ONEWAY) {
  90.         STATE_ONEWAY = sTATE_ONEWAY;
  91.     }

  92.     private static TimerState STATE_ASINCRONI = TimerState.OFF; // abilitato in OpenSPCoop2Startup al momento dell'avvio
  93.     public static TimerState getSTATE_ASINCRONI() {
  94.         return STATE_ASINCRONI;
  95.     }
  96.     public static void setSTATE_ASINCRONI(TimerState sTATE_ASINCRONI) {
  97.         STATE_ASINCRONI = sTATE_ASINCRONI;
  98.     }

  99.     private MsgDiagnostico msgDiag = null;
  100.     private Logger logTimer = null;
  101.     private OpenSPCoop2Properties propertiesReader = null;
  102.     private boolean logQuery = false;
  103.     private int limit = CostantiPdD.LIMIT_MESSAGGI_GESTORI;
  104.     private long timeout = 10;
  105.     private ConfigurazionePdDManager configurazionePdDReader;
  106.     private RegistroServiziManager registroServiziReader;

  107.     /** INodeSender */
  108.     //private static INodeSender nodeSender = null;
  109.     // C'e' lo stato
  110.     private static String tipoNodeSender = null;

  111.     private ProtocolFactoryManager protocolFactoryManager = null;

  112.     private TimerLock timerLock = null;

  113.     /** Semaforo */
  114.     private Semaphore semaphore = null;
  115.     private InfoStatistics semaphore_statistics;

  116.     public TimerGestoreBusteNonRiscontrateLib(MsgDiagnostico msgDiag,Logger log,OpenSPCoop2Properties p,boolean logQuery,int limit,
  117.             long timeout,ConfigurazionePdDManager configurazionePdDReader,RegistroServiziManager registroServiziReader) throws TimerException{
  118.         this.msgDiag = msgDiag;
  119.         this.logTimer = log;
  120.         this.propertiesReader = p;
  121.         this.logQuery = logQuery;
  122.         this.limit = limit;
  123.         this.timeout = timeout;
  124.         this.configurazionePdDReader = configurazionePdDReader;
  125.         this.registroServiziReader = registroServiziReader;
  126.         try{
  127.             this.protocolFactoryManager = ProtocolFactoryManager.getInstance();
  128.         }catch(Exception e){
  129.             // log dell'eventuale errore e' dentro il metodo
  130.             throw new TimerException("Riscontrato errore durante l'inizializzazione del ProtocolFactoryManager: "+e.getMessage(),e);
  131.         }

  132.         if(TimerGestoreBusteNonRiscontrateLib.tipoNodeSender==null){
  133.             try{
  134.                 TimerGestoreBusteNonRiscontrateLib.tipoNodeSender = this.propertiesReader.getNodeSender();
  135.             }catch(Exception e){
  136.                 // log dell'eventuale errore e' dentro il metodo
  137.                 throw new TimerException("Riscontrato errore durante l'inizializzazione del Thread GestoreBusteNonRiscontrate (NodeSender): "+e.getMessage(),e);
  138.             }
  139.         }
  140.        
  141.         this.timerLock = new TimerLock(TipoLock.GESTIONE_BUSTE_NON_RISCONTRATE);

  142.         if(this.propertiesReader.isTimerLockByDatabase()) {
  143.             this.semaphore_statistics = new InfoStatistics();

  144.             SemaphoreConfiguration config = GestoreMessaggi.newSemaphoreConfiguration(this.propertiesReader.getTimerGestoreRiscontriRicevuteLockMaxLife(),
  145.                     this.propertiesReader.getTimerGestoreRiscontriRicevuteLockIdleTime());

  146.             TipiDatabase databaseType = TipiDatabase.toEnumConstant(this.propertiesReader.getDatabaseType());
  147.             try {
  148.                 this.semaphore = new Semaphore(this.semaphore_statistics, SemaphoreMapping.newInstance(this.timerLock.getIdLock()),
  149.                         config, databaseType, this.logTimer);
  150.             }catch(Exception e) {
  151.                 throw new TimerException(e.getMessage(),e);
  152.             }
  153.         }
  154.     }


  155.     public void check() throws TimerException {

  156.         // Controllo che il sistema non sia andando in shutdown
  157.         if(OpenSPCoop2Startup.contextDestroyed){
  158.             this.logTimer.error("["+TimerGestoreBusteNonRiscontrate.ID_MODULO+"] Rilevato sistema in shutdown");
  159.             return;
  160.         }
  161.        
  162.         // Controllo che l'inizializzazione corretta delle risorse sia effettuata
  163.         if(!OpenSPCoop2Startup.initialize){
  164.             this.msgDiag.logFatalError("inizializzazione di OpenSPCoop non effettuata", "Check Inizializzazione");
  165.             String msgErrore = "Riscontrato errore: inizializzazione del Timer o di OpenSPCoop non effettuata";
  166.             this.logTimer.error(msgErrore);
  167.             throw new TimerException(msgErrore);
  168.         }

  169.         // Controllo risorse di sistema disponibili
  170.         if( !TimerMonitoraggioRisorseThread.isRisorseDisponibili()){
  171.             this.logTimer.error("["+TimerGestoreBusteNonRiscontrate.ID_MODULO+"] Risorse di sistema non disponibili: "+TimerMonitoraggioRisorseThread.getRisorsaNonDisponibile().getMessage(),TimerMonitoraggioRisorseThread.getRisorsaNonDisponibile());
  172.             return;
  173.         }
  174.         if( !MsgDiagnostico.gestoreDiagnosticaDisponibile){
  175.             this.logTimer.error("["+TimerGestoreBusteNonRiscontrate.ID_MODULO+"] Sistema di diagnostica non disponibile: "+MsgDiagnostico.motivoMalfunzionamentoDiagnostici.getMessage(),MsgDiagnostico.motivoMalfunzionamentoDiagnostici);
  176.             return;
  177.         }

  178.         // Controllo che il timer non sia stato momentaneamente disabilitato
  179.         if(!TimerState.ENABLED.equals(STATE_ONEWAY) && !TimerState.ENABLED.equals(STATE_ASINCRONI)) {
  180.             this.msgDiag.logPersonalizzato("disabilitato");
  181.             this.logTimer.info(this.msgDiag.getMessaggio_replaceKeywords("disabilitato"));
  182.             return;
  183.         }
  184.        
  185.         // refresh
  186.         if( this.configurazionePdDReader.getTimeoutRiscontro() < 1  )   {
  187.             String msgErrore = "Riscontrato errore durante la lettura del timeout per le buste non riscontrate (<=0 ??)";
  188.             this.msgDiag.logErroreGenerico(msgErrore,"getTimeoutRiscontro()");
  189.             this.logTimer.error(msgErrore);
  190.             return;
  191.         }

  192.         this.timeout = this.configurazionePdDReader.getTimeoutRiscontro();
  193.         String minuti = "minuti";
  194.         if(this.timeout == 1)
  195.             minuti = "minuto";
  196.         this.msgDiag.addKeyword(CostantiPdD.KEY_TIMEOUT, this.timeout+" "+minuti);
  197.         this.msgDiag.addKeyword(CostantiPdD.KEY_LIMIT, this.limit+"");
  198.         this.msgDiag.logPersonalizzato("controlloInCorso");
  199.         this.logTimer.info(this.msgDiag.getMessaggio_replaceKeywords("controlloInCorso"));
  200.         long startControlloBusteNonRiscontrate = DateManager.getTimeMillis();


  201.         // Gestione Riscontri...
  202.         GestoreMessaggi gestoreMsg= null;
  203.         GestoreMessaggi messaggioDaInviare= null;
  204.         RepositoryBuste repositoryBuste= null;
  205.         Riscontri gestoreRiscontri = null;
  206.         RollbackRepositoryBuste rollbackRepositoryBuste= null;

  207.         OpenSPCoopStateful openspcoopState = new OpenSPCoopStateful();

  208.         try {

  209.             openspcoopState.initResource(this.propertiesReader.getIdentitaPortaDefaultWithoutProtocol(),TimerGestoreBusteNonRiscontrate.ID_MODULO, null);
  210.             Connection connectionDB = ((StateMessage)openspcoopState.getStatoRichiesta()).getConnectionDB();


  211.             /* ----- Gestione Riscontri per profilo OneWay ----- */
  212.             if(TimerState.ENABLED.equals(STATE_ONEWAY)) {
  213.                 Riscontri rBuste = new Riscontri(openspcoopState.getStatoRichiesta(),this.logTimer);
  214.                 int offsetRiscontri = 0;
  215.                 String causaBusteOneWayToSend = "Rispedizione buste con profilo oneway non riscontrate";
  216.                 List<BustaNonRiscontrata> busteOneWayToSend = null;
  217.                 try{
  218.                     GestoreMessaggi.acquireLock(
  219.                             this.semaphore, connectionDB, this.timerLock,
  220.                             this.msgDiag, causaBusteOneWayToSend,
  221.                             this.propertiesReader.getTimerGestoreRiscontriRicevuteGetLockAttesaAttiva(),
  222.                             this.propertiesReader.getTimerGestoreRiscontriRicevuteGetLockCheckInterval());
  223.                    
  224.                     busteOneWayToSend = rBuste.getBustePerUlterioreInoltro(this.timeout,this.limit,offsetRiscontri,this.logQuery);
  225.                     if(this.logQuery &&
  226.                          (busteOneWayToSend != null) && (busteOneWayToSend.isEmpty())){
  227.                         this.logTimer.info("Non sono state trovate buste con profilo oneway non riscontrate da rispedire");
  228.                     }
  229.        
  230.                     // Gestione buste da re-spedire
  231.                     while ( (busteOneWayToSend != null) && (!busteOneWayToSend.isEmpty()) ) {
  232.        
  233.                         if(this.logQuery)
  234.                             this.logTimer.info("Trovate "+busteOneWayToSend.size()+" buste con profilo oneway non riscontrate da rispedire ...");
  235.        
  236.                         int gestiti = 0;
  237.                         for (int i = 0; i < busteOneWayToSend.size(); i++) {
  238.        
  239.                             BustaNonRiscontrata bustaNonRiscontrata = busteOneWayToSend.get(i);
  240.                             String idBustaDaRispedire = bustaNonRiscontrata.getIdentificativo();
  241.                             this.msgDiag.addKeyword(CostantiPdD.KEY_ID_MESSAGGIO_RICHIESTA, idBustaDaRispedire);
  242.                             this.msgDiag.addKeyword(CostantiPdD.KEY_PROFILO_COLLABORAZIONE, bustaNonRiscontrata.getProfiloCollaborazione().name());
  243.        
  244.                             // Busta da rispedire
  245.                             this.msgDiag.logPersonalizzato("bustaNonRiscontrata");
  246.                             if(this.logQuery){
  247.                                 this.logTimer.debug(this.msgDiag.getMessaggio_replaceKeywords("bustaNonRiscontrata"));
  248.                             }
  249.                            
  250.                             try{
  251.                                 GestoreMessaggi.updateLock(
  252.                                         this.semaphore, connectionDB, this.timerLock,
  253.                                         this.msgDiag, "Rispedizione busta con profilo oneway con id ["+idBustaDaRispedire+"] ...");
  254.                             }catch(Throwable e){
  255.                                 this.msgDiag.logErroreGenerico(e,"RispedizioneBustaNonRiscontrataOneWay("+idBustaDaRispedire+")-UpdateLock");
  256.                                 this.logTimer.error("ErroreRispedizioneBustaNonRiscontrataOneWay("+idBustaDaRispedire+")-UpdateLock: "+e.getMessage(),e);
  257.                                 break;
  258.                             }
  259.        
  260.                             // Controllo che al riscontro corrisponda effettivamente un messaggio nel repository
  261.                             messaggioDaInviare = new GestoreMessaggi(openspcoopState,true,idBustaDaRispedire,Costanti.OUTBOX,
  262.                                     this.logTimer,this.msgDiag,null);
  263.                             if(messaggioDaInviare.existsMessage_noCache()==false){
  264.                                 this.msgDiag.logPersonalizzato("bustaNonRiscontrata.messaggioNonEsistente");
  265.                                 this.logTimer.error(this.msgDiag.getMessaggio_replaceKeywords("bustaNonRiscontrata.messaggioNonEsistente"));
  266.                                 try{
  267.                                     repositoryBuste = new RepositoryBuste(openspcoopState.getStatoRichiesta(), true,null);
  268.                                     repositoryBuste.eliminaUtilizzoPdDFromOutBox(idBustaDaRispedire);
  269.        
  270.                                     gestoreRiscontri = new Riscontri(openspcoopState.getStatoRichiesta(),null);
  271.                                     gestoreRiscontri.validazioneRiscontroRicevuto(idBustaDaRispedire);
  272.        
  273.                                     ((StateMessage)openspcoopState.getStatoRichiesta()).executePreparedStatement();
  274.                                    
  275.                                     gestiti++;
  276.                                    
  277.                                 }catch(Exception e){
  278.                                     this.msgDiag.logErroreGenerico(e,"EliminazioneBustaNonRiscontrataNonEsistente("+idBustaDaRispedire+")");
  279.                                     this.logTimer.error("ErroreEliminazioneBustaNonRiscontrataNonEsistente("+idBustaDaRispedire+"): "+e.getMessage(),e);
  280.                                 }
  281.                             }
  282.                             else{
  283.        
  284.                                 try{
  285.        
  286.                                     // PdDContext
  287.                                     PdDContext pddContext = messaggioDaInviare.getPdDContext(true); // aggiorno anche l'istanza dentro l'oggetto messaggioDaInviare stesso.
  288.                                     IProtocolFactory<?> protocolFactory = this.protocolFactoryManager.getProtocolFactoryByName((String) pddContext.getObject(org.openspcoop2.core.constants.Costanti.PROTOCOL_NAME));
  289.        
  290.                                     // Recupero busta
  291.                                     repositoryBuste = new RepositoryBuste(openspcoopState.getStatoRichiesta(),this.logTimer, true,protocolFactory);
  292.                                     Busta bustaToSend = repositoryBuste.getBustaFromOutBox(idBustaDaRispedire);
  293.                                     this.msgDiag.addKeywords(bustaToSend, true);    
  294.        
  295.                                     // Controllo se la busta e' scaduta
  296.                                     Date scadenza = bustaToSend.getScadenza();
  297.                                     Timestamp now = DateManager.getTimestamp();
  298.        
  299.                                     // Eventuale msg Scaduto.
  300.                                     if (scadenza.before(now)) {
  301.                                         // Busta scaduta
  302.        
  303.                                         this.msgDiag.logPersonalizzato("bustaNonRiscontrataScaduta");
  304.                                         if(this.logQuery)
  305.                                             this.logTimer.info(this.msgDiag.getMessaggio_replaceKeywords("bustaNonRiscontrataScaduta"));
  306.        
  307.                                         try{
  308.                                             repositoryBuste = new RepositoryBuste(openspcoopState.getStatoRichiesta(), true,protocolFactory);
  309.                                             repositoryBuste.eliminaUtilizzoPdDFromOutBox(bustaToSend.getID());
  310.                                             ((StateMessage)openspcoopState.getStatoRichiesta()).executePreparedStatement();
  311.                                             gestoreMsg = new GestoreMessaggi(openspcoopState, true, bustaToSend.getID(),Costanti.OUTBOX,this.msgDiag,pddContext);
  312.                                             gestoreMsg.validateAndDeleteMsgOneWayRiscontrato();
  313.                                         }catch(Exception e){
  314.                                             this.msgDiag.logErroreGenerico(e,"EliminazioneBustaNonRiscontrataScaduta("+bustaToSend.getID()+")");
  315.                                             this.logTimer.error("ErroreEliminazioneBustaNonRiscontrataScaduta("+bustaToSend.getID()+"): "+e.getMessage(),e);
  316.                                         }
  317.        
  318.                                     }
  319.                                     else {
  320.        
  321.                                         // Dati
  322.                                         IDSoggetto soggettoBustaNonRiscontrata = new IDSoggetto(bustaToSend.getTipoMittente(),
  323.                                                 bustaToSend.getMittente());
  324.                                         IDSoggetto identitaPdD = null;
  325.                                         String dominioRD = null;
  326.                                         try{
  327.                                             dominioRD = this.configurazionePdDReader.getIdentificativoPorta(soggettoBustaNonRiscontrata,protocolFactory,null);
  328.                                             if(dominioRD==null){
  329.                                                 throw new Exception("Dominio is null");
  330.                                             }
  331.                                         }catch(Exception e){
  332.                                             this.msgDiag.logErroreGenerico(e,"BustaNonRiscontrata getDominio("+soggettoBustaNonRiscontrata+")");
  333.                                         }
  334.                                         if(dominioRD==null){
  335.                                             identitaPdD = this.propertiesReader.getIdentitaPortaDefaultWithoutProtocol();
  336.                                         }else{
  337.                                             identitaPdD = new IDSoggetto(bustaToSend.getTipoMittente(),
  338.                                                     bustaToSend.getMittente(),dominioRD);
  339.                                         }
  340.                                         IDServizio servizioBusta = IDServizioFactory.getInstance().getIDServizioFromValues(bustaToSend.getTipoServizio(),
  341.                                                 bustaToSend.getServizio(),
  342.                                                 bustaToSend.getTipoDestinatario(),
  343.                                                 bustaToSend.getDestinatario(),
  344.                                                 bustaToSend.getVersioneServizio());
  345.                                         servizioBusta.setAzione(bustaToSend.getAzione());
  346.        
  347.                                         // Dati integrazione
  348.                                         repositoryBuste = new RepositoryBuste(openspcoopState.getStatoRichiesta(), true,protocolFactory);
  349.                                         Integrazione infoIntegrazione = repositoryBuste.getInfoIntegrazioneFromOutBox(bustaToSend.getID());
  350.                                         ProprietaErroreApplicativo erroreAppl = this.propertiesReader.getProprietaGestioneErrorePD(protocolFactory.createProtocolManager());
  351.                                         erroreAppl.setDominio(identitaPdD.getCodicePorta());
  352.        
  353.                                         // RichiestaDelegata
  354.                                         IDPortaDelegata idPD = this.configurazionePdDReader.getIDPortaDelegata(infoIntegrazione.getNomePorta(), null, protocolFactory);
  355.                                         RichiestaDelegata richiestaDelegata = new RichiestaDelegata(
  356.                                                 idPD,infoIntegrazione.getServizioApplicativo(),
  357.                                                 infoIntegrazione.getIdModuloInAttesa(),erroreAppl,identitaPdD);
  358.                                         richiestaDelegata.setScenario(infoIntegrazione.getScenario());
  359.                                         richiestaDelegata.setUtilizzoConsegnaAsincrona(true); // i riscontri sono utilizzati solo con il profilo oneway
  360.                                         richiestaDelegata.setIdCollaborazione(bustaToSend.getCollaborazione());
  361.                                         richiestaDelegata.setProfiloCollaborazione(bustaToSend.getProfiloDiCollaborazione(),bustaToSend.getProfiloDiCollaborazioneValue());
  362.                                         try{
  363.                                             richiestaDelegata.setIdCorrelazioneApplicativa(messaggioDaInviare.getIDCorrelazioneApplicativa());
  364.                                         }catch(Exception e){}
  365.        
  366.                                         // Lettura servizio applicativo
  367.                                         ServizioApplicativo sa = null;
  368.                                         String servizioApplicativo = richiestaDelegata.getServizioApplicativo();
  369.                                         try{
  370.                                             if(servizioApplicativo!=null){
  371.                                                 IDServizioApplicativo idSA = new IDServizioApplicativo();
  372.                                                 idSA.setNome(servizioApplicativo);
  373.                                                 idSA.setIdSoggettoProprietario(richiestaDelegata.getIdSoggettoFruitore());
  374.                                                 sa = this.configurazionePdDReader.getServizioApplicativo(idSA, null);
  375.                                             }
  376.                                         }catch (Exception e) {
  377.                                             if( !(e instanceof DriverConfigurazioneNotFound) || !(CostantiPdD.SERVIZIO_APPLICATIVO_ANONIMO.equals(servizioApplicativo)) ){
  378.                                                 throw e;
  379.                                             }
  380.                                         }
  381.        
  382.                                         String implementazioneMittente = this.registroServiziReader.getImplementazionePdD(new IDSoggetto(bustaToSend.getTipoMittente(),bustaToSend.getMittente()), null, null);
  383.                                         String implementazioneDestinatario = this.registroServiziReader.getImplementazionePdD(new IDSoggetto(bustaToSend.getTipoDestinatario(),bustaToSend.getDestinatario()), null, null);
  384.        
  385.                                         // Gestione errore del servizio applicativo
  386.                                         this.configurazionePdDReader.aggiornaProprietaGestioneErrorePD(erroreAppl,sa);
  387.        
  388.                                         // Profilo Gestione
  389.                                         String profiloGestione = this.registroServiziReader.getProfiloGestioneFruizioneServizio(servizioBusta, null, null);
  390.                                         richiestaDelegata.setProfiloGestione(profiloGestione);
  391.        
  392.                                         // Identificazione modalita di gestione (oneway 11 o 10)
  393.                                         PortaDelegata pd = this.configurazionePdDReader.getPortaDelegataSafeMethod(idPD, null);
  394.                                         boolean oneWayStateless = this.configurazionePdDReader.isModalitaStateless(pd, bustaToSend.getProfiloDiCollaborazione());
  395.                                         boolean oneWayVersione11 = this.propertiesReader.isGestioneOnewayStateful_1_1() && !oneWayStateless;
  396.        
  397.                                         // costruzione InoltroBuste_MEssage
  398.                                         InoltroBusteMessage inoltroMSG = new InoltroBusteMessage();
  399.                                         inoltroMSG.setRichiestaDelegata(richiestaDelegata);
  400.                                         inoltroMSG.setBusta(bustaToSend);
  401.                                         inoltroMSG.setOneWayVersione11(oneWayVersione11);
  402.                                         if(oneWayVersione11){
  403.                                             OpenSPCoopStateless stateless = new OpenSPCoopStateless();
  404.                                             StatelessMessage statelessMessage = new StatelessMessage();
  405.                                             statelessMessage.setBusta(bustaToSend);
  406.                                             stateless.setStatoRichiesta(statelessMessage);
  407.                                             inoltroMSG.setOpenspcoopstate(stateless);
  408.                                         }
  409.                                         inoltroMSG.setImplementazionePdDSoggettoMittente(implementazioneMittente);
  410.                                         inoltroMSG.setImplementazionePdDSoggettoDestinatario(implementazioneDestinatario);
  411.                                         inoltroMSG.setPddContext(pddContext);
  412.        
  413.                                         gestoreMsg = new GestoreMessaggi(openspcoopState, true, bustaToSend.getID(),Costanti.OUTBOX,this.msgDiag,pddContext);
  414.        
  415.                                         // Send Message on Queue
  416.                                         if(CostantiConfigurazione.COMUNICAZIONE_INFRASTRUTTURALE_DB.equals(TimerGestoreBusteNonRiscontrateLib.tipoNodeSender)){
  417.                                             gestoreMsg.ripristinaMessaggio();
  418.                                         }else{
  419.                                             try{
  420.        
  421.                                                 String classTypeNodeSender = null;
  422.                                                 INodeSender nodeSender = null;
  423.                                                 try{
  424.                                                     classTypeNodeSender = ClassNameProperties.getInstance().getNodeSender(TimerGestoreBusteNonRiscontrateLib.tipoNodeSender);
  425.                                                     nodeSender = (INodeSender) Loader.getInstance().newInstance(classTypeNodeSender);
  426.                                                     AbstractCore.init(nodeSender, pddContext, protocolFactory);
  427.                                                 }catch(Exception e){
  428.                                                     throw new EJBUtilsException("Riscontrato errore durante il caricamento della classe ["+classTypeNodeSender+
  429.                                                             "] da utilizzare per la spedizione nell'infrastruttura: "+e.getMessage(),e);
  430.                                                 }
  431.        
  432.                                                 nodeSender.send(inoltroMSG, InoltroBuste.ID_MODULO, this.msgDiag,
  433.                                                         this.propertiesReader.getIdentitaPortaDefaultWithoutProtocol(),TimerGestoreBusteNonRiscontrate.ID_MODULO, bustaToSend.getID(), gestoreMsg);
  434.                                             }catch(Exception e){
  435.                                                 this.msgDiag.logErroreGenerico(e,"GenericLib.nodeSender.send(InoltroBuste)");
  436.                                                 this.logTimer.error("Spedizione->InoltroBuste non riuscita",e);
  437.                                                 return;
  438.                                             }
  439.                                         }
  440.        
  441.                                     }
  442.        
  443.                                     if(this.logQuery)
  444.                                         this.logTimer.debug("Gestita/Reinviata busta OneWay non riscontrata con ID ["+ bustaToSend.getID() + "]");
  445.        
  446.                                     gestiti++;
  447.                                    
  448.                                 }catch(Exception e){
  449.                                     String msgErrore = "RespedizioneBustaNonRiscontrata ErroreGenerale("+idBustaDaRispedire+")";
  450.                                     this.msgDiag.logErroreGenerico(e,msgErrore);
  451.                                     this.logTimer.error(msgErrore+": "+e.getMessage(),e);
  452.                                 }      
  453.        
  454.        
  455.                             }
  456.        
  457.                         }
  458.        
  459.                         if(this.logQuery)
  460.                             this.logTimer.info("Gestite "+gestiti+" buste con profilo oneway non riscontrate da rispedire");
  461.        
  462.                         boolean cerca = true;
  463.                         try{
  464.                             GestoreMessaggi.updateLock(
  465.                                     this.semaphore, connectionDB, this.timerLock,
  466.                                     this.msgDiag, "Ricerca nuovo buste con profilo oneway non riscontrate ...");                        
  467.                         }catch(Throwable e){
  468.                             this.msgDiag.logErroreGenerico(e,"RicercaNuoveBusteOneWayNonRiscontrate-UpdateLock");
  469.                             this.logTimer.error("ErroreRicercaNuoveBusteOneWayNonRiscontrate-UpdateLock: "+e.getMessage(),e);
  470.                             cerca = false;
  471.                         }
  472.                        
  473.                         // Check altri riscontri da inviare
  474.                         if(cerca) {
  475.                             offsetRiscontri = offsetRiscontri + busteOneWayToSend.size();
  476.                             busteOneWayToSend =
  477.                                     rBuste.getBustePerUlterioreInoltro(this.timeout, this.limit, offsetRiscontri, this.logQuery);
  478.                         }
  479.                         else {
  480.                             busteOneWayToSend = new ArrayList<BustaNonRiscontrata>(); // per uscire dal while
  481.                         }
  482.                        
  483.                     }
  484.                 }finally{
  485.                     try{
  486.                         GestoreMessaggi.releaseLock(
  487.                                 this.semaphore, connectionDB, this.timerLock,
  488.                                 this.msgDiag, causaBusteOneWayToSend);
  489.                     }catch(Exception e){}
  490.                 }
  491.             }
  492.             else {
  493.                 if(this.logQuery) {
  494.                     this.logTimer.info("Gestione buste, con profilo oneway, disabilitata");
  495.                 }  
  496.             }





  497.             /* ----- Gestione RicevuteAsincrone per profili Asincroni ----- */
  498.             if(TimerState.ENABLED.equals(STATE_ASINCRONI)) {
  499.                 ProfiloDiCollaborazione pBuste = new ProfiloDiCollaborazione(openspcoopState.getStatoRichiesta(),this.logTimer,null);
  500.                 int offsetBusteAsincrone = 0;
  501.                 String causaBusteAsincroneToSend = "Rispedizione buste con profilo asincrono non riscontrate";
  502.                 try{
  503.                     GestoreMessaggi.acquireLock(
  504.                             this.semaphore, connectionDB, this.timerLock,
  505.                             this.msgDiag, causaBusteAsincroneToSend,
  506.                             this.propertiesReader.getTimerGestoreRiscontriRicevuteGetLockAttesaAttiva(),
  507.                             this.propertiesReader.getTimerGestoreRiscontriRicevuteGetLockCheckInterval());
  508.                    
  509.                     List<BustaNonRiscontrata> busteAsincroneToSend = null;
  510.                     busteAsincroneToSend = pBuste.asincrono_getBusteAsincronePerUlterioreInoltro(this.timeout,this.limit,offsetBusteAsincrone,this.logQuery);
  511.                     if(this.logQuery){
  512.                         if( (busteAsincroneToSend != null) && (busteAsincroneToSend.size()<=0)){
  513.                             this.logTimer.info("Non sono state trovate buste con profilo asincrono non riscontrate da rispedire");
  514.                         }
  515.                     }
  516.        
  517.                     // Gestione buste da re-spedire
  518.                     while ( (busteAsincroneToSend != null) && (busteAsincroneToSend.size()>0) ) {
  519.        
  520.                         if(this.logQuery)
  521.                             this.logTimer.info("Trovate "+busteAsincroneToSend.size()+" buste con profilo asincrono non riscontrate da rispedire ...");
  522.        
  523.                         int gestiti = 0;
  524.                         for (int i = 0; i < busteAsincroneToSend.size(); i++) {
  525.        
  526.                             BustaNonRiscontrata bustaNonRiscontrata = busteAsincroneToSend.get(i);
  527.                             String idBustaDaRispedire = bustaNonRiscontrata.getIdentificativo();
  528.                             this.msgDiag.addKeyword(CostantiPdD.KEY_ID_MESSAGGIO_RICHIESTA, idBustaDaRispedire);
  529.                             this.msgDiag.addKeyword(CostantiPdD.KEY_PROFILO_COLLABORAZIONE, bustaNonRiscontrata.getProfiloCollaborazione().name());
  530.        
  531.                             // Busta da rispedire
  532.                             this.msgDiag.logPersonalizzato("ricevutaAsincronaNonRicevuta");
  533.                             if(this.logQuery){
  534.                                 this.logTimer.debug(this.msgDiag.getMessaggio_replaceKeywords("ricevutaAsincronaNonRicevuta"));
  535.                             }
  536.                            
  537.                             try{
  538.                                 GestoreMessaggi.updateLock(
  539.                                         this.semaphore, connectionDB, this.timerLock,
  540.                                         this.msgDiag, "Rispedizione busta con profilo asincrono con id ["+idBustaDaRispedire+"] ...");
  541.                             }catch(Throwable e){
  542.                                 this.msgDiag.logErroreGenerico(e,"RispedizioneBustaNonRiscontrataAsincrona("+idBustaDaRispedire+")-UpdateLock");
  543.                                 this.logTimer.error("ErroreRispedizioneBustaNonRiscontrataAsincrona("+idBustaDaRispedire+")-UpdateLock: "+e.getMessage(),e);
  544.                                 break;
  545.                             }
  546.        
  547.                             // Controllo che alla busta corrisponda effettivamente un messaggio nel repository
  548.                             messaggioDaInviare = new GestoreMessaggi(openspcoopState,true,idBustaDaRispedire,Costanti.OUTBOX,
  549.                                     this.logTimer,this.msgDiag,null);
  550.                             if(messaggioDaInviare.existsMessage_noCache()==false){
  551.                                 this.msgDiag.logPersonalizzato("ricevutaAsincronaNonRicevuta.messaggioNonEsistente");
  552.                                 this.logTimer.error(this.msgDiag.getMessaggio_replaceKeywords("ricevutaAsincronaNonRicevuta.messaggioNonEsistente"));
  553.                                 try{
  554.                                     repositoryBuste = new RepositoryBuste(openspcoopState.getStatoRichiesta(), true,null);
  555.                                     repositoryBuste.eliminaUtilizzoPdDFromOutBox(idBustaDaRispedire);
  556.        
  557.                                     //if(bustaToSend.getRiferimentoMessaggio()==null){
  558.                                     // richiesta
  559.                                     rollbackRepositoryBuste = new RollbackRepositoryBuste(idBustaDaRispedire,openspcoopState.getStatoRichiesta(),true);
  560.                                     rollbackRepositoryBuste.rollbackBustaIntoOutBox();
  561.                                     ((StateMessage)openspcoopState.getStatoRichiesta()).executePreparedStatement();
  562.                                     //}
  563.        
  564.                                     gestiti++;
  565.                                    
  566.                                 }catch(Exception e){
  567.                                     this.msgDiag.logErroreGenerico(e,"EliminazioneBustaAsincronaNonEsistente("+idBustaDaRispedire+")");
  568.                                     this.logTimer.error("ErroreEliminazioneBustaAsincronaNonEsistente("+idBustaDaRispedire+"): "+e.getMessage(),e);
  569.                                 }
  570.                             }else{
  571.        
  572.                                 try{
  573.        
  574.                                     // PdDContext
  575.                                     PdDContext pddContext = messaggioDaInviare.getPdDContext(true); // aggiorno anche l'istanza dentro l'oggetto messaggioDaInviare stesso.;
  576.                                     IProtocolFactory<?> protocolFactory = this.protocolFactoryManager.getProtocolFactoryByName((String) pddContext.getObject(org.openspcoop2.core.constants.Costanti.PROTOCOL_NAME));
  577.        
  578.                                     // Recupero busta
  579.                                     repositoryBuste = new RepositoryBuste(openspcoopState.getStatoRichiesta(),this.logTimer, true,protocolFactory);
  580.                                     Busta bustaToSend = repositoryBuste.getBustaFromOutBox(idBustaDaRispedire);
  581.                                     this.msgDiag.addKeywords(bustaToSend, true);    
  582.        
  583.                                     // Controllo se la busta e' scaduta
  584.                                     Date scadenza = bustaToSend.getScadenza();
  585.                                     Timestamp now = DateManager.getTimestamp();
  586.        
  587.                                     // Eventuale msg Scaduto.
  588.                                     if (scadenza.before(now)) {
  589.                                         // Busta scaduta
  590.        
  591.                                         this.msgDiag.logPersonalizzato("ricevutaAsincronaNonRicevuta.bustaScaduta");
  592.                                         if(this.logQuery){
  593.                                             this.logTimer.info(this.msgDiag.getMessaggio_replaceKeywords("ricevutaAsincronaNonRicevuta.bustaScaduta"));
  594.                                         }
  595.                                         try{
  596.                                             //if(bustaToSend.getRiferimentoMessaggio()==null){
  597.                                             // richiesta
  598.                                             rollbackRepositoryBuste = new RollbackRepositoryBuste(bustaToSend.getID(),openspcoopState.getStatoRichiesta(),true);
  599.                                             rollbackRepositoryBuste.rollbackBustaIntoOutBox();
  600.                                             ((StateMessage)openspcoopState.getStatoRichiesta()).executePreparedStatement();
  601.                                             //}
  602.                                             gestoreMsg = new GestoreMessaggi(openspcoopState, true, bustaToSend.getID(),Costanti.OUTBOX,this.msgDiag,pddContext);
  603.                                             gestoreMsg.logicDeleteMessage();
  604.                                         }catch(Exception e){
  605.                                             this.msgDiag.logErroreGenerico(e,"EliminazioneBustaAsincronaScaduta("+bustaToSend.getID()+")");
  606.                                             this.logTimer.error("ErroreEliminazioneBustaAsincronaScaduta("+bustaToSend.getID()+"): "+e.getMessage(),e);
  607.                                         }
  608.        
  609.                                     }
  610.                                     else {
  611.                                         // Busta da rispedire
  612.        
  613.                                         // Dati
  614.                                         IDSoggetto soggettoBustaNonRiscontrata = new IDSoggetto(bustaToSend.getTipoMittente(),
  615.                                                 bustaToSend.getMittente());
  616.                                         IDSoggetto identitaPdD = null;
  617.                                         String dominioRD = null;
  618.                                         try{
  619.                                             dominioRD = this.configurazionePdDReader.getIdentificativoPorta(soggettoBustaNonRiscontrata,protocolFactory,null);
  620.                                             if(dominioRD==null){
  621.                                                 throw new Exception("Dominio is null");
  622.                                             }
  623.                                         }catch(Exception e){
  624.                                             this.msgDiag.logErroreGenerico(e,"BustaAsincrona getDominio("+soggettoBustaNonRiscontrata+")");
  625.                                             this.logTimer.error("ErroreBustaAsincrona getDominio("+soggettoBustaNonRiscontrata+"): "+e.getMessage(),e);
  626.                                         }
  627.                                         if(dominioRD==null){
  628.                                             identitaPdD = this.propertiesReader.getIdentitaPortaDefaultWithoutProtocol();
  629.                                         }else{
  630.                                             identitaPdD = new IDSoggetto(bustaToSend.getTipoMittente(),
  631.                                                     bustaToSend.getMittente(),dominioRD);
  632.                                         }
  633.                                         IDServizio servizioBusta = IDServizioFactory.getInstance().getIDServizioFromValues(bustaToSend.getTipoServizio(),
  634.                                                 bustaToSend.getServizio(),
  635.                                                 bustaToSend.getTipoDestinatario(),
  636.                                                 bustaToSend.getDestinatario(),
  637.                                                 bustaToSend.getVersioneServizio());
  638.                                         servizioBusta.setAzione(bustaToSend.getAzione());
  639.        
  640.                                         // Dati integrazione
  641.                                         repositoryBuste = new RepositoryBuste(openspcoopState.getStatoRichiesta(), true,protocolFactory);
  642.                                         Integrazione infoIntegrazione = repositoryBuste.getInfoIntegrazioneFromOutBox(bustaToSend.getID());
  643.                                         ProprietaErroreApplicativo erroreAppl = this.propertiesReader.getProprietaGestioneErrorePD(protocolFactory.createProtocolManager());
  644.                                         erroreAppl.setDominio(identitaPdD.getCodicePorta());
  645.        
  646.                                         // RichiestaDelegata
  647.                                         IDPortaDelegata idPD = this.configurazionePdDReader.getIDPortaDelegata(infoIntegrazione.getNomePorta(), null, protocolFactory);
  648.                                         RichiestaDelegata richiestaDelegata = new RichiestaDelegata(idPD,infoIntegrazione.getServizioApplicativo(),
  649.                                                         infoIntegrazione.getIdModuloInAttesa(),erroreAppl,identitaPdD);
  650.                                         richiestaDelegata.setScenario(infoIntegrazione.getScenario());
  651.                                         if(org.openspcoop2.protocol.sdk.constants.ProfiloDiCollaborazione.ASINCRONO_SIMMETRICO.equals(bustaToSend.getProfiloDiCollaborazione()) &&
  652.                                                 bustaToSend.getRiferimentoMessaggio() ==null)
  653.                                             richiestaDelegata.setUtilizzoConsegnaAsincrona(false); // una richiesta asincrona simmetrica non deve utilizzare la consegna asincrona della ricevuta applicativa/ok
  654.                                         else
  655.                                             richiestaDelegata.setUtilizzoConsegnaAsincrona(true);
  656.                                         richiestaDelegata.setRicevutaAsincrona(false); // solo in caso di non-gestione della ricevuta applicativa, viene attivato il timer
  657.        
  658.                                         // Lettura servizio applicativo
  659.                                         ServizioApplicativo sa = null;
  660.                                         String servizioApplicativo = richiestaDelegata.getServizioApplicativo();
  661.                                         try{
  662.                                             if(servizioApplicativo!=null){
  663.                                                 IDServizioApplicativo idSA = new IDServizioApplicativo();
  664.                                                 idSA.setNome(servizioApplicativo);
  665.                                                 idSA.setIdSoggettoProprietario(richiestaDelegata.getIdSoggettoFruitore());
  666.                                                 sa = this.configurazionePdDReader.getServizioApplicativo(idSA, null);
  667.                                             }
  668.                                         }catch (Exception e) {
  669.                                             if( !(e instanceof DriverConfigurazioneNotFound) || !(CostantiPdD.SERVIZIO_APPLICATIVO_ANONIMO.equals(servizioApplicativo)) ){
  670.                                                 throw e;
  671.                                             }
  672.                                         }
  673.        
  674.                                         // Aggiornamento informazioni integrazioni servizio applicativo
  675.                                         this.configurazionePdDReader.aggiornaProprietaGestioneErrorePD(erroreAppl,sa);
  676.        
  677.                                         // costruzione InoltroBuste_MEssage
  678.                                         InoltroBusteMessage inoltroMSG = new InoltroBusteMessage();
  679.                                         inoltroMSG.setRichiestaDelegata(richiestaDelegata);
  680.                                         inoltroMSG.setBusta(bustaToSend);
  681.        
  682.                                         gestoreMsg = new GestoreMessaggi(openspcoopState, true, bustaToSend.getID(),Costanti.OUTBOX,this.msgDiag,pddContext);
  683.                                         inoltroMSG.setPddContext(pddContext);
  684.        
  685.                                         // Send Message on Queue
  686.                                         if(CostantiConfigurazione.COMUNICAZIONE_INFRASTRUTTURALE_DB.equals(TimerGestoreBusteNonRiscontrateLib.tipoNodeSender)){
  687.                                             gestoreMsg.ripristinaMessaggio();
  688.                                         }else{
  689.                                             try{
  690.        
  691.                                                 String classTypeNodeSender = null;
  692.                                                 INodeSender nodeSender = null;
  693.                                                 try{
  694.                                                     classTypeNodeSender = ClassNameProperties.getInstance().getNodeSender(TimerGestoreBusteNonRiscontrateLib.tipoNodeSender);
  695.                                                     nodeSender = (INodeSender) Loader.getInstance().newInstance(classTypeNodeSender);
  696.                                                     AbstractCore.init(nodeSender, pddContext, protocolFactory);
  697.                                                 }catch(Exception e){
  698.                                                     throw new EJBUtilsException("Riscontrato errore durante il caricamento della classe ["+classTypeNodeSender+
  699.                                                             "] da utilizzare per la spedizione nell'infrastruttura: "+e.getMessage(),e);
  700.                                                 }
  701.        
  702.                                                 nodeSender.send(inoltroMSG, InoltroBuste.ID_MODULO, this.msgDiag,
  703.                                                         this.propertiesReader.getIdentitaPortaDefaultWithoutProtocol(),TimerGestoreBusteNonRiscontrate.ID_MODULO, bustaToSend.getID(), gestoreMsg);
  704.                                             }catch(Exception e){
  705.                                                 this.msgDiag.logErroreGenerico(e,"Asincrono GenericLib.nodeSender.send(InoltroBuste)");
  706.                                                 this.logTimer.error("Spedizione->InoltroBuste non riuscita",e);
  707.                                                 return;
  708.                                             }
  709.                                         }
  710.                                     }
  711.        
  712.                                     if(this.logQuery){
  713.                                         this.logTimer.info("Gestita/Reinviata busta asincrona, la cui ricevuta non e' pervenuta, con ID ["+ bustaToSend.getID() + "]");
  714.                                     }
  715.        
  716.                                     gestiti++;
  717.        
  718.                                 }catch(Exception e){
  719.                                     String msgErrore = "RespedizioneBustaAsincrona ErroreGenerale("+idBustaDaRispedire+")";
  720.                                     this.msgDiag.logErroreGenerico(e,msgErrore);
  721.                                     this.logTimer.error(msgErrore+": "+e.getMessage(),e);
  722.                                 }
  723.                             }
  724.        
  725.                         }
  726.        
  727.                         if(this.logQuery)
  728.                             this.logTimer.info("Gestite "+gestiti+" buste con profilo asincrono non riscontrate da rispedire");
  729.        
  730.                         boolean cerca = true;
  731.                         try{
  732.                             GestoreMessaggi.updateLock(
  733.                                     this.semaphore, connectionDB, this.timerLock,
  734.                                     this.msgDiag, "Ricerca nuovo buste con profilo asincrono non riscontrate ...");                    
  735.                         }catch(Throwable e){
  736.                             this.msgDiag.logErroreGenerico(e,"RicercaNuoveBusteAsincroneNonRiscontrate-UpdateLock");
  737.                             this.logTimer.error("ErroreRicercaNuoveBusteAsincroneNonRiscontrate-UpdateLock: "+e.getMessage(),e);
  738.                             cerca = false;
  739.                         }
  740.                        
  741.                         // Check altri riscontri da inviare
  742.                         if(cerca) {                
  743.                             // Check altre buste da inviare
  744.                             offsetBusteAsincrone = offsetBusteAsincrone + busteAsincroneToSend.size();
  745.                             busteAsincroneToSend =
  746.                                     pBuste.asincrono_getBusteAsincronePerUlterioreInoltro(this.timeout,this.limit,offsetBusteAsincrone,this.logQuery);
  747.                         }
  748.                         else {
  749.                             busteAsincroneToSend = new ArrayList<BustaNonRiscontrata>(); // per uscire dal while
  750.                         }
  751.                     }
  752.                 }finally{
  753.                     try{
  754.                         GestoreMessaggi.releaseLock(
  755.                                 this.semaphore, connectionDB, this.timerLock,
  756.                                 this.msgDiag, causaBusteAsincroneToSend);
  757.                     }catch(Exception e){}
  758.                 }
  759.             }
  760.             else {
  761.                 if(this.logQuery) {
  762.                     this.logTimer.info("Gestione buste, con profilo asincrono, disabilitata");
  763.                 }  
  764.             }
  765.            

  766.             // end
  767.             long endControlloBusteNonRiscontrate = DateManager.getTimeMillis();
  768.             long diff = (endControlloBusteNonRiscontrate-startControlloBusteNonRiscontrate);
  769.             this.logTimer.info("Controllo Buste in attesa di riscontro terminato in "+Utilities.convertSystemTimeIntoStringMillisecondi(diff, true));

  770.         }
  771.         catch(TimerLockNotAvailableException t) {
  772.             // msg diagnostico emesso durante l'emissione dell'eccezione
  773.             this.logTimer.info(t.getMessage(),t);
  774.         }
  775.         catch (Exception e) {
  776.             this.msgDiag.logErroreGenerico(e,"GestioneBusteNonRiscontrate");
  777.             this.logTimer.error("Riscontrato errore durante la gestione delle buste non riscontrate: "+ e.getMessage(),e);
  778.             return;
  779.         }finally{
  780.             if(openspcoopState!=null)
  781.                 openspcoopState.releaseResource();
  782.         }
  783.     }

  784. }