001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.juneau.rest.server.reactive.reactor;
018
019import org.apache.juneau.rest.server.reactive.*;
020import org.reactivestreams.*;
021
022/**
023 * Catch-all {@link ReactiveStreamsAdapter} for any
024 * <a class="doclink" href="https://www.reactive-streams.org/">Reactive-Streams</a>
025 * {@link org.reactivestreams.Publisher org.reactivestreams.Publisher&lt;T&gt;} that is not already
026 * handled by a more specific adapter.
027 *
028 * <p>
029 * Converts to a JDK {@link java.util.concurrent.Flow.Publisher Flow.Publisher} via
030 * {@link org.reactivestreams.FlowAdapters#toFlowPublisher(Publisher)} and renders it as a stream.
031 * Registered <em>last</em> so library-specific single-value types (Reactor {@code Mono}, which also
032 * implements {@code Publisher}) are matched by their own adapter first.
033 *
034 * @since 10.0.0
035 */
036public class ReactiveStreamsPublisherAdapter implements ReactiveStreamsAdapter {
037
038   @Override /* Overridden from ReactiveStreamsAdapter */
039   public boolean canAdapt(Object value) {
040      return value instanceof Publisher;
041   }
042
043   @Override /* Overridden from ReactiveStreamsAdapter */
044   public Adaptation adapt(Object value) {
045      return Adaptation.stream(FlowAdapters.toFlowPublisher((Publisher<?>) value));
046   }
047}