users@glassfish.java.net

Re: EJB3 Remote Referece Thread Safe?

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Thu, 16 Oct 2008 16:57:56 +0200

The intercept method body looks like this:

public Object intercept(Object object, Method method, Object[] args,
MethodProxy methodProxy) throws Throwable {

    Object result;
    if (serviceClass.isAssignableFrom(method.getDeclaringClass())) {
        logger.info(
                "Intercepting" +
                (canTryAgain ? ":" : "-retry:") +
                method + ", args:" + Arrays.toString(args));
    }
    try {
        result = method.invoke(getService(), args);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof NoSuchEJBException && canTryAgain) {
            logger.warning(
                    "Got NoSuchEJBException when calling: " +
                    beanName + ". Giving one more try...");
            canTryAgain = false;
            service = null; //force to lookup the service again
            result = intercept(object, method, args, methodProxy);
        } else {
            if (e.getCause() instanceof NoSuchEJBException) {
                logger.severe(
                        "Got NoSuchEJBException AGAIN when calling: " +
                        beanName + ". no more tries...");
            }
            throw e.getCause();
        }
    } finally {
        canTryAgain = true;
    }
    return result;
}

2008/10/16 Witold Szczerba <pljosh.mail_at_gmail.com>:
> 2008/10/16 <glassfish_at_javadesktop.org>:
>>>What do you mean by "always refresh reference"?
>>
>> Supose that you need to call, [b]very often[/b], ejb3 remote methods from a main frame window, i.e. the window that will be "alive" through the entire live of the application. I this case, you need to get a "fresh reference" (via the way you desire, but all these would lead to a lookup = fresh reference) each time you call a method, in order to follow your implementation:
>
> Well, you can also do the same thing I did - with intercepting
> methods. In my case, when one invokes:
> Services.get(SomeServiceRemote.class)
> I am looking up an object and then wraps it with my special
> interceptor and return something like a proxy.
>
> When you call a business method on that object, it is intercepted.
> When EJB exception is catched (do not remember which exactly), I am
> (under the hood) looking up that object again and reinvoke that method
> again (there is only one retry in my implementation). if secound
> invocation fails, I am giving up and throwing an exception.
>
> So, there is no unnecessary look up when everything is ok, and up to 1
> retry when something goes wrong.
>
> Regards,
> Witold Szczerba
>
>>>>I am creating reference only when I have to perform some action on particular
>>>>session bean it and throw it away when it is not needed.
>> [Message sent by forum member 'abelmj' (abelmj)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=308071
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>>
>>
>