public SipApplicationSessionTimerTask createSipApplicationSessionTimerTask(MobicentsSipApplicationSession sipApplicationSession) { return new DefaultSasTimerTask(sipApplicationSession); }
private void tryToExpire() { final SipContext sipContext = getSipApplicationSession().getSipContext(); sipContext.enterSipApp(getSipApplicationSession(), null, false, true); boolean batchStarted = sipContext.enterSipAppHa(true); try { getSipApplicationSession().setExpirationTimerTask(null); getSipApplicationSession().notifySipApplicationSessionListeners(SipApplicationSessionEventType.EXPIRATION); if(getDelay() <= 0) { getSipApplicationSession().setExpired(true); if(getSipApplicationSession().isValidInternal()) { getSipApplicationSession().invalidate(true); if(getSipApplicationSession().getExpirationTimerTask() != null) { logger.debug("expiration timer task is non null so the application has extended the session lifetime directly through setExpires"); sipContext.exitSipApp(getSipApplicationSession(), null); setSipApplicationSession(null);
@SuppressWarnings("unchecked") public void run() { try { if(logger.isDebugEnabled()) { logger.debug("initial kick off of SipApplicationSessionTimerTask running for sip application session " + sipApplicationSession.getId()); } long sleep = getDelay(); if(sleep > 0) { // if the session has been accessed since we started it, put it to sleep if(logger.isDebugEnabled()) { logger.debug("expirationTime is " + sipApplicationSession.getExpirationTimeInternal() + ", now is " + System.currentTimeMillis() + " sleeping for " + sleep / 1000L + " seconds"); } final SipContext sipContext = sipApplicationSession.getSipContext(); final SipApplicationSessionTimerTask expirationTimerTask = sipContext.getSipApplicationSessionTimerService().createSipApplicationSessionTimerTask(sipApplicationSession); sipApplicationSession.setExpirationTimerTask(expirationTimerTask); sipContext.getSipApplicationSessionTimerService().schedule(expirationTimerTask, sleep, TimeUnit.MILLISECONDS); } else { tryToExpire(); } } catch (Throwable t) { logger.error("Timer problem", t); } }
public SipApplicationSessionTimerTask schedule( SipApplicationSessionTimerTask expirationTimerTask, long delay, TimeUnit unit) { if(logger.isDebugEnabled()) { logger.debug("Scheduling sip application session "+ expirationTimerTask.getSipApplicationSession().getKey() +" to expire in " + (delay / (double) 1000 / (double) 60) + " minutes"); } ((DefaultSasTimerTask)expirationTimerTask).setScheduledFuture((ScheduledFuture<MobicentsSipApplicationSession>)super.schedule(expirationTimerTask, delay, unit)); return expirationTimerTask; }
public boolean cancel(SipApplicationSessionTimerTask expirationTimerTask) { //CANCEL needs to remove the shceduled timer see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6602600 //to improve perf ScheduledFuture<MobicentsSipApplicationSession> future = ((DefaultSasTimerTask)expirationTimerTask).getScheduledFuture(); if(future != null) { boolean removed = super.remove((Runnable) future); if(logger.isDebugEnabled()) { logger.debug("expiration timer on sip application session " + expirationTimerTask.getSipApplicationSession().getKey() + " removed : " + removed); } boolean cancelled = future.cancel(true); if(logger.isDebugEnabled()) { logger.debug("expiration timer on sip application session " + expirationTimerTask.getSipApplicationSession().getKey() + " Cancelled : " + cancelled); } future = null; // Purge is expensive when called frequently, only call it every now and then. // We do not sync the numCancelled variable. We dont care about correctness of // the number, and we will still call purge rought once on every 25 cancels. numCancelled++; if(numCancelled % 100 == 0) { super.purge(); } return cancelled; } else { if(logger.isDebugEnabled()) { logger.debug("expiration timer future is null, thus cannot be Cancelled"); } return false; } }