Search in sources :

Example 1 with ScalarToGroup

use of io.mantisrx.runtime.ScalarToGroup in project mantis by Netflix.

the class WorkerPublisherRemoteObservable method start.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void start(final StageConfig<T, R> stage, Observable<Observable<R>> toServe) {
    RemoteRxServer.Builder serverBuilder = new RemoteRxServer.Builder();
    if (stage instanceof KeyToKey || stage instanceof ScalarToKey || stage instanceof ScalarToGroup || stage instanceof GroupToGroup) {
        if (runNewW2WserverGroups(jobName)) {
            logger.info("Modern server setup for name: " + name + " type: Keyedstage");
            long expiryTimeInSecs = Long.MAX_VALUE;
            if (stage instanceof KeyToKey) {
                expiryTimeInSecs = ((KeyToKey) stage).getKeyExpireTimeSeconds();
            } else if (stage instanceof ScalarToKey) {
                expiryTimeInSecs = ((ScalarToKey) stage).getKeyExpireTimeSeconds();
            }
            Func1<R, byte[]> valueEncoder = new Func1<R, byte[]>() {

                @Override
                public byte[] call(R t1) {
                    return stage.getOutputCodec().encode(t1);
                }
            };
            Func1<String, byte[]> keyEncoder = new Func1<String, byte[]>() {

                @Override
                public byte[] call(String t1) {
                    return Codecs.string().encode(t1);
                }
            };
            ServerConfig<KeyValuePair<String, R>> config = new ServerConfig.Builder<KeyValuePair<String, R>>().name(name).port(serverPort).metricsRegistry(MetricsRegistry.getInstance()).numQueueConsumers(numConsumerThreads()).maxChunkSize(maxChunkSize()).maxChunkTimeMSec(maxChunkTimeMSec()).bufferCapacity(bufferCapacity()).useSpscQueue(useSpsc()).router(Routers.consistentHashingLegacyTcpProtocol(jobName, keyEncoder, valueEncoder)).build();
            // remove type
            Observable go = toServe;
            if (stage instanceof ScalarToGroup || stage instanceof GroupToGroup) {
                final LegacyTcpPushServer<KeyValuePair<String, R>> modernServer = PushServers.infiniteStreamLegacyTcpNestedMantisGroup(config, go, expiryTimeInSecs, keyEncoder, io.reactivex.mantis.network.push.HashFunctions.ketama());
                modernServer.start();
                // support legacy server interface
                this.server = new RemoteRxServer() {

                    @Override
                    public void start() {
                    }

                    @Override
                    public void startAndWait() {
                    }

                    @Override
                    public void shutdown() {
                        modernServer.shutdown();
                    }

                    @Override
                    public void blockUntilServerShutdown() {
                        modernServer.blockUntilShutdown();
                    }
                };
            } else {
                // ScalarToKey or KeyTKey
                final LegacyTcpPushServer<KeyValuePair<String, R>> modernServer = PushServers.infiniteStreamLegacyTcpNestedGroupedObservable(config, go, expiryTimeInSecs, keyEncoder, io.reactivex.mantis.network.push.HashFunctions.ketama());
                modernServer.start();
                // support legacy server interface
                this.server = new RemoteRxServer() {

                    @Override
                    public void start() {
                    }

                    @Override
                    public void startAndWait() {
                    }

                    @Override
                    public void shutdown() {
                        modernServer.shutdown();
                    }

                    @Override
                    public void blockUntilServerShutdown() {
                        modernServer.blockUntilShutdown();
                    }
                };
            }
        }
    } else if (stage instanceof ScalarToScalar || stage instanceof KeyToScalar || stage instanceof GroupToScalar) {
        if (runNewW2Wserver(jobName)) {
            logger.info("Modern server setup for name: " + name + " type: Scalarstage");
            Func1<R, byte[]> encoder = new Func1<R, byte[]>() {

                @Override
                public byte[] call(R t1) {
                    return stage.getOutputCodec().encode(t1);
                }
            };
            ServerConfig<R> config = new ServerConfig.Builder<R>().name(name).port(serverPort).metricsRegistry(MetricsRegistry.getInstance()).router(Routers.roundRobinLegacyTcpProtocol(name, encoder)).build();
            final LegacyTcpPushServer<R> modernServer = PushServers.infiniteStreamLegacyTcpNested(config, toServe);
            modernServer.start();
            // support legacy server interface
            this.server = new RemoteRxServer() {

                @Override
                public void start() {
                }

                @Override
                public void startAndWait() {
                }

                @Override
                public void shutdown() {
                    modernServer.shutdown();
                }

                @Override
                public void blockUntilServerShutdown() {
                    modernServer.blockUntilShutdown();
                }
            };
        } else {
            logger.info("Legacy server setup for name: " + name + " type: Scalarstage");
            RoundRobin slotting = new RoundRobin();
            serverBuilder.addObservable(new ServeNestedObservable.Builder().name(name).encoder(stage.getOutputCodec()).observable(toServe).slottingStrategy(slotting).build());
            MetricsRegistry.getInstance().registerAndGet(slotting.getMetrics());
            server = serverBuilder.port(serverPort).build();
            server.start();
        }
    } else {
        throw new RuntimeException("Unsupported stage type: " + stage);
    }
}
Also used : ScalarToGroup(io.mantisrx.runtime.ScalarToGroup) GroupToScalar(io.mantisrx.runtime.GroupToScalar) ServerConfig(io.reactivex.mantis.network.push.ServerConfig) ScalarToScalar(io.mantisrx.runtime.ScalarToScalar) Func1(rx.functions.Func1) KeyValuePair(io.reactivex.mantis.network.push.KeyValuePair) ScalarToKey(io.mantisrx.runtime.ScalarToKey) LegacyTcpPushServer(io.reactivex.mantis.network.push.LegacyTcpPushServer) RemoteRxServer(io.reactivex.mantis.remote.observable.RemoteRxServer) KeyToScalar(io.mantisrx.runtime.KeyToScalar) ServeNestedObservable(io.reactivex.mantis.remote.observable.ServeNestedObservable) Observable(rx.Observable) GroupToGroup(io.mantisrx.runtime.GroupToGroup) RoundRobin(io.reactivex.mantis.remote.observable.slotting.RoundRobin) ServeNestedObservable(io.reactivex.mantis.remote.observable.ServeNestedObservable) KeyToKey(io.mantisrx.runtime.KeyToKey)

Example 2 with ScalarToGroup

use of io.mantisrx.runtime.ScalarToGroup in project mantis by Netflix.

the class StageExecutors method executeIntermediate.

@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T, R> void executeIntermediate(WorkerConsumer consumer, final StageConfig<T, R> stage, WorkerPublisher publisher, final Context context) {
    if (consumer == null) {
        throw new IllegalArgumentException("consumer cannot be null");
    }
    if (stage == null) {
        throw new IllegalArgumentException("stage cannot be null");
    }
    if (publisher == null) {
        throw new IllegalArgumentException("producer cannot be null");
    }
    Observable<?> toSink = null;
    if (stage instanceof ScalarToScalar) {
        ScalarToScalar scalarStage = (ScalarToScalar) stage;
        Observable<Observable<T>> source = consumer.start(scalarStage);
        toSink = setupScalarToScalarStage(scalarStage, source, context);
    } else if (stage instanceof ScalarToKey) {
        ScalarToKey scalarStage = (ScalarToKey) stage;
        Observable<Observable<T>> source = consumer.start(scalarStage);
        toSink = setupScalarToKeyStage(scalarStage, source, context);
    } else // NJ
    if (stage instanceof ScalarToGroup) {
        ScalarToGroup scalarStage = (ScalarToGroup) stage;
        Observable<Observable<T>> source = consumer.start(scalarStage);
        toSink = setupScalarToGroupStage(scalarStage, source, context);
    } else if (stage instanceof KeyToKey) {
        KeyToKey keyToKey = (KeyToKey) stage;
        Observable<Observable<GroupedObservable<String, T>>> source = consumer.start(keyToKey);
        toSink = setupKeyToKeyStage(keyToKey, source, context);
    } else if (stage instanceof GroupToGroup) {
        GroupToGroup groupToGroup = (GroupToGroup) stage;
        Observable<Observable<MantisGroup<String, T>>> source = consumer.start(groupToGroup);
        toSink = setupGroupToGroupStage(groupToGroup, source, context);
    } else if (stage instanceof KeyToScalar) {
        KeyToScalar scalarToKey = (KeyToScalar) stage;
        Observable<Observable<MantisGroup<String, T>>> source = consumer.start(scalarToKey);
        toSink = setupKeyToScalarStage(scalarToKey, source, context);
    } else if (stage instanceof GroupToScalar) {
        GroupToScalar groupToScalar = (GroupToScalar) stage;
        Observable<Observable<MantisGroup<String, T>>> source = consumer.start(groupToScalar);
        toSink = setupGroupToScalarStage(groupToScalar, source, context);
    }
    publisher.start(stage, toSink);
}
Also used : ScalarToGroup(io.mantisrx.runtime.ScalarToGroup) ScalarToKey(io.mantisrx.runtime.ScalarToKey) MantisGroup(io.mantisrx.common.MantisGroup) KeyToScalar(io.mantisrx.runtime.KeyToScalar) Observable(rx.Observable) GroupedObservable(rx.observables.GroupedObservable) GroupToScalar(io.mantisrx.runtime.GroupToScalar) ScalarToScalar(io.mantisrx.runtime.ScalarToScalar) GroupToGroup(io.mantisrx.runtime.GroupToGroup) KeyToKey(io.mantisrx.runtime.KeyToKey) GroupedObservable(rx.observables.GroupedObservable)

Aggregations

GroupToGroup (io.mantisrx.runtime.GroupToGroup)2 GroupToScalar (io.mantisrx.runtime.GroupToScalar)2 KeyToKey (io.mantisrx.runtime.KeyToKey)2 KeyToScalar (io.mantisrx.runtime.KeyToScalar)2 ScalarToGroup (io.mantisrx.runtime.ScalarToGroup)2 ScalarToKey (io.mantisrx.runtime.ScalarToKey)2 ScalarToScalar (io.mantisrx.runtime.ScalarToScalar)2 Observable (rx.Observable)2 MantisGroup (io.mantisrx.common.MantisGroup)1 KeyValuePair (io.reactivex.mantis.network.push.KeyValuePair)1 LegacyTcpPushServer (io.reactivex.mantis.network.push.LegacyTcpPushServer)1 ServerConfig (io.reactivex.mantis.network.push.ServerConfig)1 RemoteRxServer (io.reactivex.mantis.remote.observable.RemoteRxServer)1 ServeNestedObservable (io.reactivex.mantis.remote.observable.ServeNestedObservable)1 RoundRobin (io.reactivex.mantis.remote.observable.slotting.RoundRobin)1 Func1 (rx.functions.Func1)1 GroupedObservable (rx.observables.GroupedObservable)1