【问题标题】:BlazeDS Destination destroy()?BlazeDS 目的地销毁()?
【发布时间】:2009-10-22 18:13:47
【问题描述】:

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

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

谢谢, 马特

【问题讨论】:

    标签: java apache-flex blazeds


    【解决方案1】:

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

    【讨论】:

    • 我在服务中有很多处理程序,但我总是希望调用destroy()。
    【解决方案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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-24
      • 2020-06-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多