0

Help me in the following code and how to used the backup on the Hazelcast migration of the hazelcast 3.x.x to 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<K,V> implements EntryProcessor<K,V> {

    private final EntryBackupProcessor<K,V> 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<k,V>, HazelcastInstanceAware {
        // generated for EntryBackupProcessorImpl which doesn't implement HazelcastInstanceAware
        static final long serialVersionUID = -5081502753526394129L;

        @Override
        public void processBackup(Map.Entry<K,V> entry) {
            process(entry);
        }

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

How to used the backup methods in 5.x.x versons of series

how to used the backup in the above question ?

Deepak_M
  • 11
  • 4

1 Answers1

1

This should work:

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;
    }
}
mrck
  • 328
  • 1
  • 8
  • Bur problem is that AbstractEntryProcessor is not present in the 5.x.x version – Deepak_M Dec 26 '22 at 01:55
  • You can implement it yourself, updated answer accordingly. – mrck Dec 26 '22 at 07:20
  • Thanks @mrck for the code i'm very thankful to you and i have two doubts related to this code 1 can you please check it once my code i have done some edits and update your code according it Please 2 can you please tell the logic of setHazelcastInstance and Now in 5.x.x series we are using 3 vars in EntryProcessor – Deepak_M Dec 29 '22 at 17:20
  • please help me in the above link https://stackoverflow.com/questions/74970544/what-is-the-alternate-of-hz-proxy-server-client-xml-for-5-x-x-series-using-jav – Deepak_M Dec 31 '22 at 15:37
  • https://hazelcastcommunity.slack.com/archives/C015Q2TUBKL/p1673806027368409 Please mrck take a look Please – Deepak_M Jan 15 '23 at 18:08