📄 embedded.java
字号:
*
* @param engine The engine to be added
*/
public synchronized void addEngine(Engine engine) {
if( log.isDebugEnabled() )
log.debug("Adding engine (" + engine.getInfo() + ")");
// Add this Engine to our set of defined Engines
Engine results[] = new Engine[engines.length + 1];
for (int i = 0; i < engines.length; i++)
results[i] = engines[i];
results[engines.length] = engine;
engines = results;
// Start this Engine if necessary
if (started && (engine instanceof Lifecycle)) {
try {
((Lifecycle) engine).start();
} catch (LifecycleException e) {
log.error("Engine.start", e);
}
}
this.container = engine;
}
/**
* Create, configure, and return a new TCP/IP socket connector
* based on the specified properties.
*
* @param address InetAddress to bind to, or <code>null</code> if the
* connector is supposed to bind to all addresses on this server
* @param port Port number to listen to
* @param secure true if the generated connector is supposed to be
* SSL-enabled, and false otherwise
*/
public Connector createConnector(InetAddress address, int port,
boolean secure) {
return createConnector(address != null? address.toString() : null,
port, secure);
}
public Connector createConnector(String address, int port,
boolean secure) {
String protocol = "http";
if (secure) {
protocol = "https";
}
return createConnector(address, port, protocol);
}
public Connector createConnector(InetAddress address, int port,
String protocol) {
return createConnector(address != null? address.toString() : null,
port, protocol);
}
public Connector createConnector(String address, int port,
String protocol) {
Connector connector = null;
if (address != null) {
/*
* InetAddress.toString() returns a string of the form
* "<hostname>/<literal_IP>". Get the latter part, so that the
* address can be parsed (back) into an InetAddress using
* InetAddress.getByName().
*/
int index = address.indexOf('/');
if (index != -1) {
address = address.substring(index + 1);
}
}
if (log.isDebugEnabled()) {
log.debug("Creating connector for address='" +
((address == null) ? "ALL" : address) +
"' port='" + port + "' protocol='" + protocol + "'");
}
try {
if (protocol.equals("ajp")) {
connector = new Connector("org.apache.jk.server.JkCoyoteHandler");
} else if (protocol.equals("memory")) {
connector = new Connector("org.apache.coyote.memory.MemoryProtocolHandler");
} else if (protocol.equals("http")) {
connector = new Connector();
} else if (protocol.equals("https")) {
connector = new Connector();
connector.setScheme("https");
connector.setSecure(true);
// FIXME !!!! SET SSL PROPERTIES
}
if (address != null) {
IntrospectionUtils.setProperty(connector, "address",
"" + address);
}
IntrospectionUtils.setProperty(connector, "port", "" + port);
} catch (Exception e) {
log.error("Couldn't create connector.");
}
return (connector);
}
/**
* Create, configure, and return a Context that will process all
* HTTP requests received from one of the associated Connectors,
* and directed to the specified context path on the virtual host
* to which this Context is connected.
* <p>
* After you have customized the properties, listeners, and Valves
* for this Context, you must attach it to the corresponding Host
* by calling:
* <pre>
* host.addChild(context);
* </pre>
* which will also cause the Context to be started if the Host has
* already been started.
*
* @param path Context path of this application ("" for the default
* application for this host, must start with a slash otherwise)
* @param docBase Absolute pathname to the document base directory
* for this web application
*
* @exception IllegalArgumentException if an invalid parameter
* is specified
*/
public Context createContext(String path, String docBase) {
if( log.isDebugEnabled() )
log.debug("Creating context '" + path + "' with docBase '" +
docBase + "'");
StandardContext context = new StandardContext();
context.setDocBase(docBase);
context.setPath(path);
ContextConfig config = new ContextConfig();
config.setCustomAuthenticators(authenticators);
((Lifecycle) context).addLifecycleListener(config);
return (context);
}
/**
* Create, configure, and return an Engine that will process all
* HTTP requests received from one of the associated Connectors,
* based on the specified properties.
*/
public Engine createEngine() {
if( log.isDebugEnabled() )
log.debug("Creating engine");
StandardEngine engine = new StandardEngine();
// Default host will be set to the first host added
engine.setRealm(realm); // Inherited by all children
return (engine);
}
/**
* Create, configure, and return a Host that will process all
* HTTP requests received from one of the associated Connectors,
* and directed to the specified virtual host.
* <p>
* After you have customized the properties, listeners, and Valves
* for this Host, you must attach it to the corresponding Engine
* by calling:
* <pre>
* engine.addChild(host);
* </pre>
* which will also cause the Host to be started if the Engine has
* already been started. If this is the default (or only) Host you
* will be defining, you may also tell the Engine to pass all requests
* not assigned to another virtual host to this one:
* <pre>
* engine.setDefaultHost(host.getName());
* </pre>
*
* @param name Canonical name of this virtual host
* @param appBase Absolute pathname to the application base directory
* for this virtual host
*
* @exception IllegalArgumentException if an invalid parameter
* is specified
*/
public Host createHost(String name, String appBase) {
if( log.isDebugEnabled() )
log.debug("Creating host '" + name + "' with appBase '" +
appBase + "'");
StandardHost host = new StandardHost();
host.setAppBase(appBase);
host.setName(name);
return (host);
}
/**
* Create and return a class loader manager that can be customized, and
* then attached to a Context, before it is started.
*
* @param parent ClassLoader that will be the parent of the one
* created by this Loader
*/
public Loader createLoader(ClassLoader parent) {
if( log.isDebugEnabled() )
log.debug("Creating Loader with parent class loader '" +
parent + "'");
WebappLoader loader = new WebappLoader(parent);
return (loader);
}
/**
* Return descriptive information about this Server implementation and
* the corresponding version number, in the format
* <code><description>/<version></code>.
*/
public String getInfo() {
return (info);
}
/**
* Remove the specified Context from the set of defined Contexts for its
* associated Host. If this is the last Context for this Host, the Host
* will also be removed.
*
* @param context The Context to be removed
*/
public synchronized void removeContext(Context context) {
if( log.isDebugEnabled() )
log.debug("Removing context[" + context.getPath() + "]");
// Is this Context actually among those that are defined?
boolean found = false;
for (int i = 0; i < engines.length; i++) {
Container hosts[] = engines[i].findChildren();
for (int j = 0; j < hosts.length; j++) {
Container contexts[] = hosts[j].findChildren();
for (int k = 0; k < contexts.length; k++) {
if (context == (Context) contexts[k]) {
found = true;
break;
}
}
if (found)
break;
}
if (found)
break;
}
if (!found)
return;
// Remove this Context from the associated Host
if( log.isDebugEnabled() )
log.debug(" Removing this Context");
context.getParent().removeChild(context);
}
/**
* Remove the specified Engine from the set of defined Engines, along with
* all of its related Hosts and Contexts. All associated Connectors are
* also removed.
*
* @param engine The Engine to be removed
*/
public synchronized void removeEngine(Engine engine) {
if( log.isDebugEnabled() )
log.debug("Removing engine (" + engine.getInfo() + ")");
// Is the specified Engine actually defined?
int j = -1;
for (int i = 0; i < engines.length; i++) {
if (engine == engines[i]) {
j = i;
break;
}
}
if (j < 0)
return;
// Remove any Connector that is using this Engine
if( log.isDebugEnabled() )
log.debug(" Removing related Containers");
while (true) {
int n = -1;
for (int i = 0; i < connectors.length; i++) {
if (connectors[i].getContainer() == (Container) engine) {
n = i;
break;
}
}
if (n < 0)
break;
removeConnector(connectors[n]);
}
// Stop this Engine if necessary
if (engine instanceof Lifecycle) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -