2009-10-22 37 views
0

我有一個BlazeDS目標,範圍設置爲請求。當請求完成時,有沒有辦法讓BlazeDS調用destroy()?是否有另一種方式知道請求何時完成?BlazeDS Destination destroy()?

我知道我可以使用finalize(),但只有在發生垃圾回收時纔會調用它。

謝謝, 馬特

回答

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); 
    } 
} 
+0

無法將此標記爲2天的答案:( – 2009-10-22 19:10:31

0

你爲什麼不能將其連接到請求處理程序的終結?

+0

我在服務中有很多處理程序,但我總是希望destroy()被調用。 – 2009-10-22 18:57:54