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