com.aol.cyclops.streams.HotStreamImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cyclops-streams Show documentation
Show all versions of cyclops-streams Show documentation
Sequential Streams and Stream Utilities for Java 8
package com.aol.cyclops.streams;
import java.util.Optional;
import java.util.Queue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.function.Function;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
import uk.co.real_logic.agrona.concurrent.OneToOneConcurrentArrayQueue;
import com.aol.cyclops.sequence.HotStream;
import com.aol.cyclops.sequence.SequenceM;
import com.aol.cyclops.streams.spliterators.ClosingSpliterator;
public class HotStreamImpl implements HotStream{
private final Stream stream;
private final AtomicReferenceArray> connections = new AtomicReferenceArray<>(10);
private final AtomicBoolean open =new AtomicBoolean(true);
private volatile int connected=0;
public HotStreamImpl(Stream stream){
this.stream = stream;
}
public HotStream init(Executor exec){
CompletableFuture.runAsync( ()-> {
stream.forEach(a->{
int local = connected;
for(int i=0;i connect(){
return connect(new OneToOneConcurrentArrayQueue(256));
}
@Override
public SequenceM connect(Queue queue) {
connections.getAndSet(connected, queue);
connected++;
return StreamUtils.sequenceM(StreamSupport.stream(
new ClosingSpliterator(Long.MAX_VALUE, queue,open), false),Optional.empty());
}
@Override
public > R connectTo(Queue queue,Function,R> to) {
return to.apply(connect(queue));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy