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

📄 httpd.java

📁 很棒的web服务器源代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
    public synchronized ResourceReference getEditRoot() {	if ( editroot == null ) {	    // Check for the appropriate property:	    String name = props.getString(EDIT_ROOT_P, null);	    if ( name != null ) {		editroot = loadRoot(name);	    }	    if ( editroot == null ) {		editroot = getRootReference();	    }	}	return editroot;    }    /**     * Get the server URL.     */    public URL getURL() {	if ( url == null ) {	    try {		if ( port != 80 ) 		    url = new URL("http", host, port, "/");		else		    url = new URL("http", host, "/");	    } catch (MalformedURLException ex) {		throw new RuntimeException("unable to build server's URL");	    }	}			return url ;    }    /**     * Get the server software string.     */    public String getSoftware () {	return software;    }    /**     * Get the server local port     */    public int getLocalPort() {	return socket.getLocalPort() ;    }    /**     * Get this server identifier.     */    public String getIdentifier() {	return identifier ;    }    /**     * Get the server inet address     * @return The INET address this server is listening to.     */    public InetAddress getInetAddress() {	return socket.getInetAddress() ;    }    /**     * Get this server root directory.     */    public File getRootDirectory() {	return root_dir ;    }    /**     * Get this server space diretory     */    public File getSpaceDir() {	return space_dir;    }    /**     * Get this server config directory.     */    public File getConfigDirectory() {	File file = props.getFile(CONFIG_P, null);	return (file == null) ? new File(getRootDirectory(), "config") : file;    }    /**     * Get this server authentication directory.     */    public File getAuthDirectory() {	return new File(getConfigDirectory(), "auth");    }    /**     * Get this server store directory.     */    public File getStoreDirectory() {	return new File(getConfigDirectory(), "stores");    }    /**     * Get this server index directory     */    public File getIndexerDirectory() {	return new File(getConfigDirectory(), "indexers");    }    /**     * Get temp directory     */    public File getTempDirectory() {	return new File(getRootDirectory(), "tmp");    }    /**     * Clean the temp dir.     */    protected void cleanTempDirectory() {	org.w3c.util.IO.clean(getTempDirectory());    }    /**     * get the indexer catalog of this server      */    public IndexersCatalog getIndexersCatalog() {	if ( indexers == null )	    indexers = new IndexersCatalog(		new ResourceContext(getDefaultContext()));	return indexers;    }    /**     * Get this server realm catalog.     */    public RealmsCatalog getRealmsCatalog() {	return realms ;    }    /**     * Get this server resourcestore manager.     */    public ResourceStoreManager getResourceStoreManager() {	return manager ;    }    /**     * Get this server resource space     */    public ResourceSpace getResourceSpace() {	return manager ;    }    /**     * Get the default resource context for that server.     */    public ResourceContext getDefaultContext() {	return context;    }    /**     * Get the lenient value, tru if we are lenient in HTTP parsing     */    public boolean isLenient() {	return lenient;    }    /**     * Cleanup the resources associated with this server context.     * This method should only be called by the server thread itself, when     * it is requested to perform the cleanup.     * @param restart If <strong>true</strong> the server is restarted      *     (reinitialized) straight away.     */    protected synchronized void cleanup(boolean restart) {	// Close the accepting socket:	try {	    socket.close() ;	    socket = null ;	} catch (IOException ex) {	    errlog ("[cleanup]: IOException while closing server socket.");	}	// FIXME temporary hack for clones 	synchronized( instances ) {	    // remove one instance	    instances[0]--;         // @wplatzer	    if ( factory != null )		factory.shutdown(true) ;	    factory = null ;	    if ( manager != null && instances[0] == 0) // FIXME (shm)		manager.shutdown() ;	    manager = null ;	    if ( shuffler != null )		shuffler.shutdown() ;	    shuffler = null ;	    // Unregister to property monitoring	    props.unregisterObserver (this) ;	    errlog ("shutdown completed at: "+new Date()+".") ;	    // Finally close the log	    if ( logger != null && instances[0] == 0) // FIXME shm		logger.shutdown() ;	    logger = null ;	    // Release any other pointers:	    timer.stopEventManager() ;	    System.out.println (getIdentifier()+": " + getURL() + " done.") ;	    System.out.flush() ;	// Keep the data neede to reinit (in case needed)	    File init_propfile = props.getFile(PROPS_P, null);	    ObservableProperties init_props = props ;	    String init_identifier = identifier ;	    // Release pointed data:	    identifier = null ;	    manager    = null ;	    factory    = null ;	    shuffler   = null ;	    // FIXME clones props      = null ;	    indexer    = null ;	    root       = null ;	    realms     = null ;	    logger     = null ;	    socket     = null ;	    timer      = null ;	    thread     = null ;	    url        = null ;	    restarting = false ;	    finishing  = false ;	    if ( restart ) {		try {		    instances[0]++; //FIXME clones		    initialize(shm, init_identifier, init_props) ;		    start();		} catch (Exception ex) {		    // We really can't do more than this here:		    System.out.println("*** server restart failed.") ;		    ex.printStackTrace() ;		}	    }	}    }    /**     * Shutdown the server properly.     * This methods shutdown the server, and clean-up all its associated      * resources. If the current thread is not the server thread, it unblocks     * the server thread from its accept() call, and forces it to perform     * the rest of the shutdown operation itself.     * @see httpd#cleanup     */    public synchronized void shutdown () {	checkpoint();	errlog ("shutdown inited...(save done)") ;	finishing = true ;	try {	    Socket unlock = new Socket(host, port) ;	    unlock.close() ;	} catch (IOException ex) {	    errlog("[shutdown]: IOException while unblocking server thread.");	}	shm.removeServerHandler(this);	cleanTempDirectory();    }    /**     * Restart the server properly.     * This methods restarts the server. It cleans-up all its associated      * resources, and reinitialize it from scratch. If the current thread is     * not the server thread, it unblocks     * the server thread from its accept() call, and forces it to perform     * the rest of the restart operation itself.     * @param reload_properties Should we reload the properties from the     *    property file, or should we just reinitialize from the current set     *    of properties.     * @see httpd#cleanup     */    public synchronized void restart () {	errlog ("[restart]: inited !") ;	finishing    = true ;	restarting   = true ;	try {	    Socket unlock = new Socket(host, port) ;	    unlock.close() ;	} catch (IOException ex) {	    errlog ("[restart]: IOException while unblocking server thread.");	}    }    /**     * Turn debugging on/off for this instance of httpd server.     * @param A boolean, true turns debugging on, flase turns it off.     */    public void debug (boolean onoff) {	tracep = onoff ;    }    /**     * Emit a server trace. Traces are used solely for debugging purposes. You     * should either use <b>log</b> or <b>error</b> to report informations.     * @param client The client object which wants to report the trace.     * @param msg The trace message.     * @see httpd#log     */    public void trace (Client client, String msg) {	if ( tracep && (logger != null) )	    logger.trace (client, msg) ;    }    /**     * Emit a server trace, on behalf of the server itself.     * @param msg The trace the server wants to emit.     */    public void trace (String msg) {	if ( tracep && (logger != null))	    logger.trace (msg) ;    }    /**     * Emit a log entry.     * @param client The client whose request is to be logged.     * @param request The request that has been handled.     * @param reply The emitted reply.     * @param nbytes The number of bytes emitted back to the client.     * @param duration The time it took to process the request.     */    public void log (Client client		     , Request request, Reply reply		     , int nbytes		     , long duration) {	if ( logger != null )	    logger.log (request, reply, nbytes, duration) ;	statistics.updateStatistics(client, request, reply, nbytes, duration) ;    }    /**     * Emit a log message.     * @param msg The message to log.     */    public void log(String msg) {	logger.log(msg);    }    /**     * Emit a server error on behalf of some client object.     * @param client The client.     * @param msg The error message.     */    public void errlog (Client client, String msg) {	if ( logger != null )	    logger.errlog(client, msg) ;    }    /**     * Emit an error on behalf of the server.     * @param msg The error message.     */    public void errlog (String msg) {	if ( logger != null )	    logger.errlog ("["+identifier+"] "+msg) ;    }    /**     * The prefered form for reporting errors.     * @param from The object that emited the error.     * @param msg The error message.     */    public void errlog(Object from, String msg) {	if ( logger != null )	    logger.errlog("["+from.getClass().getName()+"]: "+msg);    }    /**     * Another nice way of reporting errors from an HTTPResource.     * @param from The resource that trigered the error.     * @param msg The error message.     */    public void errlog(Resource from, String msg) {	if ( logger != null )	    logger.errlog(from.getClass().getName()+"@"+from.getURLPath()			  + ": " + msg);    }    /**     * Emit a fatal error.     * @param e Any exception that caused the error.     * @param msg Any additional message.     */    public void fatal (Exception e, String msg) {	System.out.println ("*** Fatal Error, aborting") ;	System.out.println (this.getClass().getName() + ": " + msg) ;	e.printStackTrace() ;	throw new RuntimeException (msg) ;    }    /**     * Emit a fatal error.     * @param msg Any error message     */    public void fatal(String msg) {	System.out.println("*** Fatal error, aborting") ;	System.out.println(this.getClass().getName() + ": " + msg) ;	throw new RuntimeException(msg) ;    }	    /**     * Emit a warning.     * Warnings are emited, typically if the configuration is inconsistent,     * and the server can continue its work.     * @param msg The warning message.     */    public void warning (String msg) {	System.out.println ("*** Warning : " + msg) ;    }    /**     * Emit a warning.     * @param e Any exception.     * @param msg Any message.     */    public void warning (Exception e, String msg) {	System.out.println ("*** Warning: " + msg) ;	e.printStackTrace() ;    }

⌨️ 快捷键说明

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