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

com.jauntsdn.rsocket.RSocketProxy Maven / Gradle / Ivy

There is a newer version: 1.5.4
Show newest version
/*
 * Copyright 2021 - present Maksym Ostroverkhov.
 *
 * 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 com.jauntsdn.rsocket;

import io.netty.buffer.ByteBufAllocator;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import java.util.Optional;
import java.util.concurrent.ScheduledExecutorService;
import org.reactivestreams.Publisher;

public class RSocketProxy implements RSocket, RSocketHandler {
  protected final MessageStreams source;

  public RSocketProxy(MessageStreams source) {
    this.source = source;
  }

  @Override
  public Uni fireAndForget(Message message) {
    return source.fireAndForget(message);
  }

  @Override
  public Uni requestResponse(Message message) {
    return source.requestResponse(message);
  }

  @Override
  public Multi requestStream(Message message) {
    return source.requestStream(message);
  }

  @Override
  public Multi requestChannel(Publisher messages) {
    return source.requestChannel(messages);
  }

  @Override
  public Multi requestChannel(Message message, Publisher messages) {
    MessageStreams s = source;
    if (s instanceof MessageStreamsHandler) {
      return ((MessageStreamsHandler) s).requestChannel(message, messages);
    }
    return s.requestChannel(messages);
  }

  @Override
  public Optional messageFactory() {
    return source.messageFactory();
  }

  @Override
  public Optional scheduler() {
    return source.scheduler();
  }

  @Override
  public Optional coarseScheduler() {
    MessageStreams s = source;
    if (s instanceof RSocket) {
      return ((RSocket) s).coarseScheduler();
    }
    return Optional.empty();
  }

  @Override
  public Optional allocator() {
    return source.allocator();
  }

  @Override
  public void dispose() {
    source.dispose();
  }

  @Override
  public void dispose(String reason, boolean isGraceful) {
    source.dispose(reason, isGraceful);
  }

  @Override
  public boolean isDisposed() {
    return source.isDisposed();
  }

  @Override
  public Uni onClose() {
    return source.onClose();
  }

  @Override
  public Attributes attributes() {
    return source.attributes();
  }

  @Override
  public Uni metadataPush(Message message) {
    MessageStreams s = source;
    if (s instanceof RSocket) {
      return ((RSocket) s).metadataPush(message);
    }
    message.release();
    return Uni.createFrom()
        .failure(
            new UnsupportedOperationException(
                "metadata-push is not supported by source: " + s.getClass().getName()));
  }

  @Override
  public double availability(int rank) {
    MessageStreams s = source;
    if (s instanceof RSocket) {
      return ((RSocket) s).availability(rank);
    }
    return s.isDisposed() ? 0.0 : 1.0;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy