TimerLock.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. /**
  22.  * TimerLock
  23.  *
  24.  * @author Poli Andrea (apoli@link.it)
  25.  * @author $Author$
  26.  * @version $Rev$, $Date$
  27.  */


  28. public class TimerLock {

  29.     public static TimerLock newInstance(TipoLock tipoLock) throws TimerException {
  30.         return new TimerLock(tipoLock);
  31.     }
  32.    
  33.     public TimerLock(TipoLock tipoLock) throws TimerException {
  34.         this(tipoLock,tipoLock.getTipo());
  35.         check(tipoLock);
  36.     }
  37.     private static void check(TipoLock tipoLock) throws TimerException {
  38.         if(TipoLock.CUSTOM.equals(tipoLock) || TipoLock.CONSEGNA_NOTIFICHE.equals(tipoLock)) {
  39.             throw new TimerException("Tipo lock '"+tipoLock+"' non utilizzabile senza fornire l'id del lock");
  40.         }
  41.     }
  42.     public TimerLock(TipoLock tipoLock, String idLock) throws TimerException {
  43.         if(tipoLock==null) {
  44.             throw new TimerException("Tipo lock non definito");
  45.         }
  46.         if( (TipoLock.CUSTOM.equals(tipoLock) || TipoLock.CONSEGNA_NOTIFICHE.equals(tipoLock))
  47.                 &&
  48.                 (idLock==null || "".equals(idLock)) ) {
  49.             throw new TimerException("Tipo lock '"+tipoLock+"' non utilizzabile senza fornire l'id del lock");
  50.         }
  51.         this.tipoLock = tipoLock;
  52.         if(idLock==null || "".equals(idLock)) {
  53.             this.idLock = tipoLock.getTipo();
  54.         }
  55.         else if(TipoLock.CONSEGNA_NOTIFICHE.equals(tipoLock)) {
  56.             this.idLock = getIdLockConsegnaNotifica(idLock);
  57.         }
  58.         else {
  59.             this.idLock = idLock;
  60.         }
  61.     }
  62.    
  63.     public static String getIdLockConsegnaNotifica(String queue) throws TimerException {
  64.         if(queue==null) {
  65.             throw new TimerException("Coda non definita");
  66.         }
  67.         return TipoLock.CONSEGNA_NOTIFICHE.getTipo()+"-"+queue;
  68.     }  
  69.    
  70.     private TipoLock tipoLock;
  71.     private String idLock;

  72.     public TipoLock getTipoLock() {
  73.         return this.tipoLock;
  74.     }
  75.     public void setTipoLock(TipoLock tipoLock) {
  76.         this.tipoLock = tipoLock;
  77.     }
  78.     public String getIdLock() {
  79.         return this.idLock;
  80.     }
  81.     public void setIdLock(String idLock) {
  82.         this.idLock = idLock;
  83.     }
  84. }