写点什么

avatar Logo

  • 2022 年 4 月 29 日
  • 本文字数:5331 字

    阅读完需:约 17 分钟

public boolean isUseNaming()

{

return this.useNaming;

}

public void setUseNaming(boolean useNaming)

{

this.useNaming = useNaming;

}

public void setAwait(boolean b) {

this.await = b;

}

public boolean isAwait() {

return this.await;

}

protected boolean arguments(String[] args)

{

boolean isConfig = false;

if (args.length < 1) {

usage();

return false;

}

for (int i = 0; i < args.length; i++)

if (isConfig) {

this.configFile = args[i];

isConfig = false;

} else if (args[i].equals("-config")) {

isConfig = true;

} else if (args[i].equals("-nonaming")) {

setUseNaming(false); } else {

if (args[i].equals("-help")) {

usage();

return false;

}if (!args[i].equals("start"))

{

if (!args[i].equals("configtest"))

{

if (!args[i].equals("stop"))

{

**《一线大厂 Java 面试题解析+后端开发学习笔记+最新架构讲解视频+实战项目源码讲义》无偿开源 威信搜索公众号【编程进阶路】**

usage();

return false;

}

}

}

}

return true;

}

protected File configFile()

{

File file = new File(this.configFile);

if (!file.isAbsolute()) {

file = new File(Bootstrap.getCatalinaBase(), this.configFile);

}

return file;

}

protected Digester createStartDigester()

{

long t1 = System.currentTimeMillis();

Digester digester = new Digester();

digester.setValidating(false);

digester.setRulesValidation(true);

HashMap fakeAttributes = new HashMap();

ArrayList attrs = new ArrayList();

attrs.add("className");

fakeAttributes.put(Object.class, attrs);

digester.setFakeAttributes(fakeAttributes);

digester.setUseContextClassLoader(true);

digester.addObjectCreate("Server", "org.apache.catalina.core.StandardServer", "className");

digester.addSetProperties("Server");

digester.addSetNext("Server", "setServer", "org.apache.catalina.Server");

digester.addObjectCreate("Server/GlobalNamingResources", "org.apache.catalina.deploy.NamingResourcesImpl");

digester.addSetProperties("Server/GlobalNamingResources");

digester.addSetNext("Server/GlobalNamingResources", "setGlobalNamingResources", "org.apache.catalina.deploy.NamingResourcesImpl");

digester.addObjectCreate("Server/Listener", null, "className");

digester.addSetProperties("Server/Listener");

digester.addSetNext("Server/Listener", "addLifecycleListener", "org.apache.catalina.LifecycleListener");

digester.addObjectCreate("Server/Service", "org.apache.catalina.core.StandardService", "className");

digester.addSetProperties("Server/Service");

digester.addSetNext("Server/Service", "addService", "org.apache.catalina.Service");

digester.addObjectCreate("Server/Service/Listener", null, "className");

digester.addSetProperties("Server/Service/Listener");

digester.addSetNext("Server/Service/Listener", "addLifecycleListener", "org.apache.catalina.LifecycleListener");

digester.addObjectCreate("Server/Service/Executor", "org.apache.catalina.core.StandardThreadExecutor", "className");

digester.addSetProperties("Server/Service/Executor");

digester.addSetNext("Server/Service/Executor", "addExecutor", "org.apache.catalina.Executor");

digester.addRule("Server/Service/Connector", new ConnectorCreateRule());

digester.addRule("Server/Service/Connector", new SetAllPropertiesRule(new String[] { "executor" }));

digester.addSetNext("Server/Service/Connector", "addConnector", "org.apache.catalina.connector.Connector");

digester.addObjectCreate("Server/Service/Connector/Listener", null, "className");

digester.addSetProperties("Server/Service/Connector/Listener");

digester.addSetNext("Server/Service/Connector/Listener", "addLifecycleListener", "org.apache.catalina.LifecycleListener");

digester.addRuleSet(new NamingRuleSet("Server/GlobalNamingResources/"));

digester.addRuleSet(new EngineRuleSet("Server/Service/"));

digester.addRuleSet(new HostRuleSet("Server/Service/Engine/"));

digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Host/"));

addClusterRuleSet(digester, "Server/Service/Engine/Host/Cluster/");

digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/Host/Context/"));

digester.addRule("Server/Service/Engine", new SetParentClassLoaderRule(this.parentClassLoader));

addClusterRuleSet(digester, "Server/Service/Engine/Cluster/");

long t2 = System.currentTimeMillis();

if (log.isDebugEnabled()) {

log.debug("Digester for server.xml created " + (t2 - t1));

}

return digester;

}

private void addClusterRuleSet(Digester digester, String prefix)

{

Class clazz = null;

Constructor constructor = null;

try {

clazz = Class.forName("org.apache.catalina.ha.ClusterRuleSet");

constructor = clazz.getConstructor(new Class[] { String.class });

RuleSet ruleSet = (RuleSet)constructor.newInstance(new Object[] { prefix });

digester.addRuleSet(ruleSet);

} catch (Exception e) {

if (log.isDebugEnabled()) {

log.debug(sm.getString("catalina.noCluster", new Object[] { e.getClass().getName() + ": " + e.getMessage() }), e);

}

else if (log.isInfoEnabled())

log.info(sm.getString("catalina.noCluster", new Object[] { e.getClass().getName() + ": " + e.getMessage() }));

}

}

protected Digester createStopDigester()

{

Digester digester = new Digester();

digester.setUseContextClassLoader(true);

digester.addObjectCreate("Server", "org.apache.catalina.core.StandardServer", "className");

digester.addSetProperties("Server");

digester.addSetNext("Server", "setServer", "org.apache.catalina.Server");

return digester;

}

public void stopServer()

{

stopServer(null);

}

public void stopServer(String[] arguments)

{

if (arguments != null) {

arguments(arguments);

}

Server s = getServer();

File file;

Throwable localThrowable4;

if (s == null)

{

Digester digester = createStopDigester();

file = configFile();

try { FileInputStream fis = new FileInputStream(file); localThrowable4 = null;

try { InputSource is = new InputSource(file.toURI().toURL().toString());

is.setByteStream(fis);

digester.push(this);

digester.parse(is);

}

catch (Throwable localThrowable1)

{

localThrowable4 = localThrowable1; throw localThrowable1;

}

finally

{

if (fis != null) if (localThrowable4 != null) try { fis.close(); } catch (Throwable x2) { localThrowable4.addSuppressed(x2); } else fis.close();

} } catch (Exception e) { log.error("Catalina.stop: ", e);

System.exit(1); }

}

else

{

try {

s.stop();

} catch (LifecycleException e) {

log.error("Catalina.stop: ", e);

}

return;

}

s = getServer();

if (s.getPort() > 0) {

try { Socket socket = new Socket(s.getAddress(), s.getPort()); file = null;

try { OutputStream stream = socket.getOutputStream();

localThrowable4 = null;

try {

String shutdown = s.getShutdown();

for (int i = 0; i < shutdown.length(); i++) {

stream.write(shutdown.charAt(i));

}

stream.flush();

}

catch (Throwable localThrowable2)

{

localThrowable4 = localThrowable2; throw localThrowable2; } finally { } } catch (Throwable localThrowable3) { file = localThrowable3; throw localThrowable3;

}

finally

{

if (socket != null) if (file != null) try { socket.close(); } catch (Throwable x2) { file.addSuppressed(x2); } else socket.close();

} } catch (ConnectException ce) { log.error(sm.getString("catalina.stopServer.connectException", new Object[] { s.getAddress(), String.valueOf(s.getPort()) }));

log.error("Catalina.stop: ", ce);

System.exit(1);

} catch (IOException e) {

log.error("Catalina.stop: ", e);

System.exit(1);

}

} else {

log.error(sm.getString("catalina.stopServer"));

System.exit(1);

}

}

public void load()

{

long t1 = System.nanoTime();

initDirs();

initNaming();

Digester digester = createStartDigester();

InputSource inputSource = null;

InputStream inputStream = null;

File file = null;

try {

file = configFile();

inputStream = new FileInputStream(file);

inputSource = new InputSource(file.toURI().toURL().toString());

} catch (Exception e) {

if (log.isDebugEnabled()) {

log.debug(sm.getString("catalina.configFail", new Object[] { file }), e);

}

}

if (inputStream == null) {

try {

inputStream = getClass().getClassLoader().getResourceAsStream(getConfigFile());

inputSource = new InputSource(getClass().getClassLoader().getResource(getConfigFile()).toString());

}

catch (Exception e)

{

if (log.isDebugEnabled()) {

log.debug(sm.getString("catalina.configFail", new Object[] { getConfigFile() }), e);

}

}

}

if (inputStream == null) {

try {

inputStream = getClass().getClassLoader().getResourceAsStream("server-embed.xml");

inputSource = new InputSource(getClass().getClassLoader().getResource("server-embed.xml").toString());

}

catch (Exception e)

{

if (log.isDebugEnabled()) {

log.debug(sm.getString("catalina.configFail", new Object[] { "server-embed.xml" }), e);

}

}

}

if ((inputStream == null) || (inputSource == null)) {

if (file == null) {

log.warn(sm.getString("catalina.configFail", new Object[] { getConfigFile() + "] or [server-embed.xml]" }));

}

else {

log.warn(sm.getString("catalina.configFail", new Object[] { file.getAbsolutePath() }));

if ((file.exists()) && (!file.canRead())) {

log.warn("Permissions incorrect, read permission is not allowed on the file.");

}

}

return;

}

try

{

inputSource.setByteStream(inputStream);

digester.push(this);

digester.parse(inputSource);

} catch (SAXParseException spe) { log.warn("Catalina.start using " + getConfigFile() + ": " + spe.getMessage());

return;

} catch (Exception e) { log.warn("Catalina.start using " + getConfigFile() + ": ", e);

return;

}

finally {

try {

inputStream.close();

}

catch (IOException localIOException3)

{

}

}

getServer().setCatalina(this);

getServer().setCatalinaHome(Bootstrap.getCatalinaHomeFile());

getServer().setCatalinaBase(Bootstrap.getCatalinaBaseFile());

initStreams();

try

{

getServer().init();

} catch (LifecycleException e) {

if (Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE")) {

throw new Error(e);

}

log.error("Catalina.start", e);

}

long t2 = System.nanoTime();

if (log.isInfoEnabled())

log.info("Initialization processed in " + (t2 - t1) / 1000000L + " ms");

}

public void load(String[] args)

{

try

{

if (arguments(args))

load();

}

catch (Exception e) {

e.printStackTrace(System.out);

}

}

public void start()

{

if (getServer() == null) {

load();

}

if (getServer() == null) {

log.fatal("Cannot start server. Server instance is not configured.");

return;

}

long t1 = System.nanoTime();

try

{

getServer().start();

} catch (LifecycleException e) {

log.fatal(sm.getString("catalina.serverStartFail"), e);

try {

getServer().destroy();

} catch (LifecycleException e1) {

log.debug("destroy() failed for failed Server ", e1);

}

return;

}

long t2 = System.nanoTime();

if (log.isInfoEnabled()) {

log.info(" .:=+=======+=====+==++=." );

log.info(" ===+=======+===+=======++:");

log.info(" :+===============+=+=======++.");

log.info(" :====+++====================.");

log.info( " :==::::=:..::::=:==+=====+::");

log.info( " .=.:. ..::::==");

log.info( " :::. ...:. ....:=.");

log.info( " =::. . ....:..: ..::=.");

log.info( " ::.. .:.:. . .: . ::+");

log.info( " .= ::=== . ....:.......==");

用户头像

还未添加个人签名 2022.04.13 加入

还未添加个人简介

评论

发布
暂无评论
avatar Logo_Java_爱好编程进阶_InfoQ写作社区