<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2010-2013 Ning, Inc.
  ~
  ~ Ning licenses this file to you 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.
  -->

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<Configure id="Server" class="org.eclipse.jetty.server.Server">
    <!-- =============================================================== -->
    <!-- Setup MBean Server early                                        -->
    <!-- =============================================================== -->
    <Call id="MBeanServer" class="java.lang.management.ManagementFactory" name="getPlatformMBeanServer"/>

    <New id="MBeanContainer" class="org.eclipse.jetty.jmx.MBeanContainer">
        <Arg>
            <Ref id="MBeanServer"/>
        </Arg>
    </New>

    <Get id="Container" name="container">
        <Call name="addEventListener">
            <Arg>
                <Ref id="MBeanContainer"/>
            </Arg>
        </Call>
    </Get>

    <!-- =========================================================== -->
    <!-- Server Thread Pool                                          -->
    <!-- =========================================================== -->
    <Set name="ThreadPool">
        <!-- Default queued blocking threadpool -->
        <New class="org.eclipse.jetty.util.thread.QueuedThreadPool">
            <Set name="minThreads">
                <SystemProperty name="xn.server.threads.min" default="10"/>
            </Set>
            <Set name="maxThreads">
                <SystemProperty name="xn.server.threads.max" default="200"/>
            </Set>
        </New>
    </Set>

    <!-- =========================================================== -->
    <!-- Set connectors                                              -->
    <!-- =========================================================== -->

    <!-- Use this connector if NIO is not available. -->
    <Call name="addConnector">
        <Arg>
            <New class="org.eclipse.jetty.server.bio.SocketConnector">
                <Set name="host">
                    <SystemProperty name="jetty.host"/>
                </Set>
                <Set name="port">
                    <SystemProperty name="jetty.port" default="8080"/>
                </Set>
                <Set name="maxIdleTime">300000</Set>
                <Set name="Acceptors">2</Set>
                <Set name="statsOn">true</Set>
                <Set name="confidentialPort">
                    <SystemProperty name="jetty.ssl.port" default="8443"/>
                </Set>
            </New>
        </Arg>
    </Call>

    <Set name="handler">
        <New class="org.eclipse.jetty.server.handler.StatisticsHandler">
            <Set name="handler">
                <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
                    <Set name="handlers">
                        <Array type="org.eclipse.jetty.server.Handler">
                            <Item>
                                <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
                            </Item>
                            <Item>
                                <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
                            </Item>
                            <Item>
                                <New id="RequestLog" class="org.eclipse.jetty.server.handler.RequestLogHandler"/>
                            </Item>
                        </Array>
                    </Set>
                </New>
            </Set>
        </New>
    </Set>

    <Ref id="RequestLog">
        <Set name="requestLog">
            <New id="RequestLogImpl" class="org.eclipse.jetty.server.NCSARequestLog">
                <Arg>
                    <SystemProperty name="jetty.logs" default="./logs"/>/yyyy_mm_dd.request.log
                </Arg>
                <Set name="retainDays">30</Set>
                <Set name="append">true</Set>
                <Set name="extended">false</Set>
                <Set name="LogTimeZone">GMT</Set>
            </New>
        </Set>
    </Ref>

    <Call name="addLifeCycle">
        <Arg>
            <New class="org.eclipse.jetty.deploy.ContextDeployer">
                <Set name="contexts">
                    <Ref id="Contexts"/>
                </Set>
                <Set name="configurationDir">
                    <SystemProperty name="xn.jetty.contextDir" default="contexts"/>
                </Set>
                <Set name="scanInterval">1</Set>
            </New>
        </Arg>
    </Call>

    <!-- =========================================================== -->
    <!-- extra options                                               -->
    <!-- =========================================================== -->
    <Set name="stopAtShutdown">true</Set>
    <Set name="sendServerVersion">false</Set>
    <Set name="sendDateHeader">true</Set>
    <Set name="gracefulShutdown">
        <SystemProperty name="xn.jetty.gracefulShutdownTimeoutInMs" default="1000"/>
    </Set>
</Configure>
