1 13 package org.ejbca.core.model.services.intervals; 14 15 import javax.ejb.EJBException ; 16 17 import org.apache.log4j.Logger; 18 import org.ejbca.core.model.InternalResources; 19 import org.ejbca.core.model.services.BaseInterval; 20 21 30 public class PeriodicalInterval extends BaseInterval { 31 32 private static final Logger log = Logger.getLogger(PeriodicalInterval.class); 33 34 private static final InternalResources intres = InternalResources.getInstance(); 35 36 public static final String PROP_UNIT = "interval.periodical.unit"; 37 public static final String PROP_VALUE = "interval.periodical.value"; 38 39 public static final String UNIT_SECONDS = "SECONDS"; 40 public static final String UNIT_MINUTES = "MINUTES"; 41 public static final String UNIT_HOURS = "HOURS"; 42 public static final String UNIT_DAYS = "DAYS"; 43 44 public static final int UNITVAL_SECONDS = 1; 45 public static final int UNITVAL_MINUTES = 60; 46 public static final int UNITVAL_HOURS = 3600; 47 public static final int UNITVAL_DAYS = 86400; 48 49 public static final String [] AVAILABLE_UNITS = {UNIT_SECONDS, UNIT_MINUTES, UNIT_HOURS, UNIT_DAYS}; 50 public static final int[] AVAILABLE_UNITSVALUES = {UNITVAL_SECONDS, UNITVAL_MINUTES, UNITVAL_HOURS, UNITVAL_DAYS}; 51 52 53 private transient int interval = 0; 54 55 62 public long getTimeToExecution() { 63 log.debug(">PeriodicalInterval.getTimeToExecution()"); 64 if(interval == 0){ 65 String unit = properties.getProperty(PROP_UNIT); 66 if(unit == null){ 67 String msg = intres.getLocalizedMessage("services.interval.errorconfig", serviceName, "UNIT"); 68 throw new EJBException (msg); 69 } 70 int unitval = 0; 71 for(int i=0;i<AVAILABLE_UNITS.length;i++){ 72 if(AVAILABLE_UNITS[i].equalsIgnoreCase(unit)){ 73 unitval = AVAILABLE_UNITSVALUES[i]; 74 break; 75 } 76 } 77 if(unitval == 0){ 78 String msg = intres.getLocalizedMessage("services.interval.errorconfig", serviceName, "UNIT"); 79 throw new EJBException (msg); 80 } 81 82 String value = properties.getProperty(PROP_VALUE); 83 int intvalue = 0; 84 try{ 85 intvalue = Integer.parseInt(value); 86 }catch(NumberFormatException e){ 87 String msg = intres.getLocalizedMessage("services.interval.errorconfig", serviceName, "VALUE"); 88 throw new EJBException (msg); 89 } 90 91 if(intvalue == 0){ 92 String msg = intres.getLocalizedMessage("services.interval.errorconfig", serviceName, "UNIT"); 93 throw new EJBException (msg); 94 } 95 interval = intvalue * unitval; 96 } 97 log.debug("PeriodicalInterval.getTimeToExecution() : " + interval); 98 return interval; 99 } 100 101 } 102 | Popular Tags |