About Question enthuware.oce-ejbd.v6.2.361 :

Moderator: admin

Post Reply
prakashyaji
Posts: 25
Joined: Sun May 13, 2012 1:39 am
Contact:

About Question enthuware.oce-ejbd.v6.2.361 :

Post by prakashyaji »

Hi Paul,
I am little confused regarding life-cycle callback interceptors.

You said: Return type of life-cycle callback method must be void.

But when I wrote this sample code, it behaved differently. Please go through the following code snippet and help me... :)

Details: I am using Netbeans 6.9 and EE6 project - Glassfish server 3 Felix.

@Stateless
@Interceptors({TimerInterceptor.class,TestLifecycleCallbackInterceptor.class})
public class EnthuBean implements EnthuBeanRemote {

@PostConstruct
private void myPostConstruct(){
System.out.println("I am in myPostConstruct!");
}
}

// Bean code ends here...

public class TimerInterceptor {
@PostConstruct
public Object myPostConstruct(InvocationContext ic) throws Exception{
System.out.println("I am in postConstruct ------------- starts");
Object obj = ic.proceed();
System.out.println("I am in postConstruct ------------- ends");
return obj;
}
}

public class TestLifecycleCallbackInterceptor {

@PostConstruct
public Object postConstruct(InvocationContext ic) throws Exception{
System.out.println("I am in TestLifecycleCallbackInterceptor.postConstruct starts");
Object obj = ic.proceed();
System.out.println("I am in TestLifecycleCallbackInterceptor.postConstruct ends");
return obj;
}
}


// When I instantiate a EnthuBean, I get following log message

INFO: I am in postConstruct ------------- starts
INFO: I am in TestLifecycleCallbackInterceptor.postConstruct starts
INFO: I am in myPostConstruct!
INFO: I am in TestLifecycleCallbackInterceptor.postConstruct ends
INFO: I am in postConstruct ------------- ends

I am not getting any error message or anything. Please confirm if the above code is aligned with EJB 3.1 spec.

Thanks & Regards,
Prakash Yaji
Last edited by prakashyaji on Thu May 17, 2012 12:16 pm, edited 1 time in total.

admin
Site Admin
Posts: 10058
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.361 :

Post by admin »

Some times the container does not adhere to the specification strictly so if it is accepting a method with return type as a life cycle method, then the implementation is not fully compliant.

You may find other such instances. It is ok. You need to trust the specification and not what the implementation does.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

prakashyaji
Posts: 25
Joined: Sun May 13, 2012 1:39 am
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.361 :

Post by prakashyaji »

Okay... Thanks!!

fjwalraven
Posts: 429
Joined: Tue Jul 24, 2012 2:43 am
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.361 :

Post by fjwalraven »

The question:
A stateless session bean has a method named cleanup that must be executed before the bean is destroyed. Which of the following is/are correct regarding this bean?
Assume that a deployment descriptor is not used.
doesn't involve any interceptor methods, yet the explanation (referring to the 12.5.1 chapter) talks about interceptor methods.

even the explanation on the wrong answer:
"It will be executed in the transaction and security context of the caller of the @Remove method." talks about Lifecycle callback interceptor methods where I guess you mean Lifecycle callback methods . But the basic explanation that the @Remove is only to be used with Stateful Session Beans is missing...

the wrong answer "It must not throw a system runtime exception." is debatable because if the PreDestroy throws a System Exception, the so called cleanup will not succeed.

Regards,
Frits

admin
Site Admin
Posts: 10058
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.oce-ejbd.v6.2.361 :

Post by admin »

Actually, the specification calls these methods as "Lifecycle Callback Interceptor Methods" and that is why the word interceptor is used in the explanation.

It is true that the cleanup may not succeed if it throws a system exception, but the question is only asking for the cleanup method to be invoked.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 66 guests