public ServletTimer createTimer( ApplicationSession appSession, long delay, boolean isPersistent, Serializable info) { if (LOG.isDebugEnabled()) { LOG.debug( "Create timer for application " + appSession.getApplicationName() + " (delay=" + delay + ", persistent=" + isPersistent + ")"); } ApplicationSessionImpl applicationSessionImpl = (ApplicationSessionImpl) appSession; applicationSessionImpl.checkValid(); if (!applicationSessionImpl.hasTimerListener()) { throw new IllegalStateException( "No Timer listeners have been configured for this application "); } TimerListener listener = applicationSessionImpl.getServletContextInternal().getTimerListener(); ServletTimerImpl servletTimer = createTimerLocally(listener, delay, isPersistent, info, applicationSessionImpl); return servletTimer; }
public void run() { long run = System.currentTimeMillis(); // PORTAGE chgt de classLoader pour le currentThread // ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); try { // ClassLoader cl = listener.getClass().getClassLoader(); // Thread.currentThread().setContextClassLoader(cl); LOG.debug("Call timeout"); listener.timeout(this); } catch (Throwable e) { LOG.error("An unexpected exception happened in the timer callback", e); } finally { // Thread.currentThread().setContextClassLoader(oldClassLoader); if (repeatingTimer) { LOG.debug("Reset repeating servlet timer"); estimateNextExecution(); } else { LOG.debug("Cancel servlet timer"); // this non-repeating timer is now "ready" // and should not be included in the list of active timers // The application may already have canceled() the timer though cancel(); // dont bother about return value.... } } run = System.currentTimeMillis() - run; if (run > 500) { LOG.error( appSession.getId() + ": The servlet timer has taken more than 500 ms to be handled: " + run + " ms"); } }
/** * @param listener * @param delay * @param isPersistent * @param info * @param applicationSession * @return */ private ServletTimerImpl createTimerLocally( TimerListener listener, long delay, boolean isPersistent, Serializable info, ApplicationSessionImpl applicationSession) { ServletTimerImpl servletTimer = new ServletTimerImpl(info, delay, listener, applicationSession); super.schedule(servletTimer.getServletTimerTask(), delay); applicationSession.addServletTimer(servletTimer); if (isPersistent) { persist(servletTimer); } return servletTimer; }
/** * @param listener * @param delay * @param period * @param fixedDelay * @param isPersistent * @param info * @param applicationSession * @return */ private ServletTimerImpl createTimerLocally( TimerListener listener, long delay, long period, boolean fixedDelay, boolean isPersistent, Serializable info, ApplicationSessionImpl applicationSession) { final ServletTimerImpl servletTimer = new ServletTimerImpl(info, delay, fixedDelay, period, listener, applicationSession); if (fixedDelay) { super.schedule(servletTimer.getServletTimerTask(), delay, period); } else { super.scheduleAtFixedRate(servletTimer.getServletTimerTask(), delay, period); } applicationSession.addServletTimer(servletTimer); if (isPersistent) { persist(servletTimer); } return servletTimer; }
public void cancel() { LOG.debug("removeServletTimer"); appSession.removeServletTimer(this); LOG.debug("cancel timerTask"); timerTask.cancel(); }