⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractconnector.java

📁 jetty SERVER連接資料庫用的軟體
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
//========================================================================//$Id: AbstractConnector.java,v 1.9 2005/11/14 11:00:31 gregwilkins Exp $//Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.//------------------------------------------------------------------------//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 org.mortbay.jetty;import java.io.IOException;import java.net.InetAddress;import java.net.Socket;import java.net.UnknownHostException;import javax.servlet.ServletRequest;import org.mortbay.component.LifeCycle;import org.mortbay.io.EndPoint;import org.mortbay.log.Log;import org.mortbay.thread.ThreadPool;import org.mortbay.util.ajax.Continuation;import org.mortbay.util.ajax.WaitingContinuation;/** Abstract Connector implementation. * This abstract implementation of the Connector interface provides:<ul> * <li>AbstractLifeCycle implementation</li> * <li>Implementations for connector getters and setters</li> * <li>Buffer management</li> * <li>Socket configuration</li> * <li>Base acceptor thread</li> * <li>Optional reverse proxy headers checking</li> * </ul> *  * @author gregw * * TODO - allow multiple Acceptor threads */public abstract class AbstractConnector extends AbstractBuffers implements Connector{    private String _name;        private Server _server;    private ThreadPool _threadPool;    private String _host;    private int _port=0;    private String _integralScheme=HttpSchemes.HTTPS;    private int _integralPort=0;    private String _confidentialScheme=HttpSchemes.HTTPS;    private int _confidentialPort=0;    private int _acceptQueueSize=0;    private int _acceptors=1;    private int _acceptorPriorityOffset=0;    private boolean _useDNS;    private boolean _forwarded;    private String _hostHeader;    private String _forwardedHostHeader = "X-Forwarded-Host";             // default to mod_proxy_http header    private String _forwardedServerHeader = "X-Forwarded-Server";         // default to mod_proxy_http header    private String _forwardedForHeader = "X-Forwarded-For";               // default to mod_proxy_http header    private boolean _reuseAddress=true;        protected int _maxIdleTime=200000;     protected int _lowResourceMaxIdleTime=-1;     protected int _soLingerTime=-1;         private transient Thread[] _acceptorThread;        Object _statsLock = new Object();    transient long _statsStartedAt=-1;    transient int _requests;    transient int _connections;                  // total number of connections made to server        transient int _connectionsOpen;              // number of connections currently open    transient int _connectionsOpenMin;           // min number of connections open simultaneously    transient int _connectionsOpenMax;           // max number of connections open simultaneously        transient long _connectionsDurationMin;      // min duration of a connection    transient long _connectionsDurationMax;      // max duration of a connection    transient long _connectionsDurationTotal;    // total duration of all coneection        transient int _connectionsRequestsMin;       // min requests per connection    transient int _connectionsRequestsMax;       // max requests per connection        /* ------------------------------------------------------------------------------- */    /**      */    public AbstractConnector()    {    }    /* ------------------------------------------------------------------------------- */    /*     */    public Server getServer()    {        return _server;    }    /* ------------------------------------------------------------------------------- */    public void setServer(Server server)    {        _server=server;    }        /* ------------------------------------------------------------------------------- */    /*     * @see org.mortbay.jetty.HttpListener#getHttpServer()     */    public ThreadPool getThreadPool()    {        return _threadPool;    }    /* ------------------------------------------------------------------------------- */    public void setThreadPool(ThreadPool pool)    {        _threadPool=pool;    }        /* ------------------------------------------------------------------------------- */    /**     */    public void setHost(String host)     {        _host=host;    }    /* ------------------------------------------------------------------------------- */    /*     */    public String getHost()    {        return _host;    }    /* ------------------------------------------------------------------------------- */    /*     * @see org.mortbay.jetty.HttpListener#setPort(int)     */    public void setPort(int port)    {        _port=port;    }    /* ------------------------------------------------------------------------------- */    /*     * @see org.mortbay.jetty.HttpListener#getPort()     */    public int getPort()    {        return _port;    }        /* ------------------------------------------------------------ */    /**     * @return Returns the maxIdleTime.     */    public int getMaxIdleTime()    {        return _maxIdleTime;    }        /* ------------------------------------------------------------ */    /**     * Set the maximum Idle time for a connection, which roughly translates     * to the {@link Socket#setSoTimeout(int)} call, although with NIO      * implementations other mechanisms may be used to implement the timeout.       * The max idle time is applied:<ul>     * <li>When waiting for a new request to be received on a connection</li>     * <li>When reading the headers and content of a request</li>     * <li>When writing the headers and content of a response</li>     * </ul>     * Jetty interprets this value as the maximum time between some progress being     * made on the connection. So if a single byte is read or written, then the      * timeout (if implemented by jetty) is reset.  However, in many instances,     * the reading/writing is delegated to the JVM, and the semantic is more     * strictly enforced as the maximum time a single read/write operation can     * take.  Note, that as Jetty supports writes of memory mapped file buffers,     * then a write may take many 10s of seconds for large content written to a      * slow device.     * <p>     * Previously, Jetty supported separate idle timeouts and IO operation timeouts,     * however the expense of changing the value of soTimeout was significant, so     * these timeouts were merged. With the advent of NIO, it may be possible to     * again differentiate these values (if there is demand).     *      * @param maxIdleTime The maxIdleTime to set.     */    public void setMaxIdleTime(int maxIdleTime)    {        _maxIdleTime = maxIdleTime;    }        /* ------------------------------------------------------------ */    /**     * @return Returns the maxIdleTime.     */    public int getLowResourceMaxIdleTime()    {        return _lowResourceMaxIdleTime;    }        /* ------------------------------------------------------------ */    /**     * @param maxIdleTime The maxIdleTime to set.     */    public void setLowResourceMaxIdleTime(int maxIdleTime)    {        _lowResourceMaxIdleTime = maxIdleTime;    }        /* ------------------------------------------------------------ */    /**     * @return Returns the soLingerTime.     */    public int getSoLingerTime()    {        return _soLingerTime;    }    /* ------------------------------------------------------------ */    /**     * @return Returns the acceptQueueSize.     */    public int getAcceptQueueSize()    {        return _acceptQueueSize;    }    /* ------------------------------------------------------------ */    /**     * @param acceptQueueSize The acceptQueueSize to set.     */    public void setAcceptQueueSize(int acceptQueueSize)    {        _acceptQueueSize = acceptQueueSize;    }        /* ------------------------------------------------------------ */    /**     * @return Returns the number of acceptor threads.     */    public int getAcceptors()    {        return _acceptors;    }    /* ------------------------------------------------------------ */    /**     * @param acceptors The number of acceptor threads to set.     */    public void setAcceptors(int acceptors)    {        _acceptors = acceptors;    }        /* ------------------------------------------------------------ */    /**     * @param soLingerTime The soLingerTime to set or -1 to disable.     */    public void setSoLingerTime(int soLingerTime)    {        _soLingerTime = soLingerTime;    }        /* ------------------------------------------------------------ */    protected void doStart() throws Exception    {        if (_server==null)            throw new IllegalStateException("No server");                // open listener port        open();                super.doStart();                if (_threadPool==null)            _threadPool=_server.getThreadPool();        if (_threadPool!=_server.getThreadPool() && (_threadPool instanceof LifeCycle))            ((LifeCycle)_threadPool).start();                // Start selector thread        synchronized(this)        {            _acceptorThread=new Thread[getAcceptors()];            for (int i=0;i<_acceptorThread.length;i++)            {                if (!_threadPool.dispatch(new Acceptor(i)))                {                    Log.warn("insufficient maxThreads configured for {}",this);                    break;                }            }        }                Log.info("Started {}",this);    }        /* ------------------------------------------------------------ */    protected void doStop() throws Exception    {        try{close();} catch(IOException e) {Log.warn(e);}                if (_threadPool==_server.getThreadPool())            _threadPool=null;        else if (_threadPool instanceof LifeCycle)            ((LifeCycle)_threadPool).stop();                super.doStop();                Thread[] acceptors=null;        synchronized(this)        {            acceptors=_acceptorThread;            _acceptorThread=null;        }        if (acceptors != null)        {            for (int i=0;i<acceptors.length;i++)            {                Thread thread=acceptors[i];                if (thread!=null)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -