tags:

views:

97

answers:

2

I have a BlazeDS destination and the scope is set to request. Is there a way to get BlazeDS to call destroy() when the request is complete? Is there another way to know when the request is complete?

I know I can use finalize(), but that is only called when garbage collection occurs.

Thanks, Matt

A: 

Why can't you attach it to the end of your request handler?

CookieOfFortune
I have many handlers in the service, but I always want destroy() to be called.
maclema
A: 

After browsing through the BlazeDS source code I figured out how to accomplish this by using a custom adapter. Here is the source.

package mypackage.adapters;

import java.lang.reflect.Method;
import java.util.Vector;

import flex.messaging.services.remoting.RemotingDestination;
import flex.messaging.services.remoting.adapters.JavaAdapter;
import flex.messaging.util.MethodMatcher;

public class MyAdapter extends JavaAdapter {
    protected void saveInstance(Object instance) {
     try {
      MethodMatcher methodMatcher = ((RemotingDestination)getDestination()).getMethodMatcher();
            Method method = methodMatcher.getMethod(instance.getClass(), "destroy", new Vector());
            if ( method != null ) {
             method.invoke(instance);
            }
     }
     catch ( Exception ex ) {
      ex.printStackTrace(System.out);
     }

     super.saveInstance(instance);
    }
}
maclema
Cannot mark this as an answer for 2 days :(
maclema