Converting Http Session Events into Grails 3 Events

October 19, 2015 1:16 pm

Grails 3 introduced a new Events API based on Reactor.  Unfortunately, as far as I can tell, HttpSessionEvents are not natively part of the Grails 3 Events system.  Bringing them in to the fold, however, is pretty easy.  I based this off of Oliver Wahlen’s immensely helpful blog post about sending the HttpSessionEvents to a Grails service.

First, let’s create our Spring HttpSessionServletListener.  Create this file somewhere in the /src/ path where Grails will find it:

File: .../grailsProject/src/main/groovy/com/example/HttpSessionServletListener.groovy
package com.example

import grails.events.*
import javax.servlet.http.HttpSession
import javax.servlet.http.HttpSessionEvent
import javax.servlet.http.HttpSessionListener

class HttpSessionServletListener implements HttpSessionListener, Events {
  
    // called by servlet container upon session creation
    void sessionCreated(HttpSessionEvent event) {
        notify("example:httpSessionCreated", event.session)
    }

    // called by servlet container upon session destruction
    void sessionDestroyed(HttpSessionEvent event) {
        notify("example:httpSessionDestroyed", event.session)
    }
}

Now register the HttpSessionServletListener as a Spring Bean.  If you don’t already have a resources.groovy file, create one and add the following.

.../grailsProject/grails-app/conf/spring/resources.groovy
import org.springframework.boot.context.embedded.ServletListenerRegistrationBean
import com.example.HttpSessionServletListener

beans = {
    
    httpSessionServletListener(ServletListenerRegistrationBean) {
        listener = bean(HttpSessionServletListener)
    }
    
}
// Yes this is the entire file

Now you are all set to listen for the “example:httpSessionCreated” and “example:httpSessionDestroyed” events using the Grails 3 Events API.  “Example” is the namespace of the event, which in my real code I set to the last part of the package name, so I made it match the package name of “example”.  Just use something so you don’t have to worry about naming collisions.

Here’s an example of listening for the events in a standard Grails Controller.  Note that the event handlers are attached after construction, and before the Controller bean is made available, by using the PostConstruct annotation.

.../grailsProject/grails-app/controllers/com/example/ExampleController.groovy
package com.example

import grails.events.*
import javax.annotation.PostConstruct

class ExampleController {
    
    @PostConstruct
    void init() {
        
        on("example:httpSessionCreated") { session ->
            println "sessionCreated: ${session.id}"
        }
        
        on("example:httpSessionDestroyed") { session ->
            println "sessionDestroyed: ${session.id}"
        }
    }
}

NASA Apollo Pictures

October 5, 2015 5:40 pm

Last week NASA released a bunch (over 10,000) of original images from the Apollo missions on their Flickr account.  They’re all Public Domain images so anyone can download the originals and use them for anything they like.  I flipped through and picked out my favorites and cleaned them up.  I’ll probably get some nice canvas prints made of some of them when Canvas Press has sales.

Here are my top 10 after cleaning them up.  I’ve uploaded my full versions so you can download them yourself if you want to make a poster or canvas print or something.  Clicking an image will open the full-size version, which you can then save to your computer using right-click -> Save image…21060968314_bcca0b9191_o_kbd 21065336993_765fba69b6_o_kbd 21082003763_9471526a7e_o_kbd 21472205930_d42afbe79a_o_kbd 21492224000_7f7d5991a8_o_kbd 21496319710_4d7bd28063_o_kbd 21653924176_26f5a10ce1_o_kbd 21667234912_ac412e1fb9_o_kbd 21693186921_68e0b6d72f_o_kbd 21912171516_ea0ef12faf_o_kbd

 

A Light in the Dark

September 28, 2015 7:34 pm

I wrapped an LED around a button battery with a little material to keep it separated so you push on it to turn the LED on.  Then we took turns waving it around while camera took a picture with a long exposure.

Heather’s work was usually very…nuclear:

IMGP3861as

We encouraged her to move around more:

IMGP3863as

I tried to write my name, but my spatial awareness is apparently not great:

IMGP3865as

Jess did better with her contribution:

IMGP3867as

Lunar Eclipse 2015

September 27, 2015 8:41 pm

We and a few families from Church went to a local park and climbed a hill to try and get a decent view of the lunar eclipse tonight.  Despite having had nothing but clear skies for about 9 months we managed to have clouds covering the eastern sky, and only the eastern sky, this evening.  We waited around for a while and did manage to get about 5 minutes where we could see the moon.  I had had plans to try and make a nice timelapse image as the moon came up over the horizon, but that didn’t work out.

Here’s the best shot I managed to get:

Lunar Eclipse from Livermore, CA
Lunar Eclipse from Livermore, CA

But at least we got a chance to hangout with friends for a little while and we did get to see something.

Of course, after the eclipse ended the sky cleared up perfectly:

IMGP3856a

These were just using my Pentax K-7 with a 200mm lens, nothing special.

And here is some of the group that was up on the hill watching:

IMGP3831as

Scott Adams, Donald Trump, What is Real?

September 9, 2015 11:19 am

Scott Adams, creator of Dilbert, has been writing a series of articles discussing Donald Trump and his presidential campaign.  Scott Adams is, so far, the only person I’ve seen who can build a coherent argument about who Donald Trump is, what he’s trying to do, and why it’s working.  That makes me pay attention.

He started with his post on August 13 titled “Clown Genius.”  You should go read it and if Adams’ hypothesis intrigues you then keep looking through his blog posts after that date, he writes a lot about Trump and gives really interesting examples and details of what’s happening and why it’s working.

His most important point thus far, I think, is understanding that Trump is, first and foremost, a businessman.  He literally wrote the book on negotiation.  Anything he says is part of a negotiation.  We find this strange in U.S. politics because negotiation in politics has been dead for 20 years or so.  “Compromise” has become a career killer.  But it’s necessary to be successful in business.

So, Adams says, when Trump presents some extreme position he’s just using it to anchor the negotiation and then he can move to the middle as he sees fit and compromise; just like any negotiation.  You never open with what you actually expect to get–that would simply guarantee that you don’t get it.  Politicians act this way, but they seem to have forgotten the part where you then negotiate to something more reasonable.

Adams believes Trump will easily reposition himself as necessary and that he’ll do it in a way that is immune from people calling him a “flip-flopper.”  That is, he will task underlings with studying the topics and putting together proposals that outline costs, likelihood of success, etc–standard business practice; then when he picks a more moderate position it will be based on analysis of data and facts which is totally reasonable–not flip-flopping.

The overall concept that Adams discusses is the “Master Wizard” hypothesis (so you’ll see that term in his writing).  That is, people like Trump have studied and learned the art of getting what they want.  Call it persuasion or manipulation or whatever but the result is the same.  They get people to agree with them and then give them what they want.  He suggests another  Master Wizard you might recognize: Steve Jobs.  By all objective accounts he was a jerk with no technical skill.  Yet he was absurdly successful running a computer company.  He got people to do things for him, no question about it.

Here’s one example Adams calls out: Trump was getting a lot of press recently for calling Ben Carson a “nice guy.”  It’s an interesting phrase to use and he carefully ends his statement with it so it’s left hanging.  What do many people mentally fill in when you drop the phrase “nice guy(s)” and then leave it hanging?  “Finish last.”  Adams argues that Trump fired this “linguistic bullet” to end Carson’s campaign.  In his opinion, millions of people now believe Carson has no chance of winning because he’s too nice, but they don’t realize why they think that.  That is how wizards operate.

The thing that’s scary to me is that the more I read Adams’ thoughts on the subject the more is seems like Trump isn’t necessarily a bad candidate.  Someone who actually negotiates would be good for the country, we need to bring compromise back in to politics.  But then another part of my brain just says, “Buuuut….he’s Donald Trump….seriously?”

Adams believes Trump will win the Republican nomination and then win the general election.  I don’t know if that will happen, but Adams has convinced me that I should definitely pay more attention to the details of how Trump is operating and that there is more there than meets the eye.