Signal<T> signal = new Signal<T>(null, discrete); publishTo(signal).forEach(e -> { }, e -> { }, () -> signal.close()); return signal.getDiscrete().stream(); } else { Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); Signal<T> signal = new Signal<T>(null, queue); Subscription sub = source.subscribe(signal::set, i -> { signal.close(); signal.close(); }); return signal.getDiscrete().stream();
/** * @param stream Populate this Signal from a Stream */ public void fromStream(final Stream<T> stream) { stream.forEach(next -> set(next)); }
/** * Set the current value of this signal * * @param newValue Replacement value * @return newValue */ public T set(final T newValue) { if(continuous!=null) continuous.offer(newValue); setDiscreteIfDiff(newValue); return newValue; }
/** * @return Signal backed by a queue */ public static <T> Signal<T> queueBackedSignal() { return new Signal<T>( new Queue<T>( new LinkedBlockingQueue<T>(), null), new Queue<T>( new LinkedBlockingQueue<T>(), null)); }
/** * @return Signal backed by a topic */ public static <T> Signal<T> topicBackedSignal() { return new Signal( new Topic<>(), new Topic<>()); }
public ReactiveSeq<T> changes(){ com.oath.cyclops.async.adapters.Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); Spliterator<T> copy = copy(); Continuation[] contRef ={null}; Signal<T> signal = new Signal<T>(null, queue); AtomicBoolean wip = new AtomicBoolean(false); Continuation cont = new Continuation(()->{ if(wip.compareAndSet(false,true)) { if(!copy.tryAdvance(signal::set)){ signal.close(); return Continuation.empty(); } wip.set(false); } return contRef[0]; }); contRef[0]= cont; queue.addContinuation(cont); return signal.getDiscrete().stream(); }
default ReactiveSeq<T> publishTo(Signal<T>... signals){ return peek(e->{ for(Signal<T> next: signals){ next.set(e); } }); } default ReactiveSeq<T> merge(Adapter<T>... adapters){
/** * @return Signal backed by a queue */ public static <T> Signal<T> queueBackedSignal() { return new Signal<T>( new Queue<T>( new LinkedBlockingQueue<T>(), null), new Queue<T>( new LinkedBlockingQueue<T>(), null)); }
/** * Set the current value of this signal * * @param newValue Replacement value * @return newValue */ public T set(final T newValue) { if(continuous!=null) continuous.offer(newValue); setDiscreteIfDiff(newValue); return newValue; }
Signal<T> signal = new Signal<T>(null, discrete); publishTo(signal).forEach(e -> { }, e -> { }, () -> signal.close()); return signal.getDiscrete().stream(); } else { Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); Signal<T> signal = new Signal<T>(null, queue); Subscription sub = source.subscribe(signal::set, i -> { signal.close(); signal.close(); }); return signal.getDiscrete().stream();
/** * Add a single data point to the queue * * If the queue is a bounded queue and is full, will return false * * @param data Data to add * @return true if successfully added. */ public boolean add(final T data) { try { final boolean result = queue.add((T) nullSafe(data)); if (result) { if (sizeSignal != null) this.sizeSignal.set(queue.size()); } return result; } catch (final IllegalStateException e) { return false; } }
/** * @return Signal backed by a topic */ public static <T> Signal<T> topicBackedSignal() { return new Signal( new Topic<>(), new Topic<>()); }
public ReactiveSeq<T> changes(){ com.oath.cyclops.async.adapters.Queue<T> queue = QueueFactories.<T>unboundedNonBlockingQueue() .build(); Spliterator<T> copy = copy(); Continuation[] contRef ={null}; Signal<T> signal = new Signal<T>(null, queue); AtomicBoolean wip = new AtomicBoolean(false); Continuation cont = new Continuation(()->{ if(wip.compareAndSet(false,true)) { if(!copy.tryAdvance(signal::set)){ signal.close(); return Continuation.empty(); } wip.set(false); } return contRef[0]; }); contRef[0]= cont; queue.addContinuation(cont); return signal.getDiscrete().stream(); }
/** * Offer a single datapoint to this Queue * * If the queue is a bounded queue and is full it will block until space comes available or until * offer time out is reached (default is Integer.MAX_VALUE DAYS). * * @param data * data to add * @return self */ @Override public boolean offer(final T data) { if (!open) { throw new ClosedQueueException(); } try { final boolean result = producerWait.offer(() -> this.queue.offer((T) nullSafe(data), this.offerTimeout, this.offerTimeUnit)); if (sizeSignal != null) this.sizeSignal.set(queue.size()); return result; } catch (final InterruptedException e) { Thread.currentThread() .interrupt(); throw ExceptionSoftener.throwSoftenedException(e); } }
this.sizeSignal.set(queue.size());
/** * @param stream Populate this Signal from a Stream */ public void fromStream(final Stream<T> stream) { stream.forEach(next -> set(next)); }
default ReactiveSeq<T> publishTo(Signal<T>... signals){ return peek(e->{ for(Signal<T> next: signals){ next.set(e); } }); } default ReactiveSeq<T> merge(Adapter<T>... adapters){
/** * Add a single data point to the queue * * If the queue is a bounded queue and is full, will return false * * @param data Data to add * @return true if successfully added. */ public boolean add(final T data) { try { final boolean result = queue.add((T) nullSafe(data)); if (result) { if (sizeSignal != null) this.sizeSignal.set(queue.size()); } return result; } catch (final IllegalStateException e) { return false; } }
/** * Offer a single datapoint to this Queue * * If the queue is a bounded queue and is full it will block until space comes available or until * offer time out is reached (default is Integer.MAX_VALUE DAYS). * * @param data * data to add * @return self */ @Override public boolean offer(final T data) { if (!open) { throw new ClosedQueueException(); } try { final boolean result = producerWait.offer(() -> this.queue.offer((T) nullSafe(data), this.offerTimeout, this.offerTimeUnit)); if (sizeSignal != null) this.sizeSignal.set(queue.size()); return result; } catch (final InterruptedException e) { Thread.currentThread() .interrupt(); throw ExceptionSoftener.throwSoftenedException(e); } }
this.sizeSignal.set(queue.size());