New Interceptor Configuration in Seam 2.1.x

August 27th, 2008

I thought this is a good time for this post since Seam 2.1.0b1 is out. If you look through the feature list for 2.1.0b1, you’ll notice the new built-in ability to customize the default interceptor stack which I find convenient. Lately, I have been wanting to enable or disable my custom Interceptors at deployment time but realized this wasn’t easily achievable in 2.0.x. If you know of a way, let me know. The 2.1.x releases seem to support this feature, although I haven’t seen it documented. Interceptors in 2.1.x can take an optional method with the signature public boolean isInterceptorEnabled() {} where it will be checked at deployment time whether the interceptor is enabled or disabled for that particular component. This gives you finer control on when interceptors will be enabled against your components because they can be source of performance headaches in Seam applications.

Here’s a contrived example where we have a SimpleProfile annotation that is used to mark components to use the ProfileInterceptor which simply tracks the response time for each invocation call to the component.


// SimpleProfile.java
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Interceptors(ProfileInterceptor.class)
public @interface SimpleProfile{}

// ProfilerInterceptor.java
@Interceptor
public class ProfileInterceptor extends AbstractInterceptor {
  private static LogProvider log
      = Logging.getLogProvider(ProfileInterceptor.class)

  @AroundInvoke
  public Object aroundInvoke(InvocationContext ivc) throws Exception {
    long begin = System.currentTimeMillis();
    Object result = ivc.proceed();
    long total = System.currentTimeMillis() - begin;
    Method method = ivc.getMethod();
    log.debug(method.getDeclaringClass().getSimpleName()
                + "." + method.getName() + " - "  + total + "ms")
    return result;

  }

  public boolean isInterceptorEnabled() {
    return getComponent().beanClassHasAnnotation(SimpleProfile.class)
             && Init.instance().isDebug();
  }
}

Now, if we have a Seam component:

@Name("exampleBean") @SimpleProfile public class ExampleBean {}

the interceptor will see the presence of the annotation and then check whether the debug property for Seam’s Init instance is turned on. This property is configurable in the components.xml so we can easily enable or disable Seam Interceptors at deployment time.

As a side note, you can customize the default list of Seam interceptors that will be used in the application by overriding the Init default property in components.xml:

  

<core:init>
  <core:interceptors>
    ..
    <value>your.package.SomeInterceptor</value>
    <value>your.package.AnotherInterceptor</value>
    ..
  </core:interceptors>
</core:init>

The power is back on

February 25th, 2008

just transferred to a new hosting provider so everything looks pretty bare but i should have everything back up in the next few days.

Why I don’t vote on DZone

November 12th, 2007

As announced on DZone, that “95% of visitors never vote, ever! Vote for just 3 new links per day, and you’ll enjoy a better DZone.” At first I was astonished with that figure, but then I remembered why I didn’t vote: registration required. I don’t know how others feel, but when I click on that arrow icon that signals to vote and then pop-ups a window to sign-up, I immediately closed it and said “no thanks.”

Seriously, I’m tired of having to do site registrations. And 99% of the time, I fill-in random information (e.g. “aoiweghoiawheawoegh”) quickly just so I can use a particular service like downloading a PDF, or posting to a forum at that moment. Really, as a user, that’s all I want to do. A month or two later when I return to the site, I would have to do the same thing again because I would have forgotten the user name and password I chose for that particular site (you don’t think honestly I would use the same user-id and password combination for every web site). bugmenot.com definitely helps, but I just don’t bother anymore.

IDEA VCS support

October 16th, 2007

The one thing I like about IDEA is that there’s full of goodies waiting to be discovered. Like the other day, I discovered the “changes” panel (ALT-9 for toggling) that tracks the activity of my VCS. Just from a glance, it tells me what local files are non-committed and what incoming files have not been updated by refreshing my VCS at a specified time interval. Often I always forget to do an update before I start writing code which increases the chance of conflicts, but now IDEA can help me detect stale copies and recommends that I do an update, which is pretty convenient. Also it’s much easier to do “diffing” of locally modified or incoming files because all the information is presented to you in one “changes” panel. I don’t appear to find myself navigating through source trees to try to make sense of what changes need to be synchronized. There’s other stuff like “changelist” which I haven’t really use because I do incremental commits rather than batch commits but maybe I’m missing the point. Were all these available before v7? I missed out.

Excuses to not advocate web framework X

October 16th, 2007

Alright fanboys, we know that you love your web framework and wishing others would see it the way you do. So you’re wondering why people don’t want to use your framework? Here’s my excuses:

  • Seam: JSF ’nuff said….immediate=true anyone?
  • Struts2: 5 years of Struts1 horror and you expect me to continue to follow the Struts tradition?
  • WebWork2 (re-branded to Struts2): i have to implement some interface for my Action?
  • Stripes: see WebWork2
  • Wicket: hmmm I have to learn Swing again?
  • Grails: why is my IDE-refactor broken??
  • Tapestry5: 4 versions, so this is the groundbreaking release?
  • Spring-MVC: sure when XML is cool again
  • Vanilla Servlet+JSP: are you kidding me?

What kind of syndrome is this?

October 15th, 2007

I wonder if I am the only one being inflicted with this kind of syndrome relating to software development. You learn a tool, and you begin to see it as the means to the end. It’s a mixed blessing that, on one hand, I felt that I learned a particular way at solving a problem. On the other hand, it’s annoying insofar that I feel my perception is warped as I find it increasingly difficult to rationalize with people who just don’t see it the way you do.

For example, when I first learned design patterns, I would try to find in previous projects to refactor existing or introduce new code into those patterns that I learned. Or when I learned how cool it was to understand what inversion-of-control means, and the next thing I realized that all my code is managed by Spring or whatever IoC container was popular then. I’m not one who’s afraid to think I’m wrong for behaving this way but it’s a problem I had to control over time with limited success. The new becomes old, and the vicious cycle repeats itself. I guess it’s understandable to see the giddy one gets from learning something new and feeling compelled to announce it to the world about their achievement. It’s like we’re kids constantly requiring approval that we are in fact learning and doing something right–and that’s okay. However, I think we all need to take a step back and reaffirm to ourselves that a tool is just one small piece of a larger puzzle that you’re trying to solve when you’re doing software development. It should rarely be deserving of your entire energy and focus.

Now having said that, these days I’m finding myself reading Groovy a little more than I should, and I think I maybe suffering again. Last time this happen to me was when I was looking up Seam and the syndrome lasted 5 months as that was the time it took to design and deploy the application into production.

I guess I never learn.

Getting Groovy with Java

October 10th, 2007

I really had no business delving into Groovy until I had recently attended a Groovy presentation at a local JUG meeting (thanks Jeff Brown). Sorry–I am a bit late to the coming-out party so excuse me if all this seems old news. But I came out of the presentation really impressed with the current state of Groovy. I was so impressed that I had quickly downloaded JetGroovy plug-in and began doing some simple and fun experimentation of the “differentiating” features in Groovy mixed with Java code! The soon-to-be-released IDEA7 supports Groovy/Grails, and from my VERY limited experience it does a pretty good job with the usual refactoring and smart capabilities that you have come to expect from IDEA. I love how Java and Groovy can interoperate with each other so seamlessly and effortlessly. It wasn’t always this easy in the past as I understood it; however, the soon-to-be-released Groovy 1.1 will address the ‘chicken-and-egg’ compilation-and-linking issue that made it difficult (but not impossible) to build mixed Groovy and Java projects. I’m excited for the Java platform.

On a related note, I am noticing Grails is seemingly gaining in attention, and, possibly even, some traction in the web-application framework space, and I am now beginning to find it intriguing after being exposed to Groovy. Cool stuff. Is there any reason for Java developers to even want to learn Ruby/Rails now?

Every project needs a swear jar

September 23rd, 2007

Humour =) Swear Jar

There’s more Eclipse-converts than we know

September 13th, 2007

OK, ya… so I ain’t afraid to admit that I’m an IDEA fanboy. So what do you think I did when I saw my new colleague whips out his Eclipse in his first day at work? That’s right–I tried to convert him. Any time you try to change someone’s habit, you got to be really really careful though. The wrong approach could make for an uneasy relationship down the road. My observations revealed to me it was doable. It wasn’t easy but I was convinced that if he would give it an honest trial then he would never go back to that crappy Eclipse. Boy I was right!

So I met him recently (we’re both with different employers now) that he told me he has officially been “converted.” While I’m not surprised, but that news brought a smile to my face which, then, leads me to think that there’s a lot more Eclipse-converts than we know. So where are you all at?

Liking the Live Query plugin for jQuery

September 12th, 2007

From my limited time using jQuery (a month now), I really came to enjoy this compact and powerful javascript library. I stumbled onto this while I was checking out Seam’s Wiki source. [Sidetrack–speaking of Seam’s Wiki, it’s now the web application that powers Hibernate blog–nice!] The only problem that I had with it was that it didn’t automatically bind event handlers to some selection of elements after the page is loaded. So I was looking for answers–and it came with the Live Query plugin, developed by Brandon Aaron. This is a really useful tool when you need to dynamically add and remove parts of a page dynamically by just updating the DOM via append(). I thought I maybe read somewhere that this plugin is in the road map to be part of the core of jQuery–good idea.