/* (non-Javadoc)
@see javax.servlet.sip.SipApplicationSessionActivationListener#sessionWillPassivate(javax.servlet.sip.SipApplicationSessionEvent)
11223
public void sessionWillPassivate(SipApplicationSessionEvent event) {
		logger.info("Following sip application session just passivated " + event.getApplicationSession().getId() + " cause " + ((SipApplicationSessionActivationEvent)event).getCause());

	}
716446
public void sessionReady(boolean isReady) {
	if (isReady) {
	    speedSlider.setValue(session.getClockPeriod());
	}
	startAction.setEnabled(isReady);
	speedSlider.setEnabled(isReady);
	stepAction.setEnabled(isReady);
	reloadAction.setEnabled(isReady);

    }
1355264
void sessionError(final SibRaMessagingEngineConnection connection,
            final ConsumerSession session, final Throwable throwable) {

        final String methodName = "sessionError";
        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.entry(this, TRACE, methodName, new Object[] { connection,
                    session });
        }

        final SIDestinationAddress destination = session
                .getDestinationAddress();

        if (_remoteDestination) {

            /*
             * Output a message to the admin console and attempt to create a new
             * listener
             */

            SibTr.warning(TRACE, "CONSUMER_FAILED_CWSIV0770", new Object[] {
                    destination.getDestinationName(),
                    _endpointConfiguration.getBusName(), this, throwable });

            try {

                createListener(connection);

            } catch (final ResourceException exception) {

                // No FFDC code needed

            }

        } else {

            if (SibRaEngineComponent.isMessagingEngineReloading(connection
                    .getConnection().getMeUuid())) {

                /*
                 * Output a warning to the admin console and close the
                 * connection - will be recreated during engineReloaded if
                 * required
                 */

                SibTr.warning(TRACE, "FAILURE_DURING_RELOAD_CWSIV0774",
                        new Object[] { throwable,
                                destination.getDestinationName(),
                                connection.getConnection().getMeName(),
                                destination.getBusName(), this });

                closeConnection(connection.getConnection().getMeUuid());

            } else {

                /*
                 * Output a message to the admin console and deactivate the
                 * endpoint
                 */

                SibTr.error(TRACE, "SESSION_ERROR_CWSIV0766", new Object[] {
                        throwable, destination.getDestinationName(),
                        connection.getConnection().getMeName(),
                        destination.getBusName(), this });

                deactivate();

            }

        }

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, methodName);
        }

    }
1358489
public void passivate() {
        // Notify ActivationListeners
    	SipSessionEvent event = null;
    	if(this.sipSessionAttributeMap != null) {
	        Set<String> keySet = getAttributeMap().keySet();
	        for (String key : keySet) {
	        	Object attribute = getAttributeMap().get(key);
	            if (attribute instanceof SipSessionActivationListener) {
	                if (event == null)
	                	event = new SipSessionActivationEvent(this, SessionActivationNotificationCause.PASSIVATION);
	                try {
	                    ((SipSessionActivationListener)attribute)
	                        .sessionWillPassivate(event);
	                } catch (Throwable t) {
	                    logger.error("SipSessionActivationListener threw exception", t);
	                }
	            }
			}
    	}
    }
470176
public SipApplicationSession getApplicationSessionByKey(String applicationSessionKey,
			boolean create, boolean isContainerManaged) {
		if(logger.isDebugEnabled()) {
			logger.debug("getApplicationSessionByKey - applicationSessionKey=" + applicationSessionKey);
		}
		
		if(applicationSessionKey == null) {
			throw new NullPointerException("the given key is null !");
		}
		SipApplicationSessionKey sipApplicationSessionKey = new SipApplicationSessionKey(null, sipContext.getApplicationName(), applicationSessionKey);
		
		MobicentsSipApplicationSession sipApplicationSession = sipContext.getSipManager().getSipApplicationSession(sipApplicationSessionKey, create);
		if(sipApplicationSession == null) {
			return null;
		} else {
			// make sure to acquire this app session and add it to the set of app sessions we monitor in the context of the application
			// to release them all when we exit application code
			sipContext.enterSipApp(sipApplicationSession, null, true, isContainerManaged);
			return sipApplicationSession.getFacade();
		}
	}
763177
public SipApplicationSession createApplicationSession(boolean managed) {
		MobicentsSipApplicationSession sipApplicationSessionImpl = null; 
		HttpSession httpSession = threadLocalHttpSession.get();
		// make sure we don't create a new sip app session if the http session has already one associated
		if(httpSession != null) {
			ConvergedSession convergedSession = (ConvergedSession) httpSession;
			sipApplicationSessionImpl = convergedSession.getApplicationSession(false);
		}
		if(sipApplicationSessionImpl == null) {
			sipApplicationSessionImpl =
				(MobicentsSipApplicationSession)sipFactoryImpl.createApplicationSessionByAppName(sipContext.getApplicationName(), managed);
			associateHttpSession(sipApplicationSessionImpl);
		}
		return sipApplicationSessionImpl;
	}
1141388
public void sessionIdle(IoSession session, IdleStatus status)
            throws Exception {
        SingleSessionIoHandler handler = (SingleSessionIoHandler) session
                .getAttribute(HANDLER);
        handler.sessionIdle(status);
    }
84282
public SipServletRequest createRequest(SipApplicationSession sipAppSession,
			String method, URI from, URI to, String handler) {
		if (logger.isDebugEnabled()) {
			logger
					.debug("Creating new SipServletRequest for SipApplicationSession["
							+ sipAppSession
							+ "] METHOD["
							+ method
							+ "] FROM_URI[" + from + "] TO_URI[" + to + "]");
		}

		validateCreation(method, sipAppSession);

		//javadoc specifies that a copy of the uri should be done hence the clone
		Address toA = this.createAddress(to.clone());
		Address fromA = this.createAddress(from.clone());

		try {
			return createSipServletRequest(sipAppSession, method, fromA, toA, handler, null, null);
		} catch (ServletParseException e) {
			logger.error("Error creating sipServletRequest", e);
			return null;
		}

	}
519648
public void sessionClosed(IoSession session) throws Exception {
        SingleSessionIoHandler handler = (SingleSessionIoHandler) session
                .getAttribute(HANDLER);
        handler.sessionClosed();
    }
23570
public void sessionDidActivate(SipApplicationSessionEvent event) {
		logger.info("Following sip application session just activated " + event.getApplicationSession().getId() + " cause " + ((SipApplicationSessionActivationEvent)event).getCause());
		if(((SipApplicationSessionActivationEvent)event).getCause() == SessionActivationNotificationCause.FAILOVER) {
			event.getApplicationSession().setAttribute(SIP_APPLICATION_SESSION_ACTIVATED, "true" );
		}

	}
1251767
public void setHandler(String name) throws ServletException {
		if(!isValid()) {
			throw new IllegalStateException("the session has already been invalidated, no handler can be set on it anymore !");
		}
		if(name != null && name.equals(handlerServlet)) {
			return ;
		}
		SipContext sipContext = getSipApplicationSession().getSipContext();
		MobicentsSipServlet container = sipContext.findSipServletByName(name);

		if(container == null && sipContext.getSipRubyController() == null) {
			throw new ServletException("the sip servlet with the name "+ name +
					" doesn't exist in the sip application " + sipContext.getApplicationName());
		}
		this.handlerServlet = name;
		getSipApplicationSession().setCurrentRequestHandler(handlerServlet);
		if(logger.isDebugEnabled()) {
			if(name !=null) {
				logger.debug("Session Handler for application " + getKey().getApplicationName() + " set to " + handlerServlet + " on sip session " + key);
			} else {
				logger.debug("Session Handler for application " + getKey().getApplicationName() + " set to " + sipContext.getSipRubyController() + " on sip session " + key);
			}
		}
	}
1224185
public void sessionCreated(HttpSessionEvent event) {
    if (null == eventMulticaster) {
      eventMulticaster = Containers.getRoot().getBean(EventMulticaster.class).get();
      Assert.notNull(eventMulticaster);
    }
    eventMulticaster.multicast(new HttpSessionCreationEvent(event.getSession()));
  }
20655
public void addHttpSession(HttpSession session) {
		synchronized (this.sessions) {
			this.sessions.add(session);
		}
		this.model.addHttpSession(session);
	}
38988
@Override
    public void setBypassProxy(boolean bypassProxy) {
    	if(logger.isDebugEnabled()) {
			logger.debug("setting bypassProxy: " + bypassProxy + " on the sip session " + key);
		}
        this.bypassProxy = bypassProxy;
    }
338409
public void sessionCreated(ISession session) {
        HttpSession httpsession = (HttpSessionImpl) _adapter.adapt(session);
        HttpSessionEvent event = new HttpSessionEvent(httpsession);
        HttpSessionListener listener = null;

        // synchronized (_sessionListeners) {
        for (int i = 0; i < _sessionListeners.size(); i++) {
            listener = (HttpSessionListener) _sessionListeners.get(i);
            if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINE)) {
                LoggingUtil.SESSION_LOGGER_CORE.logp(Level.FINE, methodClassName, "sessionCreated", "Calling sessionCreated on listener:" + listener);
            }
            if (!session.isOverflow()) { //PK85530
                listener.sessionCreated(event);
            }
        }
        // }

    }
341902
public SipSession getSipSession(String id) {
		if(!isValid()) {
			throw new IllegalStateException("SipApplicationSession already invalidated !");
		}
		if(logger.isDebugEnabled()) {
			logger.debug("Trying to find a session with the id " + id);
			dumpSipSessions();
		}
		boolean isPresent = false;
		SipSessionKey sipSessionKey = null;
		try {
			sipSessionKey = SessionManagerUtil.parseSipSessionKey(id);
			isPresent = sipSessions.contains(sipSessionKey);
		} catch (ParseException e) {
			//can happen if the id passed is invalid
		}
		if(isPresent) {
			return sipContext.getSipManager().getSipSession(sipSessionKey, false, null, this).getFacade();
		} else {
			return null;
		}
	}
242527
public void activate() {
        // Notify ActivationListeners
    	SipApplicationSessionEvent event = null;
    	if(sipApplicationSessionAttributeMap != null) {
	        Set<String> keySet = sipApplicationSessionAttributeMap.keySet();
	        for (String key : keySet) {
	        	Object attribute = sipApplicationSessionAttributeMap.get(key);
	            if (attribute instanceof SipApplicationSessionActivationListener) {
	                if (event == null)
	                	event = new SipApplicationSessionActivationEvent(this, SessionActivationNotificationCause.ACTIVATION);
	                try {
	                    ((SipApplicationSessionActivationListener)attribute)
	                        .sessionDidActivate(event);
	                } catch (Throwable t) {
	                    logger.error("SipApplicationSessionActivationListener threw exception", t);
	                }
	            }
			}
	    }
    }