使用Mapstore后跟setWriteCoalescing为FALSE时,无法将所有更新存储在商店的密钥上

时间:2015-03-31 00:07:47

标签: multithreading hazelcast

在多线程环境中,使用Entry Processor更新对象的值并使用Mapstore Write后台策略进行持久化。将setWriteCoalescing设置为FALSE,因为我想将所有更新存储在key上。但它只对持久数据库应用最后一次更新。

使用3.4.1 hazelcast版本。

**Map Store Config**:
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setClassName("Class Name");
mapStoreConfig.setEnabled(Boolean.TRUE);
mapStoreConfig.setWriteDelaySeconds(1);
mapStoreConfig.setWriteBatchSize(100);
mapStoreConfig.setWriteCoalescing(false);
mapConfig.setMapStoreConfig(mapStoreConfig);

**AdjustmentStore Implementation**
public class AdjustmentStore implements MapStore<LocationKey, Adjustment> {
    @Override
    public void store(LocationKey key, Adjustment adjustment) {
        System.out.println("Map Store: store");

        RestTemplate restTemplate = new RestTemplate();
        if(adjustment != null) {
                String url = "http://server_name/xxxxxx";
                 try{
                     System.out.println("Map Store: store rest");
                     restTemplate.put(url, ajustment);
                 }
                 catch(Exception ex) {
                     LOG.error(ex.getMessage(), ex);
                     try {
                        throw new Exception("IO error thrown from: " + this.getClass().toString());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                 }
        }
    }}

**Entry Processor Implementation**
@Override
    public Object process(Entry<Key, Adjustment> entry) {
        Adjustment adjustment = entry.getValue();

        if(adjustment == null) {
            adjustment = updatedAdjustment;
        }
        else {
            adjustment.updateAdjustment(updatedAdjustment.getAdjustment());
        }

        entry.setValue(adjustment);

        return adjustment;
    }

1 个答案:

答案 0 :(得分:0)