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

📄 warpconnector.java

📁 Tomcat 4.1与WebServer集成组件的源代码包.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *     * @param service The service that owns this Engine     */    public void setService(Service service) {        this.service = service;    }    /**     * Return descriptive information about this <code>Connector</code>.     */    public String getInfo() {        if (this.info==null) {            synchronized(this) {                this.info=this.getClass().getName()+"/"+                          Constants.VERS_MINOR+Constants.VERS_MAJOR;            }        }        return(this.info);    }    /**     * Set descriptive information about this <code>Connector</code>.     */    public void setInfo(String info) {        if (info==null) throw new NullPointerException();        this.info=info;        if (Constants.DEBUG) logger.debug("Setting info to "+info);    }    /**     * Return the IP address to which this <code>Connector</code> will bind to.     */    public String getAddress() {        return(this.address);    }    /**     * Set the IP address to which this <code>Connector</code> will bind to.     *     * @param address The bind IP address     */    public void setAddress(String address) {        this.address=address;        if (Constants.DEBUG) logger.debug("Setting address to "+address);    }    /**     * Return the port to which this <code>Connector</code> will bind to.     */    public int getPort() {        return(this.port);    }    /**     * Set the port to which this <code>Connector</code> will bind to.     *      * @param port The bind port     */    public void setPort(int port) {        this.port=port;    }    /**     * Set the IP address to which this <code>Connector</code> will bind to.     *     * @param address The bind IP address     */    public void setAddress(int port) {        if ((port<1) || (port>65535))            throw new IllegalArgumentException("Invalid port "+port);        this.port=port;        if (Constants.DEBUG) logger.debug("Setting port to "+port);    }    /**     * Return the accept count for this Connector.     */    public int getAcceptCount() {        return (this.acceptCount);    }    /**     * Set the accept count for this Connector.     *     * @param count The new accept count     */    public void setAcceptCount(int count) {        this.acceptCount = count;        if (Constants.DEBUG) logger.debug("Setting acceptCount to "+count);    }    /**     * Get the applications base directory for hosts created via WARP.     */    public String getAppBase() {        return (this.appBase);    }    /**     * Set the applications base directory for hosts created via WARP.     *     * @param appBase The appbase property.     */    public void setAppBase(String appBase) {        this.appBase = appBase;        if (Constants.DEBUG) logger.debug("Setting appBase to "+appBase);    }    /**     * Return the debug level.     */    public int getDebug() {        return(this.debug);    }    /**     * Set the debug level.     */    public void setDebug(int debug) {        this.debug=debug;    }    /* ==================================================================== */    /* Lifecycle methods                                                    */    /* ==================================================================== */    /**     * Add a <code>LifecycleEvent</code> listener to this     * <code>Connector</code>.     *     * @param listener The listener to add     */    public void addLifecycleListener(LifecycleListener listener) {        lifecycle.addLifecycleListener(listener);    }    /**     * Get the lifecycle listeners associated with this lifecycle. If this      * Lifecycle has no listeners registered, a zero-length array is returned.     */    public LifecycleListener[] findLifecycleListeners() {        return null; // FIXME: lifecycle.findLifecycleListeners();    }    /**     * Remove a <code>LifecycleEvent</code> listener from this     * <code>Connector</code>.     *     * @param listener The listener to remove     */    public void removeLifecycleListener(LifecycleListener listener) {        lifecycle.removeLifecycleListener(listener);    }    /**     * Initialize this connector (create ServerSocket here!)     */    public void initialize()    throws LifecycleException {        if (initialized)            throw new LifecycleException("Already initialized");        this.initialized=true;        // Get a hold on a server socket        try {            ServerSocketFactory fact=this.getFactory();            int port=this.getPort();            int accc=this.getAcceptCount();            if (this.getAddress()==null) {                this.server=fact.createSocket(port,accc);            } else {                InetAddress addr=InetAddress.getByName(this.getAddress());                this.server=fact.createSocket(port,accc,addr);            }        } catch (Exception e) {            throw new LifecycleException("Error creating server socket ("+                e.getClass().getName()+")",e);        }    }    /**     * Start accepting connections by this <code>Connector</code>.     */    public void start() throws LifecycleException {        if (!initialized) this.initialize();        if (started) throw new LifecycleException("Already started");        // Can't get a hold of a server socket        if (this.server==null)            throw new LifecycleException("Server socket not created");        lifecycle.fireLifecycleEvent(START_EVENT, null);        this.started = true;        this.thread=new Thread(this);        this.thread.setDaemon(true);        this.thread.start();    }    /**     * Stop accepting connections by this <code>Connector</code>.     */    public void stop() throws LifecycleException {        if (!started) throw new LifecycleException("Not started");        lifecycle.fireLifecycleEvent(STOP_EVENT, null);        this.started = false;        if (this.server!=null) try {            this.server.close();        } catch (IOException e) {            logger.log("Cannot close ServerSocket",e);        }    }    /**     * Check whether this service was started or not.     */    public boolean isStarted() {        return(this.started);    }    /* ==================================================================== */    /* Public methods                                                       */    /* ==================================================================== */    /**     * Return the application ID for a given <code>Context</code>.     */    protected int applicationId(Context context) {        int id=this.applications.indexOf(context);        if (id==-1) {            this.applications.add(context);            id=this.applications.indexOf(context);        }        return(id);    }    /**     * Return the application for a given ID.     */    protected Context applicationContext(int id) {        try {            return((Context)this.applications.elementAt(id));        } catch (ArrayIndexOutOfBoundsException e) {            return(null);        }    }    /**     * Create (or allocate) and return a Request object suitable for     * specifying the contents of a Request to the responsible Container.     */    public Request createRequest() {        return(null);    }    /**     * Create (or allocate) and return a Response object suitable for     * receiving the contents of a Response from the responsible Container.     */    public Response createResponse() {        return(null);    }    /**     * Start accepting WARP requests from the network.     */    public void run() {        // Start accepting connections        try {            while (this.isStarted()) {                Socket sock=this.server.accept();                InetAddress raddr=sock.getInetAddress();                InetAddress laddr=sock.getLocalAddress();                int rport=sock.getPort();                int lport=sock.getLocalPort();                logger.log("Connection from "+raddr+":"+rport+" to "+laddr+                           ":"+lport);                WarpConnection conn=new WarpConnection();                conn.setConnector(this);                conn.setSocket(sock);                this.addLifecycleListener(conn);                conn.start();            }        } catch (IOException e) {            logger.log("Error accepting requests",e);        }    }}

⌨️ 快捷键说明

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