1 13 package org.ejbca.core.model.services; 14 15 import java.util.Properties ; 16 17 import org.apache.log4j.Logger; 18 import org.ejbca.core.model.InternalResources; 19 import org.ejbca.core.model.log.Admin; 20 import org.ejbca.core.model.services.intervals.DummyInterval; 21 22 29 public abstract class BaseWorker extends BaseServiceComponent implements IWorker { 30 31 private static final Logger log = Logger.getLogger(BaseWorker.class); 32 33 34 private static final InternalResources intres = InternalResources.getInstance(); 35 36 protected Properties properties = null; 37 protected String serviceName = null; 38 private IAction action = null; 39 private IInterval interval = null; 40 41 private Admin admin = null; 42 43 46 public void init(Admin admin, ServiceConfiguration serviceConfiguration, 47 String serviceName) { 48 this.admin = admin; 49 this.serviceName = serviceName; 50 this.properties = serviceConfiguration.getWorkerProperties(); 51 52 String actionClassPath = serviceConfiguration.getActionClassPath(); 53 if(actionClassPath != null){ 54 try { 55 action = (IAction) this.getClass().getClassLoader().loadClass(actionClassPath).newInstance(); 56 action.init(serviceConfiguration.getActionProperties(), serviceName); 57 } catch (Exception e) { 58 String msg = intres.getLocalizedMessage("services.erroractionclasspath", serviceName); 59 log.error(msg,e); 60 } 61 }else{ 62 log.debug("Warning no action class i defined for the service " + serviceName); 63 } 64 65 String intervalClassPath = serviceConfiguration.getIntervalClassPath(); 66 if(intervalClassPath != null){ 67 try { 68 interval = (IInterval) this.getClass().getClassLoader().loadClass(intervalClassPath).newInstance(); 69 interval.init(serviceConfiguration.getIntervalProperties(), serviceName); 70 } catch (Exception e) { 71 String msg = intres.getLocalizedMessage("services.errorintervalclasspath", serviceName); 72 log.error(msg,e); 73 } 74 }else{ 75 String msg = intres.getLocalizedMessage("services.errorintervalclasspath", serviceName); 76 log.error(msg); 77 } 78 79 if(interval == null){ 80 interval = new DummyInterval(); 81 } 82 83 } 84 85 86 89 public long getNextInterval() { 90 return interval.getTimeToExecution(); 91 } 92 93 protected IAction getAction(){ 94 if(action == null){ 95 String msg = intres.getLocalizedMessage("services.erroractionclasspath", serviceName); 96 log.error(msg); 97 } 98 return action; 99 } 100 101 104 protected Admin getAdmin(){ 105 return admin; 106 } 107 108 109 } 110 | Popular Tags |