我有一个 BlazeDS 目标,并且范围设置为请求。有没有办法让 BlazeDS 在请求完成时调用 destroy() ?有没有其他方法可以知道请求何时完成?
我知道我可以使用 finalize(),但只有在垃圾收集发生时才会调用它。
谢谢,马特
我有一个 BlazeDS 目标,并且范围设置为请求。有没有办法让 BlazeDS 在请求完成时调用 destroy() ?有没有其他方法可以知道请求何时完成?
我知道我可以使用 finalize(),但只有在垃圾收集发生时才会调用它。
谢谢,马特
为什么不能将它附加到请求处理程序的末尾?
浏览 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);
}
}