0

我的班级调解员代码是:

package wso2.caching;

import org.apache.synapse.MessageContext; 
import org.apache.synapse.mediators.AbstractMediator;
import java.util.Date;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import net.sf.ehcache.Cache;
import net.sf.ehcache.config.CacheConfiguration;


public class CacheMe extends AbstractMediator { 

    String data = "";
    CacheManager cacheManager;
    CacheConfiguration cacheConfiguration;
    Element element;
    private Cache mdmCache;
    boolean firstTime=true;

    public boolean mediate(MessageContext messageContext) {
        System.out.println(new Date() + "FirstTime = " + firstTime);
        data = String.valueOf(messageContext.getProperty("propertyarray"));
        System.out.println("data from proxy service is : " + data);
        cacheData(data);
        messageContext.setProperty("ResultData", "You got Data");
        return true;
    }

    public void cacheData(String data){
        if(firstTime){
        cacheManager  = new CacheManager();
        firstTime=false;
        }
        System.out.println(new Date() + "FirstTime = " + firstTime);
        System.out.println("Checkpoint A");
        //mdmCache = new Cache(getCacheConfiguration("mdmCache"));//test
        cacheManager.addCache("mdmCache");
        System.out.println("Checkpoint B");
        this.mdmCache = cacheManager.getCache("mdmCache");
        System.out.println("Checkpoint C");
        //this.mdmCache = mdmCache;//test
        System.out.println(new Date() + " Generating MDM Data...");
        System.out.println("mdmCache.size(): " + mdmCache.getSize());
        Element eqpElement = new Element("CacheValueKey", data);
        mdmCache.put(eqpElement);
        System.out.println("mdmCache.size(): " + mdmCache.getSize());
        }
}

我在我的 esb 序列中调用这个类调解器,因为最终在代理服务中被调用:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="cacheImplementationSeq">
   <property xmlns:ns="http://org.apache.synapse/xsd" name="propertyarray" expression="$body"/>
   <log level="custom">
      <property xmlns:ns="http://org.apache.synapse/xsd" name="PropertyData" expression="get-property('propertyarray')"/>
   </log>
   <class name="cts.falcon.data.cachable.CacheData"/>
   <property xmlns:ns="http://org.apache.synapse/xsd" name="ResultSet" expression="get-property('ResultData')" scope="default" type="STRING"/>
   <header name="To" action="remove"/>
   <property name="RESPONSE" value="true" scope="default" type="STRING"/>
   <property name="NO_ENTITY_BODY" action="remove" scope="axis2"/>
   <payloadFactory>
      <format>
         <resultSetResponse xmlns:ns1="http://www.cts.falcon.data.cachable/">$1</resultSetResponse>
      </format>
      <args>
         <arg xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('ResultSet')"/>
      </args>
   </payloadFactory>
   <send/>
</sequence>

当我第一次从 try-it 运行我的代理服务时,我的响应被缓存了一个唯一键(它是一个 UUID),当我再次运行我的服务时,我以前的键被一个新键和一个新的响应值替换。我正在寻找的是,如果我的密钥相同,它应该更新缓存,如果我的密钥不同,它应该添加一个新密钥,并且我以前的缓存密钥不应该消失?我正在使用 ehcache1.5.0 jar 来实现插件中 wso2 esb 附带的此功能。期待您的回答。提前致谢

4

1 回答 1

0

问题出在您的班级调解员 .Debug 并找到

于 2013-05-16T09:51:59.873 回答