	public void invalidate() {
		if(!isValid) {
			throw new IllegalStateException("SipApplicationSession already invalidated !");
		}
		if(logger.isInfoEnabled()) {
			logger.info("Invalidating the following sip application session " + key);
		}
		for(MobicentsSipSession session: sipSessions.values()) {
			if(session.isValid()) {
				session.invalidate();
			}
		}
		for(HttpSession session: httpSessions.values()) {
			if(((Session)session).isValid()) {
				session.invalidate();
			}
		}
		for (String key : sipApplicationSessionAttributeMap.keySet()) {
			removeAttribute(key);
		}
		notifySipApplicationSessionListeners(SipApplicationSessionEventType.DELETION);
		isValid = false;	
		for (Map.Entry<String, ServletTimer> servletTimerEntry : servletTimers.entrySet()) {
			ServletTimer timerEntry = servletTimerEntry.getValue();
			if(timerEntry != null) {
				timerEntry.cancel();				
			}
		}		
		if(!expired && expirationTimerFuture != null) {
			cancelExpirationTimer();
		}
        long timeNow = System.currentTimeMillis();
        int timeAlive = (int) ((timeNow - creationTime)/1000);
        SipManager manager = sipContext.getSipManager();
        synchronized (manager) {
            if (timeAlive > manager.getSipApplicationSessionMaxAliveTime()) {
                manager.setSipApplicationSessionMaxAliveTime(timeAlive);
            }
            int numExpired = manager.getExpiredSipApplicationSessions();
            numExpired++;
            manager.setExpiredSipApplicationSessions(numExpired);
            int average = manager.getSipApplicationSessionAverageAliveTime();
            average = ((average * (numExpired-1)) + timeAlive)/numExpired;
            manager.setSipApplicationSessionAverageAliveTime(average);
        }
		sipContext.getSipManager().removeSipApplicationSession(key);		
		expirationTimerTask = null;
		expirationTimerFuture = null;
		httpSessions.clear();
		servletTimers.clear();
		sipApplicationSessionAttributeMap.clear();
		sipSessions.clear();
		httpSessions.clear();
		executorService.shutdown();
		executorService = null;		
		httpSessions = null;
		sipSessions = null;
		sipApplicationSessionAttributeMap = null;
		servletTimers = null;
		sipContext = null;		
		if(logger.isInfoEnabled()) {
			logger.info("The following sip application session " + key + " has been invalidated");
		}
		currentRequestHandler = null;
		key = null;		
	}

	public void invalidate() {
		if(!isValid) {
			throw new IllegalStateException("SipApplicationSession already invalidated !");
		}
		if(logger.isInfoEnabled()) {
			logger.info("Invalidating the following sip application session " + key);
		}
		for(MobicentsSipSession session: sipSessions.values()) {
			if(session.isValid()) {
				session.invalidate();
			}
		}
		for(HttpSession session: httpSessions.values()) {
			try {
				session.invalidate();
			} catch(IllegalStateException ignore) {
			}
		}
		for (String key : sipApplicationSessionAttributeMap.keySet()) {
			removeAttribute(key);
		}
		notifySipApplicationSessionListeners(SipApplicationSessionEventType.DELETION);
		isValid = false;	
		for (Map.Entry<String, ServletTimer> servletTimerEntry : servletTimers.entrySet()) {
			ServletTimer timerEntry = servletTimerEntry.getValue();
			if(timerEntry != null) {
				timerEntry.cancel();				
			}
		}		
		if(!expired && expirationTimerFuture != null) {
			cancelExpirationTimer();
		}
        long timeNow = System.currentTimeMillis();
        int timeAlive = (int) ((timeNow - creationTime)/1000);
        SipManager manager = sipContext.getSipManager();
        synchronized (manager) {
            if (timeAlive > manager.getSipApplicationSessionMaxAliveTime()) {
                manager.setSipApplicationSessionMaxAliveTime(timeAlive);
            }
            int numExpired = manager.getExpiredSipApplicationSessions();
            numExpired++;
            manager.setExpiredSipApplicationSessions(numExpired);
            int average = manager.getSipApplicationSessionAverageAliveTime();
            average = ((average * (numExpired-1)) + timeAlive)/numExpired;
            manager.setSipApplicationSessionAverageAliveTime(average);
        }
		sipContext.getSipManager().removeSipApplicationSession(key);		
		expirationTimerTask = null;
		expirationTimerFuture = null;
		httpSessions.clear();
		servletTimers.clear();
		sipApplicationSessionAttributeMap.clear();
		sipSessions.clear();
		httpSessions.clear();
		executorService.shutdown();
		executorService = null;		
		httpSessions = null;
		sipSessions = null;
		sipApplicationSessionAttributeMap = null;
		servletTimers = null;
		sipContext = null;		
		if(logger.isInfoEnabled()) {
			logger.info("The following sip application session " + key + " has been invalidated");
		}
		currentRequestHandler = null;
		key = null;		
	}
