ConfigurazioneCoda.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.config;

  21. import java.util.Properties;

  22. /**
  23.  * ConfigurazioneCoda
  24.  *
  25.  * @author Poli Andrea (apoli@link.it)
  26.  * @author $Author$
  27.  * @version $Rev$, $Date$
  28.  */
  29. public class ConfigurazioneCoda {

  30.     private String name;

  31.     private int poolSize;
  32.     private int queueSize;
  33.    
  34.     private int nextMessages_limit;
  35.     private int nextMessages_intervalloControllo;
  36.    
  37.     private Integer scheduleNewMessageAfter;
  38.    
  39.     private int nextMessages_consegnaFallita_intervalloControllo;
  40.     private boolean nextMessages_consegnaFallita_calcolaDataMinimaRiconsegna;
  41.    
  42.     private int consegnaFallita_intervalloMinimoRiconsegna;
  43.        
  44.     private boolean debug = false;
  45.    
  46.     public ConfigurazioneCoda(String name, Properties p) throws Exception {
  47.         this.name = name;
  48.        
  49.         this.poolSize = getIntProperty(this.name, p, "threads.poolSize");
  50.         this.queueSize = getIntProperty(this.name, p, "threads.queueSize");
  51.        
  52.         this.nextMessages_limit = getIntProperty(this.name, p, "nextMessages.limit");
  53.         this.nextMessages_intervalloControllo = getIntProperty(this.name, p, "nextMessages.intervalloControllo");
  54.        
  55.         String tmp = p.getProperty("nextMessages.scheduleNewMessageAfter");
  56.         if(tmp!=null) {
  57.             try {
  58.                 this.scheduleNewMessageAfter = Integer.valueOf(tmp);
  59.             }catch(Throwable t) {
  60.                 throw new Exception("[Queue:"+this.name+"] Property 'nextMessages.scheduleNewMessageAfter' invalid: "+t.getMessage(),t);
  61.             }
  62.             if(this.scheduleNewMessageAfter<=0) {// lasciare per poter annullare da properties
  63.                 this.scheduleNewMessageAfter = null;
  64.             }
  65.         }
  66.        
  67.         this.nextMessages_consegnaFallita_intervalloControllo = getIntProperty(this.name, p, "nextMessages.consegnaFallita.intervalloControllo");
  68.         this.nextMessages_consegnaFallita_calcolaDataMinimaRiconsegna = getBooleanProperty(this.name, p, "nextMessages.consegnaFallita.calcolaDataMinimaRiconsegna");
  69.        
  70.         this.consegnaFallita_intervalloMinimoRiconsegna  = getIntProperty(this.name, p, "consegnaFallita.intervalloMinimoRiconsegna");
  71.        
  72.         this.debug = getBooleanProperty(this.name, p, "debug");
  73.     }
  74.    
  75.     @Override
  76.     public String toString() {
  77.         return this.toString(true, ", ");
  78.     }
  79.     public String toString(boolean printName, String separator) {
  80.         StringBuilder sb = new StringBuilder();
  81.         if(printName) {
  82.             sb.append("name:").append(this.name).append(separator);
  83.         }
  84.         sb.append("poolSize:").append(this.poolSize).append(separator);
  85.         sb.append("queueSize:").append(this.queueSize).append(separator);
  86.         sb.append("nextMessages_limit:").append(this.nextMessages_limit).append(separator);
  87.         sb.append("nextMessages_newCheckEverySeconds:").append(this.nextMessages_intervalloControllo).append(separator);
  88.         if(this.scheduleNewMessageAfter!=null) {
  89.             sb.append("nextMessages_scheduleNewMessageAfter:").append(this.scheduleNewMessageAfter).append(separator);
  90.         }
  91.         sb.append("nextMessages_checkFailedDelivery_everySeconds:").append(this.nextMessages_consegnaFallita_intervalloControllo).append(separator);
  92.         sb.append("nextMessages_checkFailedDelivery_computeMinDate:").append(this.nextMessages_consegnaFallita_calcolaDataMinimaRiconsegna).append(separator);
  93.         sb.append("nextFailedDeliveryAfterSeconds:").append(this.consegnaFallita_intervalloMinimoRiconsegna);
  94.         return sb.toString();
  95.     }
  96.    
  97.     private static String getProperty(String coda, Properties p, String name) throws Exception {
  98.         String tmp = p.getProperty(name);
  99.         if(tmp==null) {
  100.             throw new Exception("[Queue:"+coda+"] Property '"+name+"' not found");
  101.         }
  102.         return tmp.trim();
  103.     }
  104.     private static int getIntProperty(String coda, Properties p, String name) throws Exception {
  105.         String tmp = getProperty(coda, p, name);
  106.         try {
  107.             return Integer.valueOf(tmp);
  108.         }catch(Exception e) {
  109.             throw new Exception("[Queue:"+coda+"] Property '"+name+"' uncorrect (value:"+tmp+"): "+e.getMessage(),e);
  110.         }
  111.     }
  112.     private static boolean getBooleanProperty(String coda, Properties p, String name) throws Exception {
  113.         String tmp = getProperty(coda, p, name);
  114.         try {
  115.             return Boolean.valueOf(tmp);
  116.         }catch(Exception e) {
  117.             throw new Exception("[Queue:"+coda+"] Property '"+name+"' uncorrect (value:"+tmp+"): "+e.getMessage(),e);
  118.         }
  119.     }
  120.    
  121.     public String getName() {
  122.         return this.name;
  123.     }

  124.     public int getPoolSize() {
  125.         return this.poolSize;
  126.     }

  127.     public int getQueueSize() {
  128.         return this.queueSize;
  129.     }

  130.     public int getNextMessages_limit() {
  131.         return this.nextMessages_limit;
  132.     }

  133.     public int getNextMessages_intervalloControllo() {
  134.         return this.nextMessages_intervalloControllo;
  135.     }

  136.     public Integer getScheduleMessageAfter() {
  137.         return this.scheduleNewMessageAfter;
  138.     }
  139.    
  140.     public int getNextMessages_consegnaFallita_intervalloControllo() {
  141.         return this.nextMessages_consegnaFallita_intervalloControllo;
  142.     }

  143.     public boolean isNextMessages_consegnaFallita_calcolaDataMinimaRiconsegna() {
  144.         return this.nextMessages_consegnaFallita_calcolaDataMinimaRiconsegna;
  145.     }
  146.    
  147.     public int getConsegnaFallita_intervalloMinimoRiconsegna() {
  148.         return this.consegnaFallita_intervalloMinimoRiconsegna;
  149.     }
  150.    
  151.     public boolean isDebug() {
  152.         return this.debug;
  153.     }
  154.    
  155. }