public function find($id)
{
// return immediately if the requested session ID is empty
if (empty($id)) {
return;
}
// declare the session variable
$session = null;
// query whether or not the session with the passed ID exists
if ($this->getSessions()->exists($id)) {
$session = $this->getSessions()->get($id);
} else {
// iterate over the session handlers and try to un-persist the session
/** @var \AppserverIo\Appserver\ServletEngine\Session\SessionHandlerInterface $sessionHandler */
foreach ($this->getSessionHandlers() as $sessionHandler) {
try {
if ($session = $sessionHandler->load($id)) {
$this->attach($session);
break;
}
} catch (\Exception $e) {
// log the exception if a system logger is available
if ($logger = $this->getLogger(LoggerUtils::SYSTEM)) {
$logger->error($e->__toString());
}
}
}
}
// if we found a session, we've to check if it can be resumed
if ($session instanceof ServletSessionInterface) {
if ($session->canBeResumed()) {
$session->resume();
return $session;
}
}
}