Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Copyright 2014 Netflix, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package rx.internal.operators;
import java.util.*;
import java.util.concurrent.TimeUnit;
import rx.*;
import rx.Observable;
import rx.Observable.Operator;
import rx.Observer;
import rx.Scheduler.Worker;
import rx.functions.Action0;
import rx.observers.*;
import rx.subjects.UnicastSubject;
import rx.subscriptions.Subscriptions;
/**
* Creates windows of values into the source sequence with timed window creation, length and size bounds.
* If timespan == timeshift, windows are non-overlapping but always continuous, i.e., when the size bound is reached, a new
* window is opened.
*
*
Note that this conforms the Rx.NET behavior, but does not match former RxJava
* behavior, which operated as a regular buffer and mapped its lists to Observables.
*
* @param the value type
*/
public final class OperatorWindowWithTime implements Operator, T> {
/** Length of each window. */
final long timespan;
/** Period of creating new windows. */
final long timeshift;
final TimeUnit unit;
final Scheduler scheduler;
final int size;
/** Indicate the current subject should complete and a new subject be emitted. */
static final Object NEXT_SUBJECT = new Object();
public OperatorWindowWithTime(long timespan, long timeshift, TimeUnit unit, int size, Scheduler scheduler) {
this.timespan = timespan;
this.timeshift = timeshift;
this.unit = unit;
this.size = size;
this.scheduler = scheduler;
}
@Override
public Subscriber super T> call(Subscriber super Observable> child) {
Worker worker = scheduler.createWorker();
if (timespan == timeshift) {
ExactSubscriber s = new ExactSubscriber(child, worker);
s.add(worker);
s.scheduleExact();
return s;
}
InexactSubscriber s = new InexactSubscriber(child, worker);
s.add(worker);
s.startNewChunk();
s.scheduleChunk();
return s;
}
/** The immutable windowing state with one subject. */
static final class State {
final Observer consumer;
final Observable producer;
final int count;
static final State