1 22 package org.jboss.test.timer.servlet; 23 24 import java.io.IOException ; 25 import java.io.PrintWriter ; 26 import java.util.Date ; 27 import javax.servlet.http.HttpServlet ; 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 import javax.servlet.ServletConfig ; 31 import javax.servlet.ServletException ; 32 import javax.naming.InitialContext ; 33 34 import org.jboss.test.timer.interfaces.TimerSLSBHome; 35 import org.jboss.test.timer.interfaces.TimerSLSB; 36 import org.jboss.logging.Logger; 37 38 45 public class InitTimerServlet extends HttpServlet 46 { 47 private static Logger log = Logger.getLogger(InitTimerServlet.class); 48 private static byte[] handle; 49 50 56 public void init(ServletConfig servletConfig) throws ServletException 57 { 58 super.init(servletConfig); 59 log.info("init, creating ejb timer"); 60 try 62 { 63 InitialContext ctx = new InitialContext (); 64 TimerSLSBHome home = (TimerSLSBHome) ctx.lookup("java:/comp/env/ejb/TimerSLSBHome"); 65 TimerSLSB bean = home.create(); 66 handle = bean.startTimer(60000); 67 } 68 catch(Exception e) 69 { 70 throw new ServletException (e); 71 } 72 } 73 74 protected void doGet(HttpServletRequest request, HttpServletResponse response) 75 throws ServletException , IOException 76 { 77 try 78 { 79 InitialContext ctx = new InitialContext (); 80 TimerSLSBHome home = (TimerSLSBHome) ctx.lookup("java:/comp/env/ejb/TimerSLSBHome"); 81 TimerSLSB bean = home.create(); 82 int timeoutCount = bean.getTimeoutCount(handle); 83 Date nextTimeout = bean.getNextTimeout(handle); 84 long timeRemaining = bean.getTimeRemaining(handle); 85 PrintWriter pw = response.getWriter(); 86 pw.println("<html><head><title>InitTimerServlet</title></head><body>"); 87 pw.println("<h1>Timer Info</h1>"); 88 pw.println("TimeoutCount:"+timeoutCount); 89 pw.println("<br>NextTimeout:"+nextTimeout); 90 pw.println("<br>TimeRemaining:"+timeRemaining); 91 pw.println("</body></html>"); 92 } 93 catch(Exception e) 94 { 95 throw new ServletException (e); 96 } 97 } 98 } 99 | Popular Tags |