1 21 22 package com.rift.coad.daemon.jython; 23 24 import com.rift.coad.daemon.timer.TimerEventHandler; 25 import com.rift.coad.daemon.timer.TimerException; 26 import com.rift.coad.lib.configuration.ConfigurationException; 27 import java.io.File ; 28 import java.io.FileInputStream ; 29 import java.io.Serializable ; 30 import java.rmi.RemoteException ; 31 import org.apache.log4j.Logger; 32 import org.python.util.PythonInterpreter; 33 34 38 public class JythonTimerImpl implements TimerEventHandler { 39 40 protected Logger log = 41 Logger.getLogger(JythonDaemonImpl.class.getName()); 42 43 public String scriptLocal = ""; 44 45 46 public JythonTimerImpl() throws Exception { 47 try { 48 com.rift.coad.lib.configuration.Configuration coadConfig = 49 com.rift.coad.lib.configuration.ConfigurationFactory. 50 getInstance().getConfig(com.rift.coad.daemon.jython. 51 JythonDaemonImpl.class); 52 System.setProperty("python.home", 53 coadConfig.getString("python_home")); 54 scriptLocal = coadConfig.getString("script_location"); 55 } catch (ConfigurationException ex) { 56 log.error("Failed to set jython properties :" + ex.getMessage(), 57 ex); 58 throw new Exception ("Failed to set jython properties :" + ex); 59 } 60 } 61 62 69 public void processEvent(Serializable serializable) throws RemoteException , 70 TimerException { 71 String name = (String ) serializable; 72 File scriptFile = new File (scriptLocal + File.separator + name); 73 try { 74 FileInputStream fis = new FileInputStream (scriptFile); 75 PythonInterpreter inter = new PythonInterpreter(); 76 inter.execfile(fis); 77 } catch (Exception ex) { 78 log.error("Failed to retrieve and run script:" + ex, ex); 79 } 80 } 81 82 } 83 | Popular Tags |