001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2010 Sun Microsystems, Inc.
025 *      Portions copyright 2012-2014 ForgeRock AS.
026 */
027
028package org.forgerock.opendj.ldap;
029
030/**
031 * Common options for LDAP listeners.
032 */
033public final class LDAPListenerOptions extends CommonLDAPOptions<LDAPListenerOptions> {
034    private int backlog;
035    private int maxRequestSize;
036
037    /**
038     * Creates a new set of listener options with default settings. SSL will not
039     * be enabled, and a default set of decode options will be used.
040     */
041    public LDAPListenerOptions() {
042        super();
043    }
044
045    /**
046     * Creates a new set of listener options having the same initial set of
047     * options as the provided set of listener options.
048     *
049     * @param options
050     *            The set of listener options to be copied.
051     */
052    public LDAPListenerOptions(final LDAPListenerOptions options) {
053        super(options);
054        this.backlog = options.backlog;
055        this.maxRequestSize = options.maxRequestSize;
056    }
057
058    /**
059     * Returns the maximum queue length for incoming connections requests. If a
060     * connection request arrives when the queue is full, the connection is
061     * refused. If the backlog is less than {@code 1} then a default value of
062     * {@code 50} will be used.
063     *
064     * @return The maximum queue length for incoming connections requests.
065     */
066    public int getBacklog() {
067        return backlog;
068    }
069
070    /**
071     * Returns the maximum request size in bytes for incoming LDAP requests. If
072     * an incoming request exceeds the limit then the connection will be aborted
073     * by the listener. If the limit is less than {@code 1} then a default value
074     * of {@code 5MB} will be used.
075     *
076     * @return The maximum request size in bytes for incoming LDAP requests.
077     */
078    public int getMaxRequestSize() {
079        return maxRequestSize;
080    }
081
082    /**
083     * Sets the maximum queue length for incoming connections requests. If a
084     * connection request arrives when the queue is full, the connection is
085     * refused. If the backlog is less than {@code 1} then a default value of
086     * {@code 50} will be used.
087     *
088     * @param backlog
089     *            The maximum queue length for incoming connections requests.
090     * @return A reference to this LDAP listener options.
091     */
092    public LDAPListenerOptions setBacklog(final int backlog) {
093        this.backlog = backlog;
094        return this;
095    }
096
097    /**
098     * Sets the maximum request size in bytes for incoming LDAP requests. If an
099     * incoming request exceeds the limit then the connection will be aborted by
100     * the listener. If the limit is less than {@code 1} then a default value of
101     * {@code 5MB} will be used.
102     *
103     * @param maxRequestSize
104     *            The maximum request size in bytes for incoming LDAP requests.
105     * @return A reference to this LDAP listener options.
106     */
107    public LDAPListenerOptions setMaxRequestSize(final int maxRequestSize) {
108        this.maxRequestSize = maxRequestSize;
109        return this;
110    }
111
112    @Override
113    LDAPListenerOptions getThis() {
114        return this;
115    }
116}