httpfactory.java

来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 488 行 · 第 1/2 页

JAVA
488
字号
                new DefaultConnectionListenerFailureHandler(), 
                params);
    }

    /**
     * Create and set the parameters applied to incoming request connections
     */
    public HttpParams newRequestConnectionParams() {
        HttpParams params = new BasicHttpParams();
        params
                .setIntParameter(HttpConnectionParams.SO_TIMEOUT, requestSocketTimeout)
                .setBooleanParameter(HttpConnectionParams.TCP_NODELAY, requestTcpNoDelay)
                .setIntParameter(HttpConnectionParams.MAX_LINE_LENGTH, 4000)
                .setIntParameter(HttpConnectionParams.MAX_HEADER_COUNT, 500)
                .setIntParameter(HttpConnectionParams.SOCKET_BUFFER_SIZE, 8 * 1024)
                .setParameter(HttpProtocolParams.ORIGIN_SERVER, originServer);
        return params;
    }

    /**
     * Create the connection manager used to launch request threads
     */
    public HttpConnectionManager newRequestConnectionManager(ExecutorService requestExecutor,
                                                             WorkerFactory workerFactory,
                                                             HttpParams params) {
        return new DefaultHttpConnectionManager(configurationContext, requestExecutor,
                                                workerFactory, params);
    }

    /**
     * Create the executor use the manage request processing threads
     */
    public ExecutorService newRequestExecutor(int port) {
        return new ThreadPoolExecutor(requestCoreThreadPoolSize, requestMaxThreadPoolSize,
                                      threadKeepAliveTime, threadKeepAliveTimeUnit,
                                      newRequestBlockingQueue(),
                                      new DefaultThreadFactory(
                                              new ThreadGroup("Connection thread group"),
                                              "HttpConnection-" + port));
    }

    /**
     * Create the queue used to hold incoming requests when requestCoreThreadPoolSize threads are busy.
     * Default is an unbounded queue.
     */
    public BlockingQueue newRequestBlockingQueue() {
        return new LinkedBlockingQueue();
    }

    /**
     * Create the factory for request workers
     */
    public WorkerFactory newRequestWorkerFactory() {
        if (requestWorkerFactory != null) {
            return requestWorkerFactory;
        } else {
            return new HTTPWorkerFactory();
        }
    }

    public HttpProcessor newHttpProcessor() {
        BasicHttpProcessor httpProcessor = new BasicHttpProcessor();
        httpProcessor.addInterceptor(new RequestSessionCookie());
        httpProcessor.addInterceptor(new ResponseDate());
        httpProcessor.addInterceptor(new ResponseServer());
        httpProcessor.addInterceptor(new ResponseContent());
        httpProcessor.addInterceptor(new ResponseConnControl());
        httpProcessor.addInterceptor(new ResponseSessionCookie());
        return httpProcessor;
    }

    public ConnectionReuseStrategy newConnStrategy() {
        return new DefaultConnectionReuseStrategy();
    }

    public HttpResponseFactory newResponseFactory() {
        return new DefaultHttpResponseFactory();
    }

    // *****
    // Getters and Setters
    // *****

    /**
     * Getter for configurationContext
     */
    public ConfigurationContext getConfigurationContext() {
        return configurationContext;
    }

    /**
     * Getter for httpConfiguration
     */
    public TransportInDescription getHttpConfiguration() {
        return httpConfiguration;
    }

    /**
     * Getter for port
     * return the port on which to listen for http connections (default = 6060)
     */
    public int getPort() {
        return port;
    }

    /**
     * Setter for port
     */
    public void setPort(int port) {
        this.port = port;
    }

    /**
     * Getter for hostAddress
     *
     * @return the host address (or name) to be use in reply-to endpoint references, or null if not specified (default = null)
     */
    public String getHostAddress() {
        return hostAddress;
    }

    /**
     * Setter for hostAddress
     */
    public void setHostAddress(String hostAddress) {
        this.hostAddress = hostAddress;
    }

    /**
     * Getter for originServer
     *
     * @return the Server header string for outgoing messages (default "Simple-Server/1.1")
     */
    public String getOriginServer() {
        return originServer;
    }

    /**
     * Setter for originServer
     */
    public void setOriginServer(String originServer) {
        this.originServer = originServer;
    }

    /**
     * Getter for requestSocketTimeout
     *
     * @return the maximum time in millis to wait for data on a request socket (default 20000)
     */
    public int getRequestSocketTimeout() {
        return requestSocketTimeout;
    }

    /**
     * Setter for requestSocketTimeout
     */
    public void setRequestSocketTimeout(int requestSocketTimeout) {
        this.requestSocketTimeout = requestSocketTimeout;
    }

    /**
     * Getter for requestTcpNoDelay
     * return false iff Nagle's algorithm should be used to conserve bandwidth by minimizing segments
     * at the cost of latency and performance (default true, i.e. maximize performance at
     * the cost of bandwidth)
     */
    public boolean getRequestTcpNoDelay() {
        return requestTcpNoDelay;
    }

    /**
     * Setter for requestTcpNoDelay
     */
    public void setRequestTcpNoDelay(boolean requestTcpNoDelay) {
        this.requestTcpNoDelay = requestTcpNoDelay;
    }

    /**
     * Getter for RequestCoreThreadPoolSize
     *
     * @return the size of the thread pool use to process requests assuming there is adequate queue space (default 25)
     */
    public int getRequestCoreThreadPoolSize() {
        return requestCoreThreadPoolSize;
    }

    /**
     * Setter for RequestCoreThreadPoolSize
     */
    public void setRequestCoreThreadPoolSize(int requestCoreThreadPoolSize) {
        this.requestCoreThreadPoolSize = requestCoreThreadPoolSize;
    }

    /**
     * Getter for requestMaxThreadPoolSize
     *
     * @return the maximum size of the thread pool used to process requests if the queue fills up (default 150).
     *         Since the default queue is unbounded this parameter is meaningless unless you override newRequestBlockingQueue()
     */
    public int getRequestMaxThreadPoolSize() {
        return requestMaxThreadPoolSize;
    }

    /**
     * Setter for requestMaxThreadPoolSize
     */
    public void setRequestMaxThreadPoolSize(int requestMaxThreadPoolSize) {
        this.requestMaxThreadPoolSize = requestMaxThreadPoolSize;
    }

    /**
     * Getter for threadKeepAliveTime
     *
     * @return how long a request processing thread in excess of the core pool size will be kept alive it if is inactive
     *         (default with threadKeepAliveTimeUnit to 180 seconds)
     */
    public long getThreadKeepAliveTime() {
        return threadKeepAliveTime;
    }

    /**
     * Setter for threadKeepAliveTime
     */
    public void setThreadKeepAliveTime(long threadKeepAliveTime) {
        this.threadKeepAliveTime = threadKeepAliveTime;
    }

    /**
     * Getter for threadKeepAliveTimeUnit
     * return the time unit for threadKeepAliveTime (default SECONDS)
     */
    public TimeUnit getThreadKeepAliveTimeUnit() {
        return threadKeepAliveTimeUnit;
    }

    /**
     * Setter for threadKeepAliveTimeUnit
     */
    public void setThreadKeepAliveTimeUnit(TimeUnit threadKeepAliveTimeUnit) {
        this.threadKeepAliveTimeUnit = threadKeepAliveTimeUnit;
    }

}

⌨️ 快捷键说明

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