QueueManager.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.web.ctrlstat.core;

  21. import java.util.Properties;

  22. import javax.jms.Queue;
  23. import javax.jms.QueueConnectionFactory;
  24. import javax.naming.NamingException;

  25. import org.openspcoop2.pdd.config.OpenSPCoop2ConfigurationException;
  26. import org.openspcoop2.utils.UtilsException;
  27. import org.openspcoop2.utils.resources.GestoreJNDI;
  28. import org.openspcoop2.web.lib.queue.config.QueueProperties;

  29. /**
  30.  * QueueManager
  31.  *
  32.  * @author Andrea Poli (apoli@link.it)
  33.  * @author Stefano Corallo (corallo@link.it)
  34.  * @author Sandra Giangrandi (sandra@link.it)
  35.  * @author $Author$
  36.  * @version $Rev$, $Date$
  37.  *
  38.  */
  39. public class QueueManager {

  40.     private static QueueManager manager;
  41.     private static String cfName;
  42.     private static Properties cfProp;

  43.     private QueueConnectionFactory qcf;
  44.     private GestoreJNDI jndi;

  45.     private QueueManager() {
  46.         try {
  47.             // leggo parametri dal file properties
  48.             QueueManager.readQueueProperties();
  49.             // Inizializzo il gestorejndi
  50.             this.jndi = new GestoreJNDI(QueueManager.cfProp);

  51.         } catch (Exception e) {
  52.             // ignore
  53.         }
  54.     }

  55.     private static synchronized void init() {
  56.         if (QueueManager.manager == null) {
  57.             QueueManager.manager = new QueueManager();
  58.         }
  59.     }
  60.     public static QueueManager getInstance() {
  61.         if (QueueManager.manager == null) {
  62.             // spotbugs warning 'SING_SINGLETON_GETTER_NOT_SYNCHRONIZED': l'istanza viene creata allo startup
  63.             synchronized (QueueManager.class) {
  64.                 init();
  65.             }
  66.         }

  67.         return QueueManager.manager;
  68.     }

  69.     public Queue getQueue(String queueName) throws UtilsException {
  70.         return (Queue) this.jndi.lookup(queueName);
  71.     }

  72.     public QueueConnectionFactory getQueueConnectionFactory() throws NamingException {
  73.         // istanzio connection factory
  74.         try {
  75.             this.qcf = (QueueConnectionFactory) this.jndi.lookup(QueueManager.cfName);
  76.         } catch (Exception e) {
  77.             // ignore
  78.         }
  79.         if (this.qcf == null) {
  80.             throw new NamingException("ConnectionFactory non inizializzata.");
  81.         }

  82.         return this.qcf;
  83.     }

  84.     private static void readQueueProperties() throws UtilsException, OpenSPCoop2ConfigurationException {

  85.         QueueProperties queueProperties = QueueProperties.getInstance();
  86.        
  87.         QueueManager.cfName = queueProperties.getConnectionFactory();
  88.        
  89.         QueueManager.cfProp = queueProperties.getConnectionFactoryContext();

  90.     }

  91. }