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
ISPN-8078 Support functional commands in scattered mode #5316
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.infinispan.commons.util; | ||
|
||
import java.util.EnumSet; | ||
import java.util.Set; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.BinaryOperator; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
|
||
public class ArrayCollector implements java.util.stream.Collector<Object, ArrayCollector, ArrayCollector>, Supplier<ArrayCollector> { | ||
private final Object[] array; | ||
private int pos = 0; | ||
|
||
public ArrayCollector(Object[] array) { | ||
this.array = array; | ||
} | ||
|
||
public void add(Object item) { | ||
array[pos] = item; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. calling this method too much could lead into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not much else I could do if the array is not sized properly. |
||
++pos; | ||
} | ||
|
||
@Override | ||
public Supplier<ArrayCollector> supplier() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public ArrayCollector get() { | ||
return this; | ||
} | ||
|
||
@Override | ||
public BiConsumer<ArrayCollector, Object> accumulator() { | ||
return ArrayCollector::add; | ||
} | ||
|
||
@Override | ||
public BinaryOperator<ArrayCollector> combiner() { | ||
return (a1, a2) -> { | ||
throw new UnsupportedOperationException("The stream is not supposed to be parallel"); | ||
}; | ||
} | ||
|
||
@Override | ||
public Function<ArrayCollector, ArrayCollector> finisher() { | ||
return Function.identity(); | ||
} | ||
|
||
@Override | ||
public Set<Characteristics> characteristics() { | ||
return EnumSet.of(Characteristics.IDENTITY_FINISH); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,11 +4,13 @@ | |
import java.io.ObjectInput; | ||
import java.io.ObjectOutput; | ||
import java.util.Collection; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.function.BiConsumer; | ||
|
||
import org.infinispan.commands.CommandInvocationId; | ||
import org.infinispan.commands.Visitor; | ||
import org.infinispan.commons.marshall.MarshallUtil; | ||
import org.infinispan.functional.EntryView.WriteEntryView; | ||
import org.infinispan.container.entries.CacheEntry; | ||
import org.infinispan.context.InvocationContext; | ||
|
@@ -58,7 +60,7 @@ public byte getCommandId() { | |
@Override | ||
public void writeTo(ObjectOutput output) throws IOException { | ||
CommandInvocationId.writeTo(output, commandInvocationId); | ||
output.writeObject(entries); | ||
MarshallUtil.marshallMap(entries, output); | ||
output.writeObject(f); | ||
output.writeBoolean(isForwarded); | ||
Params.writeObject(output, params); | ||
|
@@ -69,7 +71,8 @@ public void writeTo(ObjectOutput output) throws IOException { | |
@Override | ||
public void readFrom(ObjectInput input) throws IOException, ClassNotFoundException { | ||
commandInvocationId = CommandInvocationId.readFrom(input); | ||
entries = (Map<? extends K, ? extends V>) input.readObject(); | ||
// We use LinkedHashMap in order to guarantee the same order of iteration | ||
entries = MarshallUtil.unmarshallMap(input, LinkedHashMap::new); | ||
f = (BiConsumer<V, WriteEntryView<V>>) input.readObject(); | ||
isForwarded = input.readBoolean(); | ||
params = Params.readObject(input); | ||
|
@@ -93,7 +96,8 @@ public Object perform(InvocationContext ctx) throws Throwable { | |
|
||
@Override | ||
public boolean isReturnValueExpected() { | ||
return false; | ||
// Scattered cache always needs some response. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but for this case, the return is null ... isn't it ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In scattered cache it will return an array of InternalCacheValue (after modification), because originator cannot apply the function locally (it does not have the previous version). |
||
return true; | ||
} | ||
|
||
@Override | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this is an utility class now and not a private class, could be nice to test it unitary and document it uses ?