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。期待你的回答。在此先感謝
如何調試我的類中介? – Roy