Archive for the ‘Random’ Category

New Interceptor Configuration in Seam 2.1.x

Wednesday, 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

Monday, 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.

Think before you post

Tuesday, March 6th, 2007

I frequently visit various technical forums online to keep myself abreast on the continual development of various technologies that interest me. These forums have serve me well over the years as I would be able to learn from many interesting discussions, ideas, and solutions that kept me incessantly active. Nowadays, I try to give back to the community more than before by answering questions that users may have. However, is it me or are there many people who don’t think before they post? I think, paradoxically, many people want to have their questions go unanswered, or how else can you explain the myriad of questions out there that are lacking important ingredients to get a meaningful response. For me, I look for posts that are meaningful, diligent and, most importantly, concise.

A meaningful question should clearly state the problem. This isn’t so hard, is it? Yet, many posts I encounter don’t make that obviously clear. Usually, I scan very quickly for the meaning in the first few lines of the post, then I might skip to the bottom of the post to find it, if it wasn’t already found. If it’s hidden somewhere in the middle, then you can bet that I will hit the back button or close the tab to save myself the headache from decipherment. My recommendation is, obviously, state your intention clearly and early.

An diligent question should not rely on readers to make assumptions. Don’t post a generalized question because I don’t know where to start when I’m responding to it. Be specific! The post should demonstrate sufficient understanding, research and analysis on the matter under discussion. That means include source code (gawd, don’t include your entire program) and stacktraces if the question is about why a particular Java program is not working, for example. Don’t make the readers do any more work than necessary.

Finally, a concise question is exactly that–short and to the point. Write as few words as possible, but include the most relevant pieces of information. Seriously, I can’t emphasize that enough. If I want to read a novel, I’ll go to the bookstore or the library. If you believe that the inclusion of your country of origin presents a substantial significance to the goal of the post, then leave it intact. Otherwise, omit it.

So if you have any trouble getting any meaningful responses to your posts on forums, maybe try following some of these simple guidelines to help me to help you figure out exactly what is your problem.

Pet peeve: good versus well

Tuesday, February 27th, 2007

It just perplexes me how people develop the habit of misusing these words. I always feel the urge to correct these uninformed people when I hear they say “I’m doing good.” Ugh.

First post

Saturday, February 24th, 2007

Nothing much to see for now.