Der Teil meiner Coherence-Konfiguration tangosol-coherence-override.xml funktioniert nicht. Ich kann den Server starten, Daten eingeben und abrufen, aber ich kann keine Daten über CacheLoader abrufen.
Danke.
Stub für CacheLoader
package com.example;
import com.tangosol.net.cache.AbstractCacheLoader;
import java.util.HashMap;
public class DataLoader extends AbstractCacheLoader {
private HashMap<String, String> hashMap;
public DataLoader() {
hashMap = new HashMap<String, String>();
init();
}
private void init() {
hashMap.put("A", "a");
hashMap.put("B", "b");
hashMap.put("C", "c");
hashMap.put("D", "d");
hashMap.put("E", "f");
hashMap.put("F", "g");
}
public Object load(Object key) {
return hashMap.get(key);
}
}
tangosol-kohärenz-überschreibung.xml
<coherence>
<cluster-config>
<member-identity>
<cluster-name>thecluster</cluster-name>
</member-identity>
<multicast-listener>
<!--<address>224.3.6.0</address>-->
<port>9100</port>
<time-to-live>0</time-to-live>
</multicast-listener>
<caching-scheme-mapping>
<cache-mapping>
<cache-name>ABC</cache-name>
<scheme-name>distributed-rxwbm</scheme-name>
</cache-mapping>
</caching-scheme-mapping>
</cluster-config>
<caching-schemes>
<distributed-scheme>
<scheme-name>distributed-rwbm</scheme-name>
<backing-map-scheme>
<read-write-backing-map-scheme>
<internal-cache-scheme>
<local-scheme/>
</internal-cache-scheme>
<cachestore-scheme>
<class-scheme>
<class-name>com.example.DataLoader</class-name>
<init-params>
<init-param>
<param-type>java.lang.String</param-type>
<param-value>{cache-name}</param-value>
</init-param>
</init-params>
</class-scheme>
</cachestore-scheme>
</read-write-backing-map-scheme>
</backing-map-scheme>
</distributed-scheme>
</caching-schemes>
</coherence>
Server starten
package com.example;
import com.tangosol.net.DefaultCacheServer;
import com.tangosol.net.DefaultConfigurableCacheFactory;
public class HelloWorld {
public static void main(String[] args) {
DefaultConfigurableCacheFactory factory;
factory = new DefaultConfigurableCacheFactory();
DefaultCacheServer dcs = new DefaultCacheServer(factory);
dcs.startAndMonitor(5000);
}
}
Daten lesen
package com.example;
import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;
public class Reader {
public static void main(String[] args) {
CacheFactory.ensureCluster();
NamedCache cache = CacheFactory.getCache("ABC");
System.out.println("Value in cache is: " + cache.get("A"));
System.out.println("Value in cache is: " + cache.get("B"));
System.out.println("Value in cache is: " + cache.get("C"));
System.out.println("Value in cache is: " + cache.get("D"));
}
}