[Lift] Re: Need access to session variables when about to shut down a session.
David, I'm a little confused by how to use registerCleanupFunc after your most recent set of changes. It now appears to be package-private, so what is the recommended way to register a cleanup func for a RequestVar? Previously, I'd implemented my JNDIResource class for use with the JPA stuff like this: object JNDIResource { val context = new InitialContext() } abstract class JNDIResource[T](val name: String) extends RequestVar[T](context.lookup(name).asInstanceOf[T]) { // This is way too dependent upon an implementation detail of the superclass. override def cleanupFunc : Box[() = Unit] = { Log.debug(Initializing JNDI resource + name + ( + this.is + )) initialize(this.is) //this will result in a recursive call, but the the order of operations is such that it will take the other branch. Full(() = { Log.debug(Releasing JNDI resource + name + ( + this.is + )) dispose(this.is) }) } /** * Subclasses should override this method to provide initialization */ protected def initialize(resource : T) { } /** * Subclasses should override this method to provide initialization */ protected def dispose(resource: T) { } } Using the cleanupFunc like this was of course a complete hack to add the ability to do additional delgated initialization to the variable retrieved from the JNDI context. I can handle the initialization part by overriding setFunc in my new implementation, but how can I set up the delegation to dispose? Thanks, Kris On Feb 4, 11:56 pm, David Pollak feeder.of.the.be...@gmail.com wrote: I've just realized that I'm a complete idiot. I need to totally re-do the clean-up mechanism. Please give me an hour. On Wed, Feb 4, 2009 at 3:06 PM, Kris Nuttycombe kris.nuttyco...@gmail.comwrote: Heh, this one just bit me too. I can't say I didn't warn myself, though: // This is way too dependent upon an implementation detail of the superclass. override def cleanupFunc : Box[() = Unit] = { ... } Kris On Wed, Feb 4, 2009 at 1:47 PM, David Pollak feeder.of.the.be...@gmail.com wrote: That's because cleanUpFunc is gone. You must do: object sessDirHash extends SessionVar[String]() { registerCleanupFunc(session = println(Got hash: + this.is)) } On Wed, Feb 4, 2009 at 12:43 PM, Alli allilis...@gmail.com wrote: Hey David, Two questions this time: I've been playing with your commit earlier today and cleaning up SessionVar's. I got: object sessDirHash extends SessionVar[String]() { def cleanUpFunc(sess: LiftSession) = { println(Got hash: + this.is) } In my test snippet I got: sessDirHash(this is a test) println(Got var: + ResizeMyPics.sessDirHash.is) I can see it printed out correctly after setting it but it's empty in the cleanup function. 2) Second question, I submit a form and my flash component starts e.g. 3 new sessions and POST's to /resize /resize sets a SessionVar variable but it's like it's only being set the first time. I'm printing out right before I register the clean up handler in the SessionVar, from my jetty logs: INFO - Service request (GET) /images/cancelbutton.gif took 9 Milliseconds Rez Gots: 127.0.0.1 Registering cleanup for: 1uvl5176sdy9r Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 270 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 91 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 481 Milliseconds I would think it should print out Registering cleanup handler ... after each /resize request since they are different sessions. Then the sessions all timeout and I can see there are 4 sessions expiring but there is only message printed out once from the clean up handler. What are your thoughts on this? Cheers, Alfred On Feb 4, 1:19 am, Alli allilis...@gmail.com wrote: Thanks David, I'll get it tomorrow from scala-tools.org and finish up the app. URL will behttp://www.resizemypics.netafree service for people to resize their pictures and view them online. Just a simple, yet convenient service. Gives me a chance to learn more about lift as well. Been following lift for a while but this is the first site I finish, have a half finished blog site in lift. Doing all this stuff outside of work so it's easy to get distracted. Will let you know once the site is in production. Again thanks for your help. Cheers, Alli On Feb 4, 1:12 am, David Pollak feeder.of.the.be...@gmail.com wrote: 0.11-SNAPSHOT is 0.10 with bug fixes. It's very stable and will be 1.0 on 2/26. I'll commit up a fix to this problem in a few minutes. Also, what's the URL of the site? :-) On Tue, Feb 3,
[Lift] Re: Need access to session variables when about to shut down a session.
Just to clarify, the use case for this post-assignment initialization is this: object EM extends JNDIResource[EntityManager](java:comp/env/persistence/em) with ScalaEntityManager { object t extends JNDIResource[UserTransaction](java:comp/UserTransaction) override protected def initialize(em : EntityManager) = t.is.begin() override protected def dispose(em : EntityManager) = t.is.commit() override def em = this.is } On Thu, Feb 5, 2009 at 1:13 PM, Kris Nuttycombe kris.nuttyco...@gmail.comwrote: David, I'm a little confused by how to use registerCleanupFunc after your most recent set of changes. It now appears to be package-private, so what is the recommended way to register a cleanup func for a RequestVar? Previously, I'd implemented my JNDIResource class for use with the JPA stuff like this: object JNDIResource { val context = new InitialContext() } abstract class JNDIResource[T](val name: String) extends RequestVar[T](context.lookup(name).asInstanceOf[T]) { // This is way too dependent upon an implementation detail of the superclass. override def cleanupFunc : Box[() = Unit] = { Log.debug(Initializing JNDI resource + name + ( + this.is + )) initialize(this.is) //this will result in a recursive call, but the the order of operations is such that it will take the other branch. Full(() = { Log.debug(Releasing JNDI resource + name + ( + this.is + )) dispose(this.is) }) } /** * Subclasses should override this method to provide initialization */ protected def initialize(resource : T) { } /** * Subclasses should override this method to provide initialization */ protected def dispose(resource: T) { } } Using the cleanupFunc like this was of course a complete hack to add the ability to do additional delgated initialization to the variable retrieved from the JNDI context. I can handle the initialization part by overriding setFunc in my new implementation, but how can I set up the delegation to dispose? Thanks, Kris On Feb 4, 11:56 pm, David Pollak feeder.of.the.be...@gmail.com wrote: I've just realized that I'm a complete idiot. I need to totally re-do the clean-up mechanism. Please give me an hour. On Wed, Feb 4, 2009 at 3:06 PM, Kris Nuttycombe kris.nuttyco...@gmail.comwrote: Heh, this one just bit me too. I can't say I didn't warn myself, though: // This is way too dependent upon an implementation detail of the superclass. override def cleanupFunc : Box[() = Unit] = { ... } Kris On Wed, Feb 4, 2009 at 1:47 PM, David Pollak feeder.of.the.be...@gmail.com wrote: That's because cleanUpFunc is gone. You must do: object sessDirHash extends SessionVar[String]() { registerCleanupFunc(session = println(Got hash: + this.is)) } On Wed, Feb 4, 2009 at 12:43 PM, Alli allilis...@gmail.com wrote: Hey David, Two questions this time: I've been playing with your commit earlier today and cleaning up SessionVar's. I got: object sessDirHash extends SessionVar[String]() { def cleanUpFunc(sess: LiftSession) = { println(Got hash: + this.is) } In my test snippet I got: sessDirHash(this is a test) println(Got var: + ResizeMyPics.sessDirHash.is) I can see it printed out correctly after setting it but it's empty in the cleanup function. 2) Second question, I submit a form and my flash component starts e.g. 3 new sessions and POST's to /resize /resize sets a SessionVar variable but it's like it's only being set the first time. I'm printing out right before I register the clean up handler in the SessionVar, from my jetty logs: INFO - Service request (GET) /images/cancelbutton.gif took 9 Milliseconds Rez Gots: 127.0.0.1 Registering cleanup for: 1uvl5176sdy9r Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 270 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 91 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 481 Milliseconds I would think it should print out Registering cleanup handler ... after each /resize request since they are different sessions. Then the sessions all timeout and I can see there are 4 sessions expiring but there is only message printed out once from the clean up handler. What are your thoughts on this? Cheers, Alfred On Feb 4, 1:19 am, Alli allilis...@gmail.com wrote: Thanks David, I'll get it tomorrow from scala-tools.org and finish up the app. URL will behttp://www.resizemypics.netafree service for people to resize their pictures and view them online. Just a simple, yet convenient service. Gives me a chance to learn more about lift as well. Been following lift for a while but this is the
[Lift] Re: Need access to session variables when about to shut down a session.
On Thu, Feb 5, 2009 at 12:13 PM, Kris Nuttycombe kris.nuttyco...@gmail.comwrote: David, I'm a little confused by how to use registerCleanupFunc after your most recent set of changes. It now appears to be package-private, so what is the recommended way to register a cleanup func for a RequestVar? Previously, I'd implemented my JNDIResource class for use with the JPA stuff like this: object JNDIResource { val context = new InitialContext() } abstract class JNDIResource[T](val name: String) extends RequestVar[T](context.lookup(name).asInstanceOf[T]) { The onShutdown method will always be called: override protected def onShutdown(session: CleanUpParam): Unit = { dispose(this.is) } If you are putting something in the RequestVar that needs cleanup, you should register the cleanup method on the session: S.session.foreach(_.addSessionCleanup(session = cleanup)) // This is way too dependent upon an implementation detail of the superclass. override def cleanupFunc : Box[() = Unit] = { Log.debug(Initializing JNDI resource + name + ( + this.is + )) initialize(this.is) //this will result in a recursive call, but the the order of operations is such that it will take the other branch. Full(() = { Log.debug(Releasing JNDI resource + name + ( + this.is + )) dispose(this.is) }) } /** * Subclasses should override this method to provide initialization */ protected def initialize(resource : T) { } /** * Subclasses should override this method to provide initialization */ protected def dispose(resource: T) { } } Using the cleanupFunc like this was of course a complete hack to add the ability to do additional delgated initialization to the variable retrieved from the JNDI context. I can handle the initialization part by overriding setFunc in my new implementation, but how can I set up the delegation to dispose? Thanks, Kris On Feb 4, 11:56 pm, David Pollak feeder.of.the.be...@gmail.com wrote: I've just realized that I'm a complete idiot. I need to totally re-do the clean-up mechanism. Please give me an hour. On Wed, Feb 4, 2009 at 3:06 PM, Kris Nuttycombe kris.nuttyco...@gmail.comwrote: Heh, this one just bit me too. I can't say I didn't warn myself, though: // This is way too dependent upon an implementation detail of the superclass. override def cleanupFunc : Box[() = Unit] = { ... } Kris On Wed, Feb 4, 2009 at 1:47 PM, David Pollak feeder.of.the.be...@gmail.com wrote: That's because cleanUpFunc is gone. You must do: object sessDirHash extends SessionVar[String]() { registerCleanupFunc(session = println(Got hash: + this.is)) } On Wed, Feb 4, 2009 at 12:43 PM, Alli allilis...@gmail.com wrote: Hey David, Two questions this time: I've been playing with your commit earlier today and cleaning up SessionVar's. I got: object sessDirHash extends SessionVar[String]() { def cleanUpFunc(sess: LiftSession) = { println(Got hash: + this.is) } In my test snippet I got: sessDirHash(this is a test) println(Got var: + ResizeMyPics.sessDirHash.is) I can see it printed out correctly after setting it but it's empty in the cleanup function. 2) Second question, I submit a form and my flash component starts e.g. 3 new sessions and POST's to /resize /resize sets a SessionVar variable but it's like it's only being set the first time. I'm printing out right before I register the clean up handler in the SessionVar, from my jetty logs: INFO - Service request (GET) /images/cancelbutton.gif took 9 Milliseconds Rez Gots: 127.0.0.1 Registering cleanup for: 1uvl5176sdy9r Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 270 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 91 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 481 Milliseconds I would think it should print out Registering cleanup handler ... after each /resize request since they are different sessions. Then the sessions all timeout and I can see there are 4 sessions expiring but there is only message printed out once from the clean up handler. What are your thoughts on this? Cheers, Alfred On Feb 4, 1:19 am, Alli allilis...@gmail.com wrote: Thanks David, I'll get it tomorrow from scala-tools.org and finish up the app. URL will behttp://www.resizemypics.netafree service for people to resize their pictures and view them online. Just a simple, yet convenient service. Gives me a chance to learn more about lift as well. Been following lift for a while but this is the first site I finish, have a half finished blog site in lift. Doing all this stuff outside of work
[Lift] Re: Need access to session variables when about to shut down a session.
On Thu, Feb 5, 2009 at 1:43 PM, David Pollak feeder.of.the.be...@gmail.comwrote: On Thu, Feb 5, 2009 at 12:13 PM, Kris Nuttycombe kris.nuttyco...@gmail.com wrote: David, I'm a little confused by how to use registerCleanupFunc after your most recent set of changes. It now appears to be package-private, so what is the recommended way to register a cleanup func for a RequestVar? Previously, I'd implemented my JNDIResource class for use with the JPA stuff like this: object JNDIResource { val context = new InitialContext() } abstract class JNDIResource[T](val name: String) extends RequestVar[T](context.lookup(name).asInstanceOf[T]) { The onShutdown method will always be called: override protected def onShutdown(session: CleanUpParam): Unit = { dispose(this.is) } If you are putting something in the RequestVar that needs cleanup, you should register the cleanup method on the session: S.session.foreach(_.addSessionCleanup(session = cleanup)) I don't think I understand this - will the RequestVar onShutdown hook get not called at the end of the processing of each HTTP request? Thanks, Kris // This is way too dependent upon an implementation detail of the superclass. override def cleanupFunc : Box[() = Unit] = { Log.debug(Initializing JNDI resource + name + ( + this.is + )) initialize(this.is) //this will result in a recursive call, but the the order of operations is such that it will take the other branch. Full(() = { Log.debug(Releasing JNDI resource + name + ( + this.is + )) dispose(this.is) }) } /** * Subclasses should override this method to provide initialization */ protected def initialize(resource : T) { } /** * Subclasses should override this method to provide initialization */ protected def dispose(resource: T) { } } Using the cleanupFunc like this was of course a complete hack to add the ability to do additional delgated initialization to the variable retrieved from the JNDI context. I can handle the initialization part by overriding setFunc in my new implementation, but how can I set up the delegation to dispose? Thanks, Kris --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Need access to session variables when about to shut down a session.
This works now smoothly. On Feb 5, 8:50 pm, Kris Nuttycombe kris.nuttyco...@gmail.com wrote: On Thu, Feb 5, 2009 at 1:43 PM, David Pollak feeder.of.the.be...@gmail.comwrote: On Thu, Feb 5, 2009 at 12:13 PM, Kris Nuttycombe kris.nuttyco...@gmail.com wrote: David, I'm a little confused by how to use registerCleanupFunc after your most recent set of changes. It now appears to be package-private, so what is the recommended way to register a cleanup func for a RequestVar? Previously, I'd implemented my JNDIResource class for use with the JPA stuff like this: object JNDIResource { val context = new InitialContext() } abstract class JNDIResource[T](val name: String) extends RequestVar[T](context.lookup(name).asInstanceOf[T]) { The onShutdown method will always be called: override protected def onShutdown(session: CleanUpParam): Unit = { dispose(this.is) } If you are putting something in the RequestVar that needs cleanup, you should register the cleanup method on the session: S.session.foreach(_.addSessionCleanup(session = cleanup)) I don't think I understand this - will the RequestVar onShutdown hook get not called at the end of the processing of each HTTP request? Thanks, Kris // This is way too dependent upon an implementation detail of the superclass. override def cleanupFunc : Box[() = Unit] = { Log.debug(Initializing JNDI resource + name + ( + this.is + )) initialize(this.is) //this will result in a recursive call, but the the order of operations is such that it will take the other branch. Full(() = { Log.debug(Releasing JNDI resource + name + ( + this.is + )) dispose(this.is) }) } /** * Subclasses should override this method to provide initialization */ protected def initialize(resource : T) { } /** * Subclasses should override this method to provide initialization */ protected def dispose(resource: T) { } } Using the cleanupFunc like this was of course a complete hack to add the ability to do additional delgated initialization to the variable retrieved from the JNDI context. I can handle the initialization part by overriding setFunc in my new implementation, but how can I set up the delegation to dispose? Thanks, Kris --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Need access to session variables when about to shut down a session.
Hey David, Two questions this time: I've been playing with your commit earlier today and cleaning up SessionVar's. I got: object sessDirHash extends SessionVar[String]() { def cleanUpFunc(sess: LiftSession) = { println(Got hash: + this.is) } In my test snippet I got: sessDirHash(this is a test) println(Got var: + ResizeMyPics.sessDirHash.is) I can see it printed out correctly after setting it but it's empty in the cleanup function. 2) Second question, I submit a form and my flash component starts e.g. 3 new sessions and POST's to /resize /resize sets a SessionVar variable but it's like it's only being set the first time. I'm printing out right before I register the clean up handler in the SessionVar, from my jetty logs: INFO - Service request (GET) /images/cancelbutton.gif took 9 Milliseconds Rez Gots: 127.0.0.1 Registering cleanup for: 1uvl5176sdy9r Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 270 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 91 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 481 Milliseconds I would think it should print out Registering cleanup handler ... after each /resize request since they are different sessions. Then the sessions all timeout and I can see there are 4 sessions expiring but there is only message printed out once from the clean up handler. What are your thoughts on this? Cheers, Alfred On Feb 4, 1:19 am, Alli allilis...@gmail.com wrote: Thanks David, I'll get it tomorrow from scala-tools.org and finish up the app. URL will behttp://www.resizemypics.neta free service for people to resize their pictures and view them online. Just a simple, yet convenient service. Gives me a chance to learn more about lift as well. Been following lift for a while but this is the first site I finish, have a half finished blog site in lift. Doing all this stuff outside of work so it's easy to get distracted. Will let you know once the site is in production. Again thanks for your help. Cheers, Alli On Feb 4, 1:12 am, David Pollak feeder.of.the.be...@gmail.com wrote: 0.11-SNAPSHOT is 0.10 with bug fixes. It's very stable and will be 1.0 on 2/26. I'll commit up a fix to this problem in a few minutes. Also, what's the URL of the site? :-) On Tue, Feb 3, 2009 at 4:58 PM, Alli allilis...@gmail.com wrote: 0.10 at the moment, reckon i should upgrade to 0.11? This site is going live soon though and I was not sure about the status of 0.11-snapshot. On Feb 4, 12:56 am, David Pollak feeder.of.the.be...@gmail.com wrote: Crud. It looks like the session cleanup is done outside of the session scope. Are you using 0.11-SNAPSHOT? On Tue, Feb 3, 2009 at 4:35 PM, Alli allilis...@gmail.com wrote: Been testing this stuff and my object is like this: object ReportAddress extends SessionVar[String]() { def cleanUp() = { println(S.session) S.session.map { sess = println(Session ID: + sess.uniqueId) println(REM ADDRESS: + this.is) val tempDir = ... // Remove the temporary dir for this session. tempDir.destroy() } } registerCleanupFunc(cleanUp _) } println(S.session) always gives me Empty Any idea what could cause this? On Feb 3, 10:38 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 2:13 PM, Alli allilis...@gmail.com wrote: Makes a lot of sense, thanks David. Always amazes me how good and clean the design of lift is. Flattery will get you a lot... :-) On Feb 3, 9:49 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 1:06 PM, Alli allilis...@gmail.com wrote: Evening, During the lifetime of a session, the session may have uploaded bunch of files and these need to be able to be destroyed/unlinked when a session ends. When user uploads a file it's parent dir is determined by the session unique ID and the remote address of the uploader. The name is e.g. / tmp/sha1 hash of session id and remote address'. This means in order to determine what to destroy I need to know what remote address the session belongs to. I am setting that when uploading a file has been uploaded successfully. In Boot.scala I want to do something like: // Set session handler. LiftSession.onAboutToShutdownSession = List[LiftSession = Unit]( session = { var sessId = session.uniqueId val remoteIp = session.get(remoteAddress) val myTempDir = new TempDirWeb(sessId, remoteIp) myTempDir.unlinkall() })
[Lift] Re: Need access to session variables when about to shut down a session.
That's because cleanUpFunc is gone. You must do: object sessDirHash extends SessionVar[String]() { registerCleanupFunc(session = println(Got hash: + this.is)) } On Wed, Feb 4, 2009 at 12:43 PM, Alli allilis...@gmail.com wrote: Hey David, Two questions this time: I've been playing with your commit earlier today and cleaning up SessionVar's. I got: object sessDirHash extends SessionVar[String]() { def cleanUpFunc(sess: LiftSession) = { println(Got hash: + this.is) } In my test snippet I got: sessDirHash(this is a test) println(Got var: + ResizeMyPics.sessDirHash.is) I can see it printed out correctly after setting it but it's empty in the cleanup function. 2) Second question, I submit a form and my flash component starts e.g. 3 new sessions and POST's to /resize /resize sets a SessionVar variable but it's like it's only being set the first time. I'm printing out right before I register the clean up handler in the SessionVar, from my jetty logs: INFO - Service request (GET) /images/cancelbutton.gif took 9 Milliseconds Rez Gots: 127.0.0.1 Registering cleanup for: 1uvl5176sdy9r Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 270 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 91 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 481 Milliseconds I would think it should print out Registering cleanup handler ... after each /resize request since they are different sessions. Then the sessions all timeout and I can see there are 4 sessions expiring but there is only message printed out once from the clean up handler. What are your thoughts on this? Cheers, Alfred On Feb 4, 1:19 am, Alli allilis...@gmail.com wrote: Thanks David, I'll get it tomorrow from scala-tools.org and finish up the app. URL will behttp://www.resizemypics.neta free service for people to resize their pictures and view them online. Just a simple, yet convenient service. Gives me a chance to learn more about lift as well. Been following lift for a while but this is the first site I finish, have a half finished blog site in lift. Doing all this stuff outside of work so it's easy to get distracted. Will let you know once the site is in production. Again thanks for your help. Cheers, Alli On Feb 4, 1:12 am, David Pollak feeder.of.the.be...@gmail.com wrote: 0.11-SNAPSHOT is 0.10 with bug fixes. It's very stable and will be 1.0 on 2/26. I'll commit up a fix to this problem in a few minutes. Also, what's the URL of the site? :-) On Tue, Feb 3, 2009 at 4:58 PM, Alli allilis...@gmail.com wrote: 0.10 at the moment, reckon i should upgrade to 0.11? This site is going live soon though and I was not sure about the status of 0.11-snapshot. On Feb 4, 12:56 am, David Pollak feeder.of.the.be...@gmail.com wrote: Crud. It looks like the session cleanup is done outside of the session scope. Are you using 0.11-SNAPSHOT? On Tue, Feb 3, 2009 at 4:35 PM, Alli allilis...@gmail.com wrote: Been testing this stuff and my object is like this: object ReportAddress extends SessionVar[String]() { def cleanUp() = { println(S.session) S.session.map { sess = println(Session ID: + sess.uniqueId) println(REM ADDRESS: + this.is) val tempDir = ... // Remove the temporary dir for this session. tempDir.destroy() } } registerCleanupFunc(cleanUp _) } println(S.session) always gives me Empty Any idea what could cause this? On Feb 3, 10:38 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 2:13 PM, Alli allilis...@gmail.com wrote: Makes a lot of sense, thanks David. Always amazes me how good and clean the design of lift is. Flattery will get you a lot... :-) On Feb 3, 9:49 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 1:06 PM, Alli allilis...@gmail.com wrote: Evening, During the lifetime of a session, the session may have uploaded bunch of files and these need to be able to be destroyed/unlinked when a session ends. When user uploads a file it's parent dir is determined by the session unique ID and the remote address of the uploader. The name is e.g. / tmp/sha1 hash of session id and remote address'. This means in order to determine what to destroy I need to know what remote address the session belongs to. I am setting that when uploading a file has been uploaded successfully. In Boot.scala I want to do something like: // Set session handler.
[Lift] Re: Need access to session variables when about to shut down a session.
Sorry, for some reason the whole stuff i copy/pasted didn't get in: object sessDirHash extends SessionVar[String]() { def cleanUpFunc(sess: LiftSession) = { println(Got hash: + this.is) registerCleanUpFunc(cleanUpFunc _) } Anyway I changed it to this: object sessDirHash extends SessionVar[String]() { def cleanUpFunc(sess: LiftSession) = { println(Got hash: + this.is) } registerCleanupFunc(session = println(Got hash: + this.is)) } This is what I get afterwards: INFO - Session kps4gk1dz4n4 expired INFO - Session 1qxs8vlro53pw expired Got hash: There may or may not be something i'm doing wrong On Feb 4, 8:47 pm, David Pollak feeder.of.the.be...@gmail.com wrote: That's because cleanUpFunc is gone. You must do: object sessDirHash extends SessionVar[String]() { registerCleanupFunc(session = println(Got hash: + this.is)) } On Wed, Feb 4, 2009 at 12:43 PM, Alli allilis...@gmail.com wrote: Hey David, Two questions this time: I've been playing with your commit earlier today and cleaning up SessionVar's. I got: object sessDirHash extends SessionVar[String]() { def cleanUpFunc(sess: LiftSession) = { println(Got hash: + this.is) } In my test snippet I got: sessDirHash(this is a test) println(Got var: + ResizeMyPics.sessDirHash.is) I can see it printed out correctly after setting it but it's empty in the cleanup function. 2) Second question, I submit a form and my flash component starts e.g. 3 new sessions and POST's to /resize /resize sets a SessionVar variable but it's like it's only being set the first time. I'm printing out right before I register the clean up handler in the SessionVar, from my jetty logs: INFO - Service request (GET) /images/cancelbutton.gif took 9 Milliseconds Rez Gots: 127.0.0.1 Registering cleanup for: 1uvl5176sdy9r Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 270 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 91 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 481 Milliseconds I would think it should print out Registering cleanup handler ... after each /resize request since they are different sessions. Then the sessions all timeout and I can see there are 4 sessions expiring but there is only message printed out once from the clean up handler. What are your thoughts on this? Cheers, Alfred On Feb 4, 1:19 am, Alli allilis...@gmail.com wrote: Thanks David, I'll get it tomorrow from scala-tools.org and finish up the app. URL will behttp://www.resizemypics.netafree service for people to resize their pictures and view them online. Just a simple, yet convenient service. Gives me a chance to learn more about lift as well. Been following lift for a while but this is the first site I finish, have a half finished blog site in lift. Doing all this stuff outside of work so it's easy to get distracted. Will let you know once the site is in production. Again thanks for your help. Cheers, Alli On Feb 4, 1:12 am, David Pollak feeder.of.the.be...@gmail.com wrote: 0.11-SNAPSHOT is 0.10 with bug fixes. It's very stable and will be 1.0 on 2/26. I'll commit up a fix to this problem in a few minutes. Also, what's the URL of the site? :-) On Tue, Feb 3, 2009 at 4:58 PM, Alli allilis...@gmail.com wrote: 0.10 at the moment, reckon i should upgrade to 0.11? This site is going live soon though and I was not sure about the status of 0.11-snapshot. On Feb 4, 12:56 am, David Pollak feeder.of.the.be...@gmail.com wrote: Crud. It looks like the session cleanup is done outside of the session scope. Are you using 0.11-SNAPSHOT? On Tue, Feb 3, 2009 at 4:35 PM, Alli allilis...@gmail.com wrote: Been testing this stuff and my object is like this: object ReportAddress extends SessionVar[String]() { def cleanUp() = { println(S.session) S.session.map { sess = println(Session ID: + sess.uniqueId) println(REM ADDRESS: + this.is) val tempDir = ... // Remove the temporary dir for this session. tempDir.destroy() } } registerCleanupFunc(cleanUp _) } println(S.session) always gives me Empty Any idea what could cause this? On Feb 3, 10:38 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 2:13 PM, Alli allilis...@gmail.com wrote: Makes a lot of sense, thanks David. Always amazes me how good and clean the design of lift is. Flattery will get you a lot... :-) On Feb 3, 9:49 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 1:06 PM, Alli allilis...@gmail.com
[Lift] Re: Need access to session variables when about to shut down a session.
Heh, this one just bit me too. I can't say I didn't warn myself, though: // This is way too dependent upon an implementation detail of the superclass. override def cleanupFunc : Box[() = Unit] = { ... } Kris On Wed, Feb 4, 2009 at 1:47 PM, David Pollak feeder.of.the.be...@gmail.comwrote: That's because cleanUpFunc is gone. You must do: object sessDirHash extends SessionVar[String]() { registerCleanupFunc(session = println(Got hash: + this.is)) } On Wed, Feb 4, 2009 at 12:43 PM, Alli allilis...@gmail.com wrote: Hey David, Two questions this time: I've been playing with your commit earlier today and cleaning up SessionVar's. I got: object sessDirHash extends SessionVar[String]() { def cleanUpFunc(sess: LiftSession) = { println(Got hash: + this.is) } In my test snippet I got: sessDirHash(this is a test) println(Got var: + ResizeMyPics.sessDirHash.is) I can see it printed out correctly after setting it but it's empty in the cleanup function. 2) Second question, I submit a form and my flash component starts e.g. 3 new sessions and POST's to /resize /resize sets a SessionVar variable but it's like it's only being set the first time. I'm printing out right before I register the clean up handler in the SessionVar, from my jetty logs: INFO - Service request (GET) /images/cancelbutton.gif took 9 Milliseconds Rez Gots: 127.0.0.1 Registering cleanup for: 1uvl5176sdy9r Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 270 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 91 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 481 Milliseconds I would think it should print out Registering cleanup handler ... after each /resize request since they are different sessions. Then the sessions all timeout and I can see there are 4 sessions expiring but there is only message printed out once from the clean up handler. What are your thoughts on this? Cheers, Alfred On Feb 4, 1:19 am, Alli allilis...@gmail.com wrote: Thanks David, I'll get it tomorrow from scala-tools.org and finish up the app. URL will behttp://www.resizemypics.neta free service for people to resize their pictures and view them online. Just a simple, yet convenient service. Gives me a chance to learn more about lift as well. Been following lift for a while but this is the first site I finish, have a half finished blog site in lift. Doing all this stuff outside of work so it's easy to get distracted. Will let you know once the site is in production. Again thanks for your help. Cheers, Alli On Feb 4, 1:12 am, David Pollak feeder.of.the.be...@gmail.com wrote: 0.11-SNAPSHOT is 0.10 with bug fixes. It's very stable and will be 1.0 on 2/26. I'll commit up a fix to this problem in a few minutes. Also, what's the URL of the site? :-) On Tue, Feb 3, 2009 at 4:58 PM, Alli allilis...@gmail.com wrote: 0.10 at the moment, reckon i should upgrade to 0.11? This site is going live soon though and I was not sure about the status of 0.11-snapshot. On Feb 4, 12:56 am, David Pollak feeder.of.the.be...@gmail.com wrote: Crud. It looks like the session cleanup is done outside of the session scope. Are you using 0.11-SNAPSHOT? On Tue, Feb 3, 2009 at 4:35 PM, Alli allilis...@gmail.com wrote: Been testing this stuff and my object is like this: object ReportAddress extends SessionVar[String]() { def cleanUp() = { println(S.session) S.session.map { sess = println(Session ID: + sess.uniqueId) println(REM ADDRESS: + this.is) val tempDir = ... // Remove the temporary dir for this session. tempDir.destroy() } } registerCleanupFunc(cleanUp _) } println(S.session) always gives me Empty Any idea what could cause this? On Feb 3, 10:38 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 2:13 PM, Alli allilis...@gmail.com wrote: Makes a lot of sense, thanks David. Always amazes me how good and clean the design of lift is. Flattery will get you a lot... :-) On Feb 3, 9:49 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 1:06 PM, Alli allilis...@gmail.com wrote: Evening, During the lifetime of a session, the session may have uploaded bunch of files and these need to be able to be destroyed/unlinked when a session ends. When user uploads a file it's parent dir is determined by the session unique ID and the remote address of the uploader. The name is e.g. / tmp/sha1 hash of session id and remote address'. This
[Lift] Re: Need access to session variables when about to shut down a session.
I've just realized that I'm a complete idiot. I need to totally re-do the clean-up mechanism. Please give me an hour. On Wed, Feb 4, 2009 at 3:06 PM, Kris Nuttycombe kris.nuttyco...@gmail.comwrote: Heh, this one just bit me too. I can't say I didn't warn myself, though: // This is way too dependent upon an implementation detail of the superclass. override def cleanupFunc : Box[() = Unit] = { ... } Kris On Wed, Feb 4, 2009 at 1:47 PM, David Pollak feeder.of.the.be...@gmail.com wrote: That's because cleanUpFunc is gone. You must do: object sessDirHash extends SessionVar[String]() { registerCleanupFunc(session = println(Got hash: + this.is)) } On Wed, Feb 4, 2009 at 12:43 PM, Alli allilis...@gmail.com wrote: Hey David, Two questions this time: I've been playing with your commit earlier today and cleaning up SessionVar's. I got: object sessDirHash extends SessionVar[String]() { def cleanUpFunc(sess: LiftSession) = { println(Got hash: + this.is) } In my test snippet I got: sessDirHash(this is a test) println(Got var: + ResizeMyPics.sessDirHash.is) I can see it printed out correctly after setting it but it's empty in the cleanup function. 2) Second question, I submit a form and my flash component starts e.g. 3 new sessions and POST's to /resize /resize sets a SessionVar variable but it's like it's only being set the first time. I'm printing out right before I register the clean up handler in the SessionVar, from my jetty logs: INFO - Service request (GET) /images/cancelbutton.gif took 9 Milliseconds Rez Gots: 127.0.0.1 Registering cleanup for: 1uvl5176sdy9r Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 270 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 91 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 481 Milliseconds I would think it should print out Registering cleanup handler ... after each /resize request since they are different sessions. Then the sessions all timeout and I can see there are 4 sessions expiring but there is only message printed out once from the clean up handler. What are your thoughts on this? Cheers, Alfred On Feb 4, 1:19 am, Alli allilis...@gmail.com wrote: Thanks David, I'll get it tomorrow from scala-tools.org and finish up the app. URL will behttp://www.resizemypics.neta free service for people to resize their pictures and view them online. Just a simple, yet convenient service. Gives me a chance to learn more about lift as well. Been following lift for a while but this is the first site I finish, have a half finished blog site in lift. Doing all this stuff outside of work so it's easy to get distracted. Will let you know once the site is in production. Again thanks for your help. Cheers, Alli On Feb 4, 1:12 am, David Pollak feeder.of.the.be...@gmail.com wrote: 0.11-SNAPSHOT is 0.10 with bug fixes. It's very stable and will be 1.0 on 2/26. I'll commit up a fix to this problem in a few minutes. Also, what's the URL of the site? :-) On Tue, Feb 3, 2009 at 4:58 PM, Alli allilis...@gmail.com wrote: 0.10 at the moment, reckon i should upgrade to 0.11? This site is going live soon though and I was not sure about the status of 0.11-snapshot. On Feb 4, 12:56 am, David Pollak feeder.of.the.be...@gmail.com wrote: Crud. It looks like the session cleanup is done outside of the session scope. Are you using 0.11-SNAPSHOT? On Tue, Feb 3, 2009 at 4:35 PM, Alli allilis...@gmail.com wrote: Been testing this stuff and my object is like this: object ReportAddress extends SessionVar[String]() { def cleanUp() = { println(S.session) S.session.map { sess = println(Session ID: + sess.uniqueId) println(REM ADDRESS: + this.is) val tempDir = ... // Remove the temporary dir for this session. tempDir.destroy() } } registerCleanupFunc(cleanUp _) } println(S.session) always gives me Empty Any idea what could cause this? On Feb 3, 10:38 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 2:13 PM, Alli allilis...@gmail.com wrote: Makes a lot of sense, thanks David. Always amazes me how good and clean the design of lift is. Flattery will get you a lot... :-) On Feb 3, 9:49 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 1:06 PM, Alli allilis...@gmail.com wrote: Evening, During the lifetime of a session, the session may have uploaded bunch of files and these need to be able to be destroyed/unlinked when a session ends. When user uploads a
[Lift] Re: Need access to session variables when about to shut down a session.
No worries, the session vars seem to be reset to their default values before the callback gets called. I followed the code myself in Vars and LiftSession and couldn't find anything wrong. Will look at your change set tomorrow to learn better how this works. If i spot possible bugs I would like to get involved and write test cases etc so I don't have to bother you and others on the list all the time. On Feb 4, 11:56 pm, David Pollak feeder.of.the.be...@gmail.com wrote: I've just realized that I'm a complete idiot. I need to totally re-do the clean-up mechanism. Please give me an hour. On Wed, Feb 4, 2009 at 3:06 PM, Kris Nuttycombe kris.nuttyco...@gmail.comwrote: Heh, this one just bit me too. I can't say I didn't warn myself, though: // This is way too dependent upon an implementation detail of the superclass. override def cleanupFunc : Box[() = Unit] = { ... } Kris On Wed, Feb 4, 2009 at 1:47 PM, David Pollak feeder.of.the.be...@gmail.com wrote: That's because cleanUpFunc is gone. You must do: object sessDirHash extends SessionVar[String]() { registerCleanupFunc(session = println(Got hash: + this.is)) } On Wed, Feb 4, 2009 at 12:43 PM, Alli allilis...@gmail.com wrote: Hey David, Two questions this time: I've been playing with your commit earlier today and cleaning up SessionVar's. I got: object sessDirHash extends SessionVar[String]() { def cleanUpFunc(sess: LiftSession) = { println(Got hash: + this.is) } In my test snippet I got: sessDirHash(this is a test) println(Got var: + ResizeMyPics.sessDirHash.is) I can see it printed out correctly after setting it but it's empty in the cleanup function. 2) Second question, I submit a form and my flash component starts e.g. 3 new sessions and POST's to /resize /resize sets a SessionVar variable but it's like it's only being set the first time. I'm printing out right before I register the clean up handler in the SessionVar, from my jetty logs: INFO - Service request (GET) /images/cancelbutton.gif took 9 Milliseconds Rez Gots: 127.0.0.1 Registering cleanup for: 1uvl5176sdy9r Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 270 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 91 Milliseconds Rez Gots: 127.0.0.1 Rez Rep Gots: 127.0.0.1 INFO - Service request (POST) /resize took 481 Milliseconds I would think it should print out Registering cleanup handler ... after each /resize request since they are different sessions. Then the sessions all timeout and I can see there are 4 sessions expiring but there is only message printed out once from the clean up handler. What are your thoughts on this? Cheers, Alfred On Feb 4, 1:19 am, Alli allilis...@gmail.com wrote: Thanks David, I'll get it tomorrow from scala-tools.org and finish up the app. URL will behttp://www.resizemypics.netafree service for people to resize their pictures and view them online. Just a simple, yet convenient service. Gives me a chance to learn more about lift as well. Been following lift for a while but this is the first site I finish, have a half finished blog site in lift. Doing all this stuff outside of work so it's easy to get distracted. Will let you know once the site is in production. Again thanks for your help. Cheers, Alli On Feb 4, 1:12 am, David Pollak feeder.of.the.be...@gmail.com wrote: 0.11-SNAPSHOT is 0.10 with bug fixes. It's very stable and will be 1.0 on 2/26. I'll commit up a fix to this problem in a few minutes. Also, what's the URL of the site? :-) On Tue, Feb 3, 2009 at 4:58 PM, Alli allilis...@gmail.com wrote: 0.10 at the moment, reckon i should upgrade to 0.11? This site is going live soon though and I was not sure about the status of 0.11-snapshot. On Feb 4, 12:56 am, David Pollak feeder.of.the.be...@gmail.com wrote: Crud. It looks like the session cleanup is done outside of the session scope. Are you using 0.11-SNAPSHOT? On Tue, Feb 3, 2009 at 4:35 PM, Alli allilis...@gmail.com wrote: Been testing this stuff and my object is like this: object ReportAddress extends SessionVar[String]() { def cleanUp() = { println(S.session) S.session.map { sess = println(Session ID: + sess.uniqueId) println(REM ADDRESS: + this.is) val tempDir = ... // Remove the temporary dir for this session. tempDir.destroy() } } registerCleanupFunc(cleanUp _) } println(S.session) always gives me Empty Any idea what could cause this? On Feb 3, 10:38 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 2:13 PM, Alli allilis...@gmail.com wrote:
[Lift] Re: Need access to session variables when about to shut down a session.
Makes a lot of sense, thanks David. Always amazes me how good and clean the design of lift is. On Feb 3, 9:49 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 1:06 PM, Alli allilis...@gmail.com wrote: Evening, During the lifetime of a session, the session may have uploaded bunch of files and these need to be able to be destroyed/unlinked when a session ends. When user uploads a file it's parent dir is determined by the session unique ID and the remote address of the uploader. The name is e.g. / tmp/sha1 hash of session id and remote address'. This means in order to determine what to destroy I need to know what remote address the session belongs to. I am setting that when uploading a file has been uploaded successfully. In Boot.scala I want to do something like: // Set session handler. LiftSession.onAboutToShutdownSession = List[LiftSession = Unit]( session = { var sessId = session.uniqueId val remoteIp = session.get(remoteAddress) val myTempDir = new TempDirWeb(sessId, remoteIp) myTempDir.unlinkall() }) Problem with this is that the LiftSession.get[T]() method is package private (liftweb). I can think of some other scenarios where one would need access to the session variables before destroying the session. Does this make sense or is my design just plain wrong? :). get is typesafe, so exposing it would make it not type safe. It's always accessed via SessionVars. You can do something like: object ReportAddress extends SessionVar[String]() { def cleanUp() { S.session.map{ sess = val td = new TempDirWeb(sess.uniqueId, this.is) td.unlinkall() } } registerCleanupFunc(cleanUp _) } Each SessionVar (and RequestVar) has a cleanup func that will be called as the Var is going away. Cheers, Alfred -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Need access to session variables when about to shut down a session.
On Tue, Feb 3, 2009 at 1:06 PM, Alli allilis...@gmail.com wrote: Evening, During the lifetime of a session, the session may have uploaded bunch of files and these need to be able to be destroyed/unlinked when a session ends. When user uploads a file it's parent dir is determined by the session unique ID and the remote address of the uploader. The name is e.g. / tmp/sha1 hash of session id and remote address'. This means in order to determine what to destroy I need to know what remote address the session belongs to. I am setting that when uploading a file has been uploaded successfully. In Boot.scala I want to do something like: // Set session handler. LiftSession.onAboutToShutdownSession = List[LiftSession = Unit]( session = { var sessId = session.uniqueId val remoteIp = session.get(remoteAddress) val myTempDir = new TempDirWeb(sessId, remoteIp) myTempDir.unlinkall() }) Problem with this is that the LiftSession.get[T]() method is package private (liftweb). I can think of some other scenarios where one would need access to the session variables before destroying the session. Does this make sense or is my design just plain wrong? :). get is typesafe, so exposing it would make it not type safe. It's always accessed via SessionVars. You can do something like: object ReportAddress extends SessionVar[String]() { def cleanUp() { S.session.map{ sess = val td = new TempDirWeb(sess.uniqueId, this.is) td.unlinkall() } } registerCleanupFunc(cleanUp _) } Each SessionVar (and RequestVar) has a cleanup func that will be called as the Var is going away. Cheers, Alfred -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Need access to session variables when about to shut down a session.
Crud. It looks like the session cleanup is done outside of the session scope. Are you using 0.11-SNAPSHOT? On Tue, Feb 3, 2009 at 4:35 PM, Alli allilis...@gmail.com wrote: Been testing this stuff and my object is like this: object ReportAddress extends SessionVar[String]() { def cleanUp() = { println(S.session) S.session.map { sess = println(Session ID: + sess.uniqueId) println(REM ADDRESS: + this.is) val tempDir = ... // Remove the temporary dir for this session. tempDir.destroy() } } registerCleanupFunc(cleanUp _) } println(S.session) always gives me Empty Any idea what could cause this? On Feb 3, 10:38 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 2:13 PM, Alli allilis...@gmail.com wrote: Makes a lot of sense, thanks David. Always amazes me how good and clean the design of lift is. Flattery will get you a lot... :-) On Feb 3, 9:49 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 1:06 PM, Alli allilis...@gmail.com wrote: Evening, During the lifetime of a session, the session may have uploaded bunch of files and these need to be able to be destroyed/unlinked when a session ends. When user uploads a file it's parent dir is determined by the session unique ID and the remote address of the uploader. The name is e.g. / tmp/sha1 hash of session id and remote address'. This means in order to determine what to destroy I need to know what remote address the session belongs to. I am setting that when uploading a file has been uploaded successfully. In Boot.scala I want to do something like: // Set session handler. LiftSession.onAboutToShutdownSession = List[LiftSession = Unit]( session = { var sessId = session.uniqueId val remoteIp = session.get(remoteAddress) val myTempDir = new TempDirWeb(sessId, remoteIp) myTempDir.unlinkall() }) Problem with this is that the LiftSession.get[T]() method is package private (liftweb). I can think of some other scenarios where one would need access to the session variables before destroying the session. Does this make sense or is my design just plain wrong? :). get is typesafe, so exposing it would make it not type safe. It's always accessed via SessionVars. You can do something like: object ReportAddress extends SessionVar[String]() { def cleanUp() { S.session.map{ sess = val td = new TempDirWeb(sess.uniqueId, this.is) td.unlinkall() } } registerCleanupFunc(cleanUp _) } Each SessionVar (and RequestVar) has a cleanup func that will be called as the Var is going away. Cheers, Alfred -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---
[Lift] Re: Need access to session variables when about to shut down a session.
0.11-SNAPSHOT is 0.10 with bug fixes. It's very stable and will be 1.0 on 2/26. I'll commit up a fix to this problem in a few minutes. Also, what's the URL of the site? :-) On Tue, Feb 3, 2009 at 4:58 PM, Alli allilis...@gmail.com wrote: 0.10 at the moment, reckon i should upgrade to 0.11? This site is going live soon though and I was not sure about the status of 0.11-snapshot. On Feb 4, 12:56 am, David Pollak feeder.of.the.be...@gmail.com wrote: Crud. It looks like the session cleanup is done outside of the session scope. Are you using 0.11-SNAPSHOT? On Tue, Feb 3, 2009 at 4:35 PM, Alli allilis...@gmail.com wrote: Been testing this stuff and my object is like this: object ReportAddress extends SessionVar[String]() { def cleanUp() = { println(S.session) S.session.map { sess = println(Session ID: + sess.uniqueId) println(REM ADDRESS: + this.is) val tempDir = ... // Remove the temporary dir for this session. tempDir.destroy() } } registerCleanupFunc(cleanUp _) } println(S.session) always gives me Empty Any idea what could cause this? On Feb 3, 10:38 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 2:13 PM, Alli allilis...@gmail.com wrote: Makes a lot of sense, thanks David. Always amazes me how good and clean the design of lift is. Flattery will get you a lot... :-) On Feb 3, 9:49 pm, David Pollak feeder.of.the.be...@gmail.com wrote: On Tue, Feb 3, 2009 at 1:06 PM, Alli allilis...@gmail.com wrote: Evening, During the lifetime of a session, the session may have uploaded bunch of files and these need to be able to be destroyed/unlinked when a session ends. When user uploads a file it's parent dir is determined by the session unique ID and the remote address of the uploader. The name is e.g. / tmp/sha1 hash of session id and remote address'. This means in order to determine what to destroy I need to know what remote address the session belongs to. I am setting that when uploading a file has been uploaded successfully. In Boot.scala I want to do something like: // Set session handler. LiftSession.onAboutToShutdownSession = List[LiftSession = Unit]( session = { var sessId = session.uniqueId val remoteIp = session.get(remoteAddress) val myTempDir = new TempDirWeb(sessId, remoteIp) myTempDir.unlinkall() }) Problem with this is that the LiftSession.get[T]() method is package private (liftweb). I can think of some other scenarios where one would need access to the session variables before destroying the session. Does this make sense or is my design just plain wrong? :). get is typesafe, so exposing it would make it not type safe. It's always accessed via SessionVars. You can do something like: object ReportAddress extends SessionVar[String]() { def cleanUp() { S.session.map{ sess = val td = new TempDirWeb(sess.uniqueId, this.is) td.unlinkall() } } registerCleanupFunc(cleanUp _) } Each SessionVar (and RequestVar) has a cleanup func that will be called as the Var is going away. Cheers, Alfred -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp -- Lift, the simply functional web frameworkhttp://liftweb.net Beginning Scalahttp://www.apress.com/book/view/1430219890 Follow me:http://twitter.com/dpp Git some:http://github.com/dpp -- Lift, the simply functional web framework http://liftweb.net Beginning Scala http://www.apress.com/book/view/1430219890 Follow me: http://twitter.com/dpp Git some: http://github.com/dpp --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Lift group. To post to this group, send email to liftweb@googlegroups.com To unsubscribe from this group, send email to liftweb+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/liftweb?hl=en -~--~~~~--~~--~--~---