/*
Returns an existing transport session for the resource address that can be reused

@return a reusable IoSession for the address
otherwise null
976584
IoSession take(HttpResourceAddress serverAddress) {
        IoSession transportSession = removeThreadAligned(serverAddress);
        if (transportSession != null) {
            // Got a cached persistent connection

            // Remove session idle tracking for this session
            transportSession.getConfig().setBothIdleTime(0);
            IoFilterChain filterChain = transportSession.getFilterChain();
            if (filterChain.contains(IDLE_FILTER)) {
                filterChain.remove(IDLE_FILTER);
            }

            // Remove our CloseFuture listener as it is out of pool
            CloseFuture closeFuture = transportSession.getCloseFuture();
            closeFuture.removeListener(closeListener);

            SERVER_ADDRESS.remove(transportSession);
        }

        return transportSession;
    }
127743
private synchronized HttpSubSession getSubSession() {
		HttpSession backingSession = super.getSession();
		Map<Integer, HttpSubSession> subsessions = (Map<Integer, HttpSubSession>) backingSession
				.getAttribute(SESSION_MAP_KEY);

		HttpSubSession subsession = subsessions.get(sessionId);
		subsession.setLastAccessedTime(System.currentTimeMillis());

		return subsession;
	}
945951
@Override
  public IGxSessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) {
    if (clazz.equals(ClientGxSession.class)) {
      ClientGxSessionDataReplicatedImpl data =
          new ClientGxSessionDataReplicatedImpl(sessionId, this.mobicentsCluster, this.replicatedSessionDataSource.getContainer());
      return data;
    }
    else if (clazz.equals(ServerGxSession.class)) {
      ServerGxSessionDataReplicatedImpl data = new ServerGxSessionDataReplicatedImpl(sessionId, this.mobicentsCluster);
      return data;
    }
    throw new IllegalArgumentException();
  }
298211
static ResourceAddress getLowestTransportLayer(ResourceAddress transport) {
        if (transport.getTransport() != null) {
            return getLowestTransportLayer(transport.getTransport());
        }
        return transport;
    }
108885
public HttpSessionImpl getSession(final String sessionId) {
        final SessionManager sessionManager = deployment.getSessionManager();
        Session session = sessionManager.getSession(sessionId);
        if (session != null) {
            return SecurityActions.forSession(session, this, false);
        }
        return null;
    }
707678
public SipApplicationSession getApplicationSession(boolean create) {
		if(logger.isDebugEnabled()) {
			logger.debug("getApplicationSession - create=" + create);
		}

		MobicentsSipApplicationSession sipApplicationSession = getSipApplicationSession(create);
		if(sipApplicationSession == null) {
			return null;
		} else {
			return sipApplicationSession.getFacade();
		}
	}
1260617
public SipApplicationSession getApplicationSession() {
		if(logger.isDebugEnabled()) {
			logger.debug("getApplicationSession");
		}

		MobicentsSipApplicationSession sipApplicationSession = getSipApplicationSession(true);
		if(sipApplicationSession == null) {
			if(logger.isDebugEnabled()) {
				logger.debug("getApplicationSession - sipApplicationSession is null");
			}
			return null;
		} else {
			return sipApplicationSession.getFacade();
		}
	}
967539
@Override
  public AppSession getNewSession(String sessionId, Class<? extends AppSession> aClass, ApplicationId applicationId, Object[] args) {
    try {
      // FIXME: add proper handling for SessionId
      if (aClass == ClientShSession.class) {
        ShClientSessionImpl clientSession = null;

        if (sessionId == null) {
          if (args != null && args.length > 0 && args[0] instanceof Request) {
            Request request = (Request) args[0];
            sessionId = request.getSessionId();
          }
          else {
            sessionId = this.sessionFactory.getSessionId();
          }
        }

        IShClientSessionData sessionData = (IShClientSessionData) this.sessionDataFactory.getAppSessionData(ClientShSession.class, sessionId);
        sessionData.setApplicationId(applicationId);
        clientSession = new ShClientSessionImpl(sessionData, this.getMessageFactory(), sessionFactory, this.getClientShSessionListener());
        sessionDataSource.addSession(clientSession);
        clientSession.getSessions().get(0).setRequestListener(clientSession);
        return clientSession;
      }
      else if (aClass == ServerShSession.class) {
        ShServerSessionImpl serverSession = null;

        if (sessionId == null) {
          if (args != null && args.length > 0 && args[0] instanceof Request) {
            Request request = (Request) args[0];
            sessionId = request.getSessionId();
          }
          else {
            sessionId = this.sessionFactory.getSessionId();
          }
        }
        IShServerSessionData sessionData = (IShServerSessionData) this.sessionDataFactory.getAppSessionData(ServerShSession.class, sessionId);
        sessionData.setApplicationId(applicationId);
        serverSession = new ShServerSessionImpl(sessionData, this.getMessageFactory(), sessionFactory, getServerShSessionListener());
        sessionDataSource.addSession(serverSession);
        serverSession.getSessions().get(0).setRequestListener(serverSession);
        return serverSession;
      }
      else {
        throw new IllegalArgumentException("Wrong session class: [" + aClass + "]. Supported[" + ClientShSession.class + "]");
      }
    }
    catch (IllegalArgumentException iae) {
      throw iae;
    }
    catch (Exception e) {
      logger.error("Failure to obtain new Sh Session.", e);
    }

    return null;
  }
1278522
@Override
    public BrowserSession createBrowserSession(SIDestinationAddress destinationAddress,
                                               DestinationType destinationType,
                                               SelectionCriteria criteria,
                                               String alternateUser)

                    throws SIConnectionDroppedException, SIConnectionUnavailableException, SITemporaryDestinationNotFoundException, SIErrorException, SIIncorrectCallException, SIResourceException, SINotPossibleInCurrentConfigurationException
    {
        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConnection.tc.isEntryEnabled())
            SibTr.entry(CoreSPIConnection.tc, "createBrowserSession",
                        new Object[] { this, destinationAddress, destinationType, criteria });

        // See if this connection has been closed
        checkNotClosed();
        // Check for null parameters    
        checkBrowserSessionNullParameters(destinationAddress);

        BrowserSession session = createBrowserSession(destinationAddress,
                                                      destinationType,
                                                      criteria,
                                                      false,
                                                      alternateUser,
                                                      false);

        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConnection.tc.isEntryEnabled())
            SibTr.exit(CoreSPIConnection.tc, "createBrowserSession", session);
        return session;
    }
371276
public Address getRemoteParty() {
		if(sessionCreatingDialog != null) {
			return new AddressImpl(sessionCreatingDialog.getRemoteParty(), null, ModifiableRule.NotModifiable);
		} else if (sessionCreatingTransactionRequest != null){
			try {
				if(!isSessionCreatingTransactionServer) {
					ToHeader toHeader = (ToHeader)sessionCreatingTransactionRequest.getMessage().getHeader(ToHeader.NAME);
					return new AddressImpl(toHeader.getAddress(), AddressImpl.getParameters((Parameters)toHeader),  ModifiableRule.NotModifiable);
				} else {
					FromHeader fromHeader = (FromHeader)sessionCreatingTransactionRequest.getMessage().getHeader(FromHeader.NAME);
					return new AddressImpl(fromHeader.getAddress(), AddressImpl.getParameters((Parameters)fromHeader),  ModifiableRule.NotModifiable);
				}
			} catch(Exception e) {
				throw new IllegalArgumentException("Error creating Address", e);
			}
		} else {
			return remoteParty;
		}
	}
886897
private Session getOrCreateSession(SessionId sessionId) {
    Session session = sessions.get(sessionId);
    if (session == null) {
      session = new LocalSession(sessionId, name(), type(), null, service.serializer());
      sessions.put(session.sessionId(), session);
      service.register(session);
    }
    return session;
  }
830058
@Override
    public Optional<Transport> getTransportParam() throws SipParseException {
        try {
            final Optional<Buffer> transport = getParameter(SipParser.TRANSPORT);
            return transport.map(Transport::of);
        } catch (final IllegalArgumentException e) {
            throw new SipParseException(0, e.getMessage(), e);
        }
    }
779752
@Override
    public HttpSession getSession() {
        try {
            collaborator.preInvoke(componentMetaData);
            return request.getSession();
        } finally {
            collaborator.postInvoke();
        }
    }
1142419
@Override
    public SICoreConnection getConnection() throws SISessionUnavailableException
    {
        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConsumerSession.tc.isEntryEnabled())
            SibTr.entry(CoreSPIConsumerSession.tc, "getConnection", this);

        checkNotClosed();

        if (TraceComponent.isAnyTracingEnabled() && CoreSPIConsumerSession.tc.isEntryEnabled())
            SibTr.exit(CoreSPIConsumerSession.tc, "getConnection", _connection);
        //Return the connection used to create this consumer session
        return _connection;
    }
1353355
private static String resolveIdentity(SocketAddress address, IoSessionEx session) {
        if (address instanceof ResourceAddress) {
            Subject subject = session.getSubject();
            if (subject == null) {
                subject = new Subject();
            }
            return resolveIdentity((ResourceAddress) address, subject);
        }
        return null;
    }
258655
public JingleSession getSession(String jid) {
        for (JingleSession jingleSession : jingleSessions) {
            if (jingleSession.getResponder().equals(jid)) {
                return jingleSession;
            }
        }
        return null;
    }
54341
public HttpSessionActivity getHttpSessionActivity(HttpSession httpSession)
			throws NullPointerException, IllegalArgumentException, IllegalStateException,
			ActivityAlreadyExistsException, StartActivityException,
			SLEEException {
		if (httpSession == null) {
			throw new NullPointerException("null http session");
		}
		if (!(httpSession instanceof HttpSessionWrapper)) {
			throw new IllegalArgumentException();
		}
		final HttpSessionWrapper httpSessionWrapper = (HttpSessionWrapper) httpSession;
		final HttpSessionActivityImpl activity = new HttpSessionActivityImpl(httpSessionWrapper);
		if (httpSessionWrapper.getResourceEntryPoint() == null) {
			ra.getSleeEndpoint().startActivitySuspended(activity,activity);
			httpSessionWrapper.setResourceEntryPoint(ra.getName());
		}
		return activity;
	}