All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.rsocket.core.ClientSetup Maven / Gradle / Ivy

There is a newer version: 1.1.4
Show newest version
package io.rsocket.core;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.rsocket.DuplexConnection;
import java.nio.channels.ClosedChannelException;
import reactor.core.publisher.Mono;
import reactor.util.function.Tuple2;
import reactor.util.function.Tuples;

abstract class ClientSetup {
  abstract Mono> init(DuplexConnection connection);
}

class DefaultClientSetup extends ClientSetup {

  @Override
  Mono> init(DuplexConnection connection) {
    return Mono.create(
        sink -> sink.onRequest(__ -> sink.success(Tuples.of(Unpooled.EMPTY_BUFFER, connection))));
  }
}

class ResumableClientSetup extends ClientSetup {

  @Override
  Mono> init(DuplexConnection connection) {
    return Mono.>create(
            sink -> sink.onRequest(__ -> new SetupHandlingDuplexConnection(connection, sink)))
        .or(connection.onClose().then(Mono.error(ClosedChannelException::new)));
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy