1 16 package dlog4j.hsqldb; 17 18 import java.io.IOException ; 19 20 import javax.servlet.ServletException ; 21 import javax.servlet.http.HttpServlet ; 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 25 import dlog4j.util.StringUtils; 26 27 32 public class HSQLEngineServlet extends HttpServlet { 33 34 String path = "/WEB-INF/db"; 35 String database = "mydlog"; 36 int port = 9001; 37 38 41 public void init() throws ServletException { 42 String tPath = getInitParameter("path"); 44 if(StringUtils.isNotEmpty(tPath)) 45 path = tPath; 46 String tDatabase = getInitParameter("database"); 47 if(StringUtils.isNotEmpty(tDatabase)) 48 database = tDatabase; 49 String tPort = getInitParameter("port"); 50 if(StringUtils.isNumeric(tPort)){ 51 int nPort = Integer.parseInt(tPort); 52 if(nPort>1024 && nPort<65536) 53 port = nPort; 54 } 55 String dataPath; 56 if(path.startsWith("/")) 57 dataPath = getServletContext().getRealPath(path); 58 else 59 dataPath = path; 60 HSQLEngine engine = HSQLEngine.getEngine(dataPath,port,database); 62 engine.start(); 63 while(!engine.isRunning()){ 64 try{ 65 Thread.sleep(200); 66 }catch(Exception e){} 67 } 68 log("HSQLEngine of DLOG4J started."); 69 } 70 71 protected void doGet(HttpServletRequest req, HttpServletResponse res) 72 throws ServletException , IOException { 73 } 75 76 79 public void destroy() { 80 try{ 81 HSQLEngine.getEngine(null,-1,null).stop(); 82 }catch(Exception e){} 83 } 84 } 85 | Popular Tags |