swamirishi commented on PR #8203:
URL: https://github.com/apache/ozone/pull/8203#issuecomment-2932317879
> > ... Any implementation of Spliterator would give the downstream api
users the flexibility to use the object in the way they deem fit may be wanting
to submit the spliterator to a forkjoin pool to do a parallel iteration using
multiple threads. ...
>
> The point here is to minimize the change to the existing code. The new
parallel iterator currently is an experimental feature. Once the parallel
iterator has become stable in the future, we may add `Spliterator` to the API
if there is a need.
Why can't we wrap the iterator inside a spliterator and then return it. Even
if the api tries to use it as a spliterator it would still be an iterator
inside a synchronized spliterator. Something like this, when the flag is
disabled we should be just returning a SynchronizedSpliterator which doesn't
have much logic here. Do you see any risk if we do this @szetszwo
```
import java.util.Iterator;
import java.util.Spliterator;
import java.util.function.Consumer;
public class SynchronizedSpliterator<T> implements Spliterator<T> {
private final Iterator<T> iterator;
public SynchronizedSpliterator(Iterator<T> iterator) {
this.iterator = iterator;
}
@Override
public synchronized boolean tryAdvance(Consumer<? super T> action) {
if (iterator.hasNext()) {
action.accept(iterator.next());
return true;
}
return false;
}
@Override
public Spliterator<T> trySplit() {
return null; // No splitting support
}
@Override
public long estimateSize() {
return Long.MAX_VALUE; // Unknown size
}
@Override
public int characteristics() {
return ORDERED | NONNULL; // Customize as needed
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]