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;
018
019import org.apache.juneau.commons.inject.*;
020
021/**
022 * The {@code ReactiveResponse.*} settings for {@link ReactiveResponseProcessor}, resolved as a single bound object.
023 *
024 * <p>
025 * Values are resolved from the standard {@link org.apache.juneau.commons.settings.Settings Settings} source chain
026 * (system properties, environment, registered property sources) as well as any
027 * {@link org.apache.juneau.commons.settings.PropertySource PropertySource} beans registered in the resource's bean
028 * store, so a resource's {@code @Rest(config=...)} file can set a {@code ReactiveResponse.*} key. Relaxed key matching
029 * is enabled.
030 *
031 * <p>
032 * The bound instance is retrievable from the resource bean store via
033 * {@code beanStore().getBean(ReactiveResponseProperties.class)}; registering your own instance there overrides the
034 * settings.
035 *
036 * <h2 class='topic'>Settings</h2>
037 * <ul>
038 *    <li>{@code ReactiveResponse.maxBufferedElements} &mdash; the maximum number of elements collected for a
039 *       buffered (non-streaming) response. Default {@code 10000}. A value less than {@code 1} selects the default.
040 * </ul>
041 *
042 * @since 10.0.0
043 */
044@ConfigProperties(prefix = "ReactiveResponse")
045@SuppressWarnings({
046   "java:S9438" // Fields are bound reflectively from config sources by @ConfigProperties; making them final breaks binding.
047})
048public class ReactiveResponseProperties {
049
050   /** The default value of {@link #getMaxBufferedElements()}. */
051   public static final int DEFAULT_MAX_BUFFERED_ELEMENTS = 10_000;
052
053   private int maxBufferedElements = DEFAULT_MAX_BUFFERED_ELEMENTS;
054
055   /**
056    * The maximum number of elements a buffered response may collect.
057    *
058    * <p>
059    * When a publisher emits more elements than this limit, its subscription is cancelled and the request fails with a
060    * {@code 500} response; the response is never silently truncated.
061    *
062    * @return The limit. Always at least {@code 1}.
063    */
064   public int getMaxBufferedElements() {
065      return maxBufferedElements < 1 ? DEFAULT_MAX_BUFFERED_ELEMENTS : maxBufferedElements;
066   }
067}