around ScalatraKernel, easier to reuse) and cons (more verbose). But
generalization of the existing before and after filters.
On Wed, Apr 27, 2011 at 11:26 AM, Wille Faler <wille.fa
...@gmail.com> wrote:
> Does Scalatra have an equivalent of an "around"-filter?
> That could replace a lot of ugliness that comes with dealing with
> before/after/onRequest/etc lifecycle type events, as you can simply compose
> functions in different ways..
> On 27 April 2011 16:21, Ross A. Baker <ba...@alumni.indiana.edu> wrote:
>> I tend to prefer handlers to before/after filters, but it's not a
>> unanimous opinion. Depends on the use case, I guess.
>> There's a GitHub wiki that has never gotten off the ground.
>> Documentation is in the README and being migrated to the in-progress
>> website project. Pull requests for those are always appreciated.
>> With the right abstraction, I could also see that Handler evolving
>> into a scalatra-squeryl helper module.
>> On Wed, Apr 27, 2011 at 11:02 AM, Dustin Withers <fadedd...@gmail.com>
>> wrote:
>> > Wow, fantastic. Thanks for the help. I was just able to get the
>> > dynamic variable working, it seemed like I would use the value inside
>> > the block but I was confused. Your handler trait is quite superior. Is
>> > there a wiki that I can post all of this? Most of the google scouring
>> > I have done has not been this helpful and maybe having one place to
>> > show how to do a boring old MySQL connection could be helpful to
>> > others?
>> > On Apr 27, 9:46 am, "Ross A. Baker" <ba...@alumni.indiana.edu> wrote:
>> >> withValue one sets the value for the life of the block you pass it, so
>> >> dlSession would be null again after the before filter. I think you
>> >> want:
>> >> before {
>> >> dlSession.value = SessionFactory.newSession
>> >> dlSession.value.bindToCurrentThread
>> >> }
>> >> after {
>> >> dlSession.value.unbindFromCurrentThread
>> >> dlSession.value.close
>> >> dlSession.value = null
>> >> }
>> >> Alternatively you could implement Handler:
>> >> trait DlSessionSupport extends Handler {
>> >> val dlSession = new DynamicVariable[Session](null)
>> >> abstract override def handle(req: HttpServletRequest, resp:
>> >> HttpServletResponse) {
>> >> dlSession.withValue(SessionFactory.newSession) {
>> >> dlSession.value.bindToCurrentThread
>> >> try {
>> >> super.handle(request, response)
>> >> } finally {
>> >> dlSession.value.close
>> >> dlSession.value.unbindFromCurrentThread
>> >> }
>> >> }
>> >> }
>> >> }
>> >> class DailyLifFilter extends ScalatraFilter with ScalateSupport
>> >> with DlSessionSupport
>> >> On Wed, Apr 27, 2011 at 10:36 AM, Dustin Withers <fadedd...@gmail.com>
>> >> wrote:
>> >> > Where should I bind that variable? In a companion object to the
>> >> > Filter? Or should I still do it in my Filters class? Like:
>> >> > class DailyLifFilter extends ScalatraFilter with ScalateSupport with
>> >> > DatabaseInit {
>> >> > val dlSession = new DynamicVariable[Session](null)
>> >> > before {
>> >> > dlSession.withValue(SessionFactory.newSession) {
>> >> > dlSession.value.bindToCurrentThread
>> >> > }
>> >> > }
>> >> > after {
>> >> > dlSession.value.close
>> >> > dlSession.value.unbindFromCurrentThread
>> >> > }
>> >> > }
>> >> > On Apr 27, 9:12 am, Wille Faler <wille.fa...@gmail.com> wrote:
>> >> >> Hmm, making it an instance variable of your filter is not
>> >> >> thread-safe, so
>> >> >> you should probably bind your session to a
>> >> >> DynamicVariable/ThreadLocal
>> >> >> (DynamicVariable is Scala's equivalent of ThreadLocal)..
>> >> >> On 27 April 2011 15:10, Dustin Withers <fadedd...@gmail.com> wrote:
>> >> >> > Should something like the following work?
>> >> >> > class DailyLifFilter extends ScalatraFilter with ScalateSupport {
>> >> >> > var dlSession:Session = null
>> >> >> > before {
>> >> >> > dlSession = SessionFactory.newSession
>> >> >> > dlSession.bindToCurrentThread
>> >> >> > }
>> >> >> > after {
>> >> >> > dlSession.close
>> >> >> > dlSession.unbindFromCurrentThread
>> >> >> > }
>> >> >> > ....
>> >> >> > Thanks,
>> >> >> > -dustin
>> >> >> > On Apr 27, 9:01 am, Wille Faler <wille.fa...@gmail.com> wrote:
>> >> >> > > You're probably leaking sessions and connections, as you are not
>> >> >> > > closing
>> >> >> > > them or unbinding the session after a request:
>> >> >> > > session.close
>> >> >> > > session.unbindFromCurrentThread
>> >> >> > > On 27 April 2011 14:37, Dustin Withers <fadedd...@gmail.com>
>> >> >> > > wrote:
>> >> >> > > > Hello all,
>> >> >> > > > I'm new to Scala and new to Scalatra, heck I'm kinda new to
>> >> >> > > > Java web
>> >> >> > > > development other than a bunch of Oracle work in another life.
>> >> >> > > > Anyhow,
>> >> >> > > > I'm having some trouble with MySQL and C3P0 connection pooling
>> >> >> > > > . The
>> >> >> > > > code can be seen here:
>> >> >> > > >https://gist.github.com/944244
>> >> >> > > > Originally I wasn't using any kind of connection pooling and I
>> >> >> > > > eventually exhausted my connections. Now instead of exhausting
>> >> >> > > > connections the app seems to run out of C3P0 connections and
>> >> >> > > > then
>> >> >> > > > locks up with no logging in the console and no CPU usage but
>> >> >> > > > the
>> >> >> > > > thread count goes up each time I request a page.
>> >> >> > > > I've played with all of C3P0's settings and I can stave off
>> >> >> > > > the
>> >> >> > > > failure by increasing MaxPoolSize but eventually after a
>> >> >> > > > enough page
>> >> >> > > > requests the app hangs.
>> >> >> > > > Any thoughts? Should I bother the people on the Squeryl
>> >> >> > > > mailing list?
>> >> >> > > > Thanks much for your time,
>> >> >> > > > -dustin
>> >> --
>> >> Ross A. Baker
>> >> ba...@alumni.indiana.edu
>> >> Indianapolis, IN, USA
>> --
>> Ross A. Baker
>> ba...@alumni.indiana.edu
>> Indianapolis, IN, USA
Ross A. Baker