📄 server.java
字号:
public void removeUserRealm(UserRealm realm) { setUserRealms((UserRealm[])LazyList.removeFromArray(getUserRealms(), realm)); } /* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */ /** * @return Returns the sessionIdManager. */ public SessionIdManager getSessionIdManager() { return _sessionIdManager; } /* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */ /** * @param sessionIdManager The sessionIdManager to set. */ public void setSessionIdManager(SessionIdManager sessionIdManager) { _container.update(this,_sessionIdManager,sessionIdManager, "sessionIdManager",true); _sessionIdManager = sessionIdManager; } /* ------------------------------------------------------------ */ public void setSendServerVersion (boolean sendServerVersion) { _sendServerVersion = sendServerVersion; } /* ------------------------------------------------------------ */ public boolean getSendServerVersion() { return _sendServerVersion; } /* ------------------------------------------------------------ */ /** * @param sendDateHeader */ public void setSendDateHeader(boolean sendDateHeader) { _sendDateHeader = sendDateHeader; } /* ------------------------------------------------------------ */ public boolean getSendDateHeader() { return _sendDateHeader; } /** * Add a LifeCycle object to be started/stopped * along with the Server. * @param c */ public void addLifeCycle (LifeCycle c) { if (c == null) return; if (!_dependentLifeCycles.contains(c)) { _dependentLifeCycles.add(c); _container.addBean(c); } try { if (isStarted()) ((LifeCycle)c).start(); } catch (Exception e) { throw new RuntimeException (e); } } /** * Remove a LifeCycle object to be started/stopped * along with the Server * @param c */ public void removeLifeCycle (LifeCycle c) { if (c == null) return; _dependentLifeCycles.remove(c); _container.removeBean(c); } /* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */ /** * ShutdownHook thread for stopping all servers. * * Thread is hooked first time list of servers is changed. */ private static class ShutdownHookThread extends Thread { private boolean hooked = false; private ArrayList servers = new ArrayList(); /** * Hooks this thread for shutdown. * * @see java.lang.Runtime#addShutdownHook(java.lang.Thread) */ private void createShutdownHook() { if (!Boolean.getBoolean("JETTY_NO_SHUTDOWN_HOOK") && !hooked) { try { Method shutdownHook = java.lang.Runtime.class.getMethod("addShutdownHook", new Class[] { java.lang.Thread.class}); shutdownHook.invoke(Runtime.getRuntime(), new Object[] { this}); this.hooked = true; } catch (Exception e) { if (Log.isDebugEnabled()) Log.debug("No shutdown hook in JVM ", e); } } } /** * Add Server to servers list. */ public boolean add(Server server) { createShutdownHook(); return this.servers.add(server); } /** * Contains Server in servers list? */ public boolean contains(Server server) { return this.servers.contains(server); } /** * Append all Servers from Collection */ public boolean addAll(Collection c) { createShutdownHook(); return this.servers.addAll(c); } /** * Clear list of Servers. */ public void clear() { createShutdownHook(); this.servers.clear(); } /** * Remove Server from list. */ public boolean remove(Server server) { createShutdownHook(); return this.servers.remove(server); } /** * Remove all Servers in Collection from list. */ public boolean removeAll(Collection c) { createShutdownHook(); return this.servers.removeAll(c); } /** * Stop all Servers in list. */ public void run() { setName("Shutdown"); Log.info("Shutdown hook executing"); Iterator it = servers.iterator(); while (it.hasNext()) { Server svr = (Server) it.next(); if (svr == null) continue; try { svr.stop(); } catch (Exception e) { Log.warn(e); } Log.info("Shutdown hook complete"); // Try to avoid JVM crash try { Thread.sleep(1000); } catch (Exception e) { Log.warn(e); } } } } /* ------------------------------------------------------------ */ /** */ public void addHandler(Handler handler) { if (getHandler() == null) setHandler(handler); else if (getHandler() instanceof HandlerCollection) ((HandlerCollection)getHandler()).addHandler(handler); else { HandlerCollection collection=new HandlerCollection(); collection.setHandlers(new Handler[]{getHandler(),handler}); setHandler(collection); } } /* ------------------------------------------------------------ */ /** */ public void removeHandler(Handler handler) { if (getHandler() instanceof HandlerCollection) ((HandlerCollection)getHandler()).removeHandler(handler); } /* ------------------------------------------------------------ */ /** */ public Handler[] getHandlers() { if (getHandler() instanceof HandlerCollection) return ((HandlerCollection)getHandler()).getHandlers(); return null; } /* ------------------------------------------------------------ */ /** */ public void setHandlers(Handler[] handlers) { HandlerCollection collection; if (getHandler() instanceof HandlerCollection) collection=(HandlerCollection)getHandler(); else { collection=new HandlerCollection(); setHandler(collection); } collection.setHandlers(handlers); } /* ------------------------------------------------------------ */ /* * @see org.mortbay.util.AttributesMap#clearAttributes() */ public void clearAttributes() { _attributes.clearAttributes(); } /* ------------------------------------------------------------ */ /* * @see org.mortbay.util.AttributesMap#getAttribute(java.lang.String) */ public Object getAttribute(String name) { return _attributes.getAttribute(name); } /* ------------------------------------------------------------ */ /* * @see org.mortbay.util.AttributesMap#getAttributeNames() */ public Enumeration getAttributeNames() { return AttributesMap.getAttributeNamesCopy(_attributes); } /* ------------------------------------------------------------ */ /* * @see org.mortbay.util.AttributesMap#removeAttribute(java.lang.String) */ public void removeAttribute(String name) { _attributes.removeAttribute(name); } /* ------------------------------------------------------------ */ /* * @see org.mortbay.util.AttributesMap#setAttribute(java.lang.String, java.lang.Object) */ public void setAttribute(String name, Object attribute) { _attributes.setAttribute(name, attribute); } /* ------------------------------------------------------------ */ /** * @return the graceful */ public int getGracefulShutdown() { return _graceful; } /* ------------------------------------------------------------ */ /** * Set graceful shutdown timeout. If set, the {@link #doStop()} method will not immediately stop the * server. Instead, all {@link Connector}s will be closed so that new connections will not be accepted * and all handlers that implement {@link Graceful} will be put into the shutdown mode so that no new requests * will be accepted, but existing requests can complete. The server will then wait the configured timeout * before stopping. * @param timeoutMS the milliseconds to wait for existing request to complete before stopping the server. * */ public void setGracefulShutdown(int timeoutMS) { _graceful=timeoutMS; } /* ------------------------------------------------------------ */ /* A component that can be gracefully shutdown. * Called by doStop if a {@link #setGracefulShutdown} period is set. */ public interface Graceful { public void setShutdown(boolean shutdown); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -