Skip to content

Instantly share code, notes, and snippets.

@farmdawgnation
Created July 13, 2017 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save farmdawgnation/f89a6dcc56e169c4b2bc45c159690eb3 to your computer and use it in GitHub Desktop.
Save farmdawgnation/f89a6dcc56e169c4b2bc45c159690eb3 to your computer and use it in GitHub Desktop.
Session resource registry example
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