Created
July 13, 2017 16:13
-
-
Save farmdawgnation/f89a6dcc56e169c4b2bc45c159690eb3 to your computer and use it in GitHub Desktop.
Session resource registry example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object SessionResourceRegistry { | |
/** map of session id's to closeables */ | |
private[this] val resources: ConcurrentHashMap[String, Seq[Closeable]] = new ConcurrentHashMap(); | |
def registerResource(sessionId: String, resource: Closeable): Unit = { | |
// add the resource to the hash map | |
} | |
def onSessionShutdown(session: LiftSession): Unit = { | |
val sessionId = session.uniqueId | |
Option(resources.get(sessionId)) match { | |
case None => //no resources, do nothing | |
case Some(resources) => | |
resources.foreach(_.close()) | |
resources.remove(sessionId) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment