-
Notifications
You must be signed in to change notification settings - Fork 202
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
[Part 12] Calling Source::close, Sink::close as part of stage execution #163
Changes from 1 commit
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 |
---|---|---|
|
@@ -24,27 +24,34 @@ | |
import io.mantisrx.runtime.StageConfig; | ||
import io.mantisrx.runtime.sink.Sink; | ||
import io.reactivex.mantis.remote.observable.RxMetrics; | ||
import java.io.IOException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import rx.Observable; | ||
import rx.Subscriber; | ||
import rx.Subscription; | ||
import rx.functions.Action0; | ||
import rx.functions.Action1; | ||
|
||
|
||
public class SinkPublisher<T, R> implements WorkerPublisher<T, R> { | ||
/** | ||
* Implementation that publishes the results of a stage to a sink such as an SSE port. | ||
* @param <T> | ||
*/ | ||
public class SinkPublisher<T> implements WorkerPublisher<T> { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(SinkPublisher.class); | ||
private SinkHolder<R> sinkHolder; | ||
private PortSelector portSelector; | ||
private Context context; | ||
private Action0 observableTerminatedCallback; | ||
private Action0 onSubscribeAction; | ||
private Action0 onUnsubscribeAction; | ||
private Action0 observableOnCompleteCallback; | ||
private Action1<Throwable> observableOnErrorCallback; | ||
private final SinkHolder<T> sinkHolder; | ||
private final PortSelector portSelector; | ||
private final Context context; | ||
private final Action0 observableTerminatedCallback; | ||
private final Action0 onSubscribeAction; | ||
private final Action0 onUnsubscribeAction; | ||
private final Action0 observableOnCompleteCallback; | ||
private final Action1<Throwable> observableOnErrorCallback; | ||
private Subscription eagerSubscription; | ||
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. nit: separate the state from the rest of the fields. 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. done. |
||
private Sink<T> sink; | ||
|
||
public SinkPublisher(SinkHolder<R> sinkHolder, | ||
public SinkPublisher(SinkHolder<T> sinkHolder, | ||
PortSelector portSelector, | ||
Context context, | ||
Action0 observableTerminatedCallback, Action0 onSubscribeAction, Action0 onUnsubscribeAction, | ||
|
@@ -61,9 +68,9 @@ public SinkPublisher(SinkHolder<R> sinkHolder, | |
|
||
@Override | ||
@SuppressWarnings( {"unchecked", "rawtypes"}) | ||
public void start(StageConfig<T, R> stage, | ||
Observable<Observable<R>> observablesToPublish) { | ||
final Sink<R> sink = sinkHolder.getSinkAction(); | ||
public void start(StageConfig<?, T> stage, | ||
Observable<Observable<T>> observablesToPublish) { | ||
sink = sinkHolder.getSinkAction(); | ||
|
||
int sinkPort = -1; | ||
if (sinkHolder.isPortRequested()) { | ||
|
@@ -72,7 +79,7 @@ public void start(StageConfig<T, R> stage, | |
|
||
// apply transform | ||
|
||
Observable<R> merged = Observable.merge(observablesToPublish); | ||
Observable<T> merged = Observable.merge(observablesToPublish); | ||
final Observable wrappedO = merged.lift(new MonitorOperator("worker_sink")); | ||
|
||
Observable o = Observable | ||
|
@@ -101,17 +108,24 @@ public void call() { | |
.share(); | ||
if (context.getWorkerInfo().getDurationType() == MantisJobDurationType.Perpetual) { | ||
// eager subscribe, don't allow unsubscribe back | ||
o.subscribe(); | ||
eagerSubscription = o.subscribe(); | ||
} | ||
sink.init(context); | ||
sink.call(context, new PortRequest(sinkPort), | ||
o); | ||
//o.lift(new DoOnRequestOperator("beforeShare")).share().lift(new DropOperator<>("sink_share"))); | ||
sink.call(context, new PortRequest(sinkPort), o); | ||
} | ||
|
||
@Override | ||
public RxMetrics getMetrics() {return null;} | ||
|
||
@Override | ||
public void stop() {} | ||
public void close() throws IOException { | ||
try { | ||
sink.close(); | ||
} finally { | ||
if (eagerSubscription != null) { | ||
eagerSubscription.unsubscribe(); | ||
eagerSubscription = null; | ||
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. should sink also be set to null eventually? 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. done. |
||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,12 +32,12 @@ | |
import io.reactivex.mantis.remote.observable.DynamicConnectionSet; | ||
import io.reactivex.mantis.remote.observable.EndpointInjector; | ||
import io.reactivex.mantis.remote.observable.reconciliator.Reconciliator; | ||
import java.io.IOException; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import rx.Observable; | ||
|
||
|
||
public class WorkerConsumerRemoteObservable<T, R> implements WorkerConsumer<T, R> { | ||
public class WorkerConsumerRemoteObservable<T, R> implements WorkerConsumer<T> { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(WorkerConsumerRemoteObservable.class); | ||
|
||
|
@@ -55,7 +55,7 @@ public WorkerConsumerRemoteObservable(String name, | |
|
||
@SuppressWarnings( {"rawtypes", "unchecked"}) | ||
@Override | ||
public Observable<Observable<T>> start(StageConfig<T, R> stage) { | ||
public Observable<Observable<T>> start(StageConfig<T, ?> stage) { | ||
if (stage instanceof KeyToKey || stage instanceof KeyToScalar || stage instanceof GroupToScalar || stage instanceof GroupToGroup) { | ||
|
||
logger.info("Remote connection to stage " + name + " is KeyedStage"); | ||
|
@@ -100,6 +100,7 @@ private void registerMetrics(Metrics metrics) { | |
} | ||
|
||
@Override | ||
public void stop() {} | ||
public void close() throws IOException { | ||
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. why is there nothing to close for this executor? 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. I'm guessing the Observable handles most of the behavior under the hood when the unsubscribe occurs. Or just depends on the whole JVM being blown away. |
||
} | ||
|
||
} |
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.
nit: add documentation.
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.
done.