環境
- Coherence 3.7.0.0b23397
- Eclipse Java EE IDE for Web Developers.Helios Service Release 1
- Java 6.0 update 18
サンプルソース
会社コードが1のエンティティの価格を30円引くシンプルなEntryProcessorのサンプルです。Entity.java
package com.chirokings.test001;EProcessor.java
import java.io.Serializable;
public class Entity implements Serializable {
private static final long serialVersionUID = 1L;
private int companyCd;
private int price;
public int getCompanyCd() {
return companyCd;
}
public void setCompanyCd(int companyCd) {
this.companyCd = companyCd;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}
package com.chirokings.test001;Run.java
import com.tangosol.util.InvocableMap;
import com.tangosol.util.processor.AbstractProcessor;
public class EProcessor extends AbstractProcessor {
private static final long serialVersionUID = 1L;
@Override
public Object process(InvocableMap.Entry e) {
Entity en = (Entity)e.getValue();
en.setPrice(en.getPrice()-30);
e.setValue(en);
return null;
}
}
package com.chirokings.test001;
import com.tangosol.net.CacheFactory;
import com.tangosol.net.NamedCache;
import com.tangosol.util.filter.EqualsFilter;
public class Run {
public static void main(String[] args) {
NamedCache cache = CacheFactory.getCache("cache");
Entity e = null;
for( int i = 0 ; i < 10 ; i++ ){
e = new Entity();
e.setCompanyCd(i%3);
e.setPrice(i*100);
cache.put("id"+i, e);
}
EProcessor ep1 = new EProcessor();
cache.invokeAll(new EqualsFilter("getCompanyCd",1), ep1 );
System.out.println(((Entity)cache.get("id"+1)).getPrice());
System.out.println(((Entity)cache.get("id"+2)).getPrice());
}
}