首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Mapstore write FALSE并将setWriteCoalescing设置为FALSE时,无法将密钥上的所有更新存储到存储区

使用Mapstore write FALSE并将setWriteCoalescing设置为FALSE时,无法将密钥上的所有更新存储到存储区
EN

Stack Overflow用户
提问于 2015-03-31 08:07:47
回答 1查看 87关注 0票数 0

在多线程环境中,使用入口处理器来更新对象的值,并使用Mapstore的后写策略来持久化。将setWriteCoalescing设置为FALSE,因为我希望将所有更新存储在key上。但它只将最后一次更新应用于persistent DB。

使用3.4.1 hazelcast版本。

代码语言:javascript
复制
**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;
    }
EN

回答 1

Stack Overflow用户

发布于 2015-03-31 17:01:54

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29358435

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档