Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make EntryProcessor lambda-friendly #14995

Merged
merged 8 commits into from Jun 3, 2019

Conversation

@mmedenjak
Copy link
Contributor

mmedenjak commented May 7, 2019

AbstractEntryProcessor and EntryBackupProcessor have been removed. Both partition owner and backup replica use EntryProcessor. The return value from the backup entry processor is ignored.

Now, instead of:

        map.executeOnKey(key, new AbstractEntryProcessor<Integer, Employee>() {

            @Override
            public Object process(Map.Entry<Integer, Employee> entry) {
                Employee employee = entry.getValue();
                if (employee == null) {
                    employee = new Employee();
                }
                employee.setSalary(value);
                entry.setValue(employee);
                return null;
            }
        });

We can use lambda:

        map.executeOnKey(key,
                entry -> {
                    Employee employee = entry.getValue();
                    if (employee == null) {
                        employee = new Employee();
                    }
                    employee.setSalary(value);
                    entry.setValue(employee);
                    return null;
                });

Also cleaned up some warnings and used JDK8 features.

Depends on: #14994
EE: hazelcast/hazelcast-enterprise#2954
Fixes: #7028

@mmedenjak mmedenjak added this to the 4.0 milestone May 7, 2019
@mmedenjak mmedenjak force-pushed the mmedenjak:4.0-entry-processor-lambda branch from 8394247 to e470701 May 7, 2019
@@ -2840,7 +2844,8 @@ boolean tryLock(K key, long time, TimeUnit timeunit, long leaseTime, TimeUnit le
* if the write-behind queue has reached its per-node maximum
* capacity.
*/
Map<K, Object> executeOnEntries(EntryProcessor entryProcessor, Predicate predicate);
<R> Map<K, R> executeOnEntries(EntryProcessor<? super K, ? super V, R> entryProcessor,
Predicate<K, V> predicate);

This comment has been minimized.

Copy link
@cangencer

cangencer May 7, 2019

Contributor

I think ? super K, ? super V for Predicate?

This comment has been minimized.

Copy link
@mmedenjak

mmedenjak May 8, 2019

Author Contributor

Predicate and Projection improvements are reserved for a separate PR to keep this one focused and to minimise the number of changed lines as it's already pretty big.

@mmedenjak mmedenjak force-pushed the mmedenjak:4.0-entry-processor-lambda branch from 4db1562 to 86cd46a May 8, 2019
@@ -2840,7 +2848,8 @@ boolean tryLock(K key, long time, TimeUnit timeunit, long leaseTime, TimeUnit le
* if the write-behind queue has reached its per-node maximum
* capacity.
*/
Map<K, Object> executeOnEntries(EntryProcessor entryProcessor, Predicate predicate);
<R> Map<K, R> executeOnEntries(@Nonnull EntryProcessor<? super K, ? super V, R> entryProcessor,
@Nonnull Predicate<K, V> predicate);

This comment has been minimized.

Copy link
@cangencer

cangencer May 9, 2019

Contributor

Predicate<? super K, ? super V>

This comment has been minimized.

Copy link
@mmedenjak

mmedenjak May 9, 2019

Author Contributor

Predicate and Projection improvements are reserved for a separate PR to keep this one focused and to minimise the number of changed lines as it's already pretty big.

Copy link
Contributor

mustafaiman left a comment

I liked the lambda-friendly entry processor 💯

* and backup partitions so you will not lose any data.
* When coding an backup entry processor, you should take that case into
* account, otherwise {@link java.lang.NullPointerException}s can be seen
* since {@link java.util.Map.Entry#getValue()} may return null.

This comment has been minimized.

Copy link
@mustafaiman

mustafaiman May 13, 2019

Contributor

Maybe add a line to say return value of backup entry processor is ignored. People may get confused as they do not know what should be returned from a backup entry processor.

@mmedenjak mmedenjak requested a review from ahmetmircik May 23, 2019
@mmedenjak mmedenjak force-pushed the mmedenjak:4.0-entry-processor-lambda branch from 86cd46a to 3bcfcf8 Jun 3, 2019
Matko Medenjak added 8 commits May 7, 2019
`AbstractEntryProcessor` and `EntryBackupProcessor` have been removed.
Both partition owner and backup replica use `EntryProcessor`. The return
value from the backup entry processor is ignored.

Now, instead of:
  map.executeOnKey(key,
        entry -> {
            Employee employee = entry.getValue();
            if (employee == null) {
                employee = new Employee();
            }
            employee.setSalary(value);
            entry.setValue(employee);
            return null;
        });

We can use lambda:
  map.executeOnKey(key,
        entry -> {
            Employee employee = entry.getValue();
            if (employee == null) {
                employee = new Employee();
            }
            employee.setSalary(value);
            entry.setValue(employee);
            return null;
        });

Also cleaned up some warnings and used JDK8 features.
Matko Medenjak
@mmedenjak mmedenjak force-pushed the mmedenjak:4.0-entry-processor-lambda branch from b3c757c to 937dcd1 Jun 3, 2019
@mmedenjak

This comment has been minimized.

Copy link
Contributor Author

mmedenjak commented Jun 3, 2019

Merging, thanks for the reviews, guys. I have some minor finishing touches but I'll address those in a separate PR to avoid having more merge conflicts on this one and waiting for one more build.

@mmedenjak mmedenjak merged commit 6d37694 into hazelcast:master Jun 3, 2019
1 check passed
1 check passed
default Test PASSed.
Details
@mmedenjak mmedenjak deleted the mmedenjak:4.0-entry-processor-lambda branch Jun 3, 2019
mmedenjak pushed a commit to mmedenjak/hazelcast-reference-manual that referenced this pull request Oct 17, 2019
Addresses interfaces such as:
- EntryProcessor (hazelcast/hazelcast#14995)
- Projection (hazelcast/hazelcast#15204)
- ValueCallback and ValueExtractor (
hazelcast/hazelcast#15216). Changes on
ArgumentParser, ValueCollector, ValueReader are either internal or have
no effect on user code.

Also, added some samples.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.