java 如何在5.x.x中为Hazelcast中的备份实现公共AbstractEntryProcessor(boolean applyOnBackup){}

bqucvtff  于 2022-12-28  发布在  Java
关注(0)|答案(1)|浏览(85)

帮助我完成以下代码以及如何在Hazelcast上使用备份将Hazelcast 3.x.x迁移到5.x.x

package com.hazelcast.map;

import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.HazelcastInstanceAware;
import com.hazelcast.nio.serialization.impl.BinaryInterface;

import java.util.Map;
// Interface AbstractEntryProcessor
@BinaryInterface
public abstract class AbstractEntryProcessor implements EntryProcessor {

    private final EntryBackupProcessor entryBackupProcessor;
// Non Parameterize Constructor
    public AbstractEntryProcessor() {
        this(true);
    }
// Parameterize Constructor AbstractEntryProcessor
    public AbstractEntryProcessor(boolean applyOnBackup) {
        if (applyOnBackup) {
            entryBackupProcessor = new EntryBackupProcessorImpl();
        } else {
            entryBackupProcessor = null;
        }
    }
//EntryBackupProcessor
    @Override
    public final EntryBackupProcessor getBackupProcessor() {
        return entryBackupProcessor;
    }
// class EntryBackupProcessorImpl
    private class EntryBackupProcessorImpl implements EntryBackupProcessor, HazelcastInstanceAware {
        // generated for EntryBackupProcessorImpl which doesn't implement HazelcastInstanceAware
        static final long serialVersionUID = -5081502753526394129L;

        @Override
        public void processBackup(Map.Entry entry) {
            process(entry);
        }

        @Override
        public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
            final AbstractEntryProcessor outer = AbstractEntryProcessor.this;
            if (outer instanceof HazelcastInstanceAware) {
                ((HazelcastInstanceAware) outer).setHazelcastInstance(hazelcastInstance);
            }
        }
    }
}

如何在5.x.x系列中使用备份方法
如何使用上题中的备份?

nxowjjhe

nxowjjhe1#

这应该行得通:

public abstract class AbstractEntryProcessor implements EntryProcessor, HazelcastInstanceAware {

    protected transient HazelcastInstance hazelcastInstance;

    private final boolean applyOnBackup;

    // Non Parameterize Constructor
    public AbstractEntryProcessor() {
        this(true);
    }

    // Parameterize Constructor AbstractEntryProcessor
    public AbstractEntryProcessor(boolean applyOnBackup) {
        this.applyOnBackup = applyOnBackup;
    }

    //EntryBackupProcessor
    @Override
    public final EntryProcessor getBackupProcessor() {
        if (!applyOnBackup || this instanceof ReadOnly) {
            return null;
        }

        return this;
    }

    @Override
    public void setHazelcastInstance(HazelcastInstance hazelcastInstance) {
       this.hazelcastInstance = hazelcastInstance;
    }
}

相关问题