0

我有一个 BlazeDS 目标,并且范围设置为请求。有没有办法让 BlazeDS 在请求完成时调用 destroy() ?有没有其他方法可以知道请求何时完成?

我知道我可以使用 finalize(),但只有在垃圾收集发生时才会调用它。

谢谢,马特

4

2 回答 2

0

为什么不能将它附加到请求处理程序的末尾?

于 2009-10-22T18:39:14.763 回答
0

浏览 BlazeDS 源代码后,我想出了如何使用自定义适配器来完成此操作。这是来源。

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);
    }
}
于 2009-10-22T19:05:44.657 回答