ConfigurazionePriorita.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. import org.openspcoop2.utils.UtilsException;

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

  31.     private String name;
  32.     private int percentuale;
  33.     private boolean nessunaPriorita;

  34.     private String label;
  35.    
  36.     public ConfigurazionePriorita(String name, Properties p) throws UtilsException {
  37.         this.name = name;
  38.         this.percentuale = getIntProperty(this.name, p, "percentuale");
  39.         this.label = getProperty(this.name, p, "label");
  40.         this.nessunaPriorita = this.percentuale<=0;
  41.     }
  42.    
  43.     private static String getProperty(String coda, Properties p, String name) throws UtilsException {
  44.         String tmp = p.getProperty(name);
  45.         if(tmp==null) {
  46.             throw new UtilsException("[Queue:"+coda+"] Property '"+name+"' not found");
  47.         }
  48.         return tmp.trim();
  49.     }
  50.     private static int getIntProperty(String coda, Properties p, String name) throws UtilsException {
  51.         String tmp = getProperty(coda, p, name);
  52.         try {
  53.             return Integer.valueOf(tmp);
  54.         }catch(Exception e) {
  55.             throw new UtilsException("[Queue:"+coda+"] Property '"+name+"' uncorrect (value:"+tmp+"): "+e.getMessage(),e);
  56.         }
  57.     }
  58.    
  59.     public String getName() {
  60.         return this.name;
  61.     }

  62.     public int getPercentuale() {
  63.         return this.percentuale;
  64.     }

  65.     public String getLabel() {
  66.         return this.label;
  67.     }

  68.     public boolean isNessunaPriorita() {
  69.         return this.nessunaPriorita;
  70.     }

  71. }