📄 ajpaprprotocol.java
字号:
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.coyote.ajp;
import java.net.InetAddress;
import java.net.URLEncoder;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.concurrent.Executor;
import javax.management.MBeanRegistration;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import org.apache.coyote.ActionCode;
import org.apache.coyote.ActionHook;
import org.apache.coyote.Adapter;
import org.apache.coyote.ProtocolHandler;
import org.apache.coyote.RequestGroupInfo;
import org.apache.coyote.RequestInfo;
import org.apache.tomcat.util.modeler.Registry;
import org.apache.tomcat.util.net.AprEndpoint;
import org.apache.tomcat.util.net.SocketStatus;
import org.apache.tomcat.util.net.AprEndpoint.Handler;
import org.apache.tomcat.util.res.StringManager;
/**
* Abstract the protocol implementation, including threading, etc.
* Processor is single threaded and specific to stream-based protocols,
* will not fit Jk protocols like JNI.
*
* @author Remy Maucherat
* @author Costin Manolache
*/
public class AjpAprProtocol
implements ProtocolHandler, MBeanRegistration {
protected static org.apache.juli.logging.Log log =
org.apache.juli.logging.LogFactory.getLog(AjpAprProtocol.class);
/**
* The string manager for this package.
*/
protected static StringManager sm =
StringManager.getManager(Constants.Package);
// ------------------------------------------------------------ Constructor
public AjpAprProtocol() {
cHandler = new AjpConnectionHandler(this);
setSoLinger(Constants.DEFAULT_CONNECTION_LINGER);
setSoTimeout(Constants.DEFAULT_CONNECTION_TIMEOUT);
//setServerSoTimeout(Constants.DEFAULT_SERVER_SOCKET_TIMEOUT);
setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY);
}
// ----------------------------------------------------- Instance Variables
protected ObjectName tpOname;
protected ObjectName rgOname;
/**
* Associated APR endpoint.
*/
protected AprEndpoint ep = new AprEndpoint();
/**
* Configuration attributes.
*/
protected Hashtable attributes = new Hashtable();
/**
* Should authentication be done in the native webserver layer,
* or in the Servlet container ?
*/
protected boolean tomcatAuthentication = true;
/**
* Required secret.
*/
protected String requiredSecret = null;
/**
* AJP packet size.
*/
protected int packetSize = Constants.MAX_PACKET_SIZE;
/**
* Adapter which will process the requests recieved by this endpoint.
*/
private Adapter adapter;
/**
* Connection handler for AJP.
*/
private AjpConnectionHandler cHandler;
// --------------------------------------------------------- Public Methods
/**
* Pass config info
*/
public void setAttribute(String name, Object value) {
if (log.isTraceEnabled()) {
log.trace(sm.getString("ajpprotocol.setattribute", name, value));
}
attributes.put(name, value);
}
public Object getAttribute(String key) {
if (log.isTraceEnabled()) {
log.trace(sm.getString("ajpprotocol.getattribute", key));
}
return attributes.get(key);
}
public Iterator getAttributeNames() {
return attributes.keySet().iterator();
}
/**
* Set a property.
*/
public void setProperty(String name, String value) {
setAttribute(name, value);
}
/**
* Get a property
*/
public String getProperty(String name) {
return (String) getAttribute(name);
}
/**
* The adapter, used to call the connector
*/
public void setAdapter(Adapter adapter) {
this.adapter = adapter;
}
public Adapter getAdapter() {
return adapter;
}
/** Start the protocol
*/
public void init() throws Exception {
ep.setName(getName());
ep.setHandler(cHandler);
ep.setUseSendfile(false);
try {
ep.init();
} catch (Exception ex) {
log.error(sm.getString("ajpprotocol.endpoint.initerror"), ex);
throw ex;
}
if (log.isInfoEnabled()) {
log.info(sm.getString("ajpprotocol.init", getName()));
}
}
public void start() throws Exception {
if (this.domain != null ) {
try {
tpOname = new ObjectName
(domain + ":" + "type=ThreadPool,name=" + getName());
Registry.getRegistry(null, null)
.registerComponent(ep, tpOname, null );
} catch (Exception e) {
log.error("Can't register threadpool" );
}
rgOname = new ObjectName
(domain + ":type=GlobalRequestProcessor,name=" + getName());
Registry.getRegistry(null, null).registerComponent
(cHandler.global, rgOname, null);
}
try {
ep.start();
} catch (Exception ex) {
log.error(sm.getString("ajpprotocol.endpoint.starterror"), ex);
throw ex;
}
if (log.isInfoEnabled())
log.info(sm.getString("ajpprotocol.start", getName()));
}
public void pause() throws Exception {
try {
ep.pause();
} catch (Exception ex) {
log.error(sm.getString("ajpprotocol.endpoint.pauseerror"), ex);
throw ex;
}
if (log.isInfoEnabled())
log.info(sm.getString("ajpprotocol.pause", getName()));
}
public void resume() throws Exception {
try {
ep.resume();
} catch (Exception ex) {
log.error(sm.getString("ajpprotocol.endpoint.resumeerror"), ex);
throw ex;
}
if (log.isInfoEnabled())
log.info(sm.getString("ajpprotocol.resume", getName()));
}
public void destroy() throws Exception {
if (log.isInfoEnabled())
log.info(sm.getString("ajpprotocol.stop", getName()));
ep.destroy();
if (tpOname!=null)
Registry.getRegistry(null, null).unregisterComponent(tpOname);
if (rgOname != null)
Registry.getRegistry(null, null).unregisterComponent(rgOname);
}
// *
public Executor getExecutor() {
return ep.getExecutor();
}
// *
public void setExecutor(Executor executor) {
ep.setExecutor(executor);
}
public int getMaxThreads() {
return ep.getMaxThreads();
}
public void setMaxThreads(int maxThreads) {
ep.setMaxThreads(maxThreads);
setAttribute("maxThreads", "" + maxThreads);
}
public void setThreadPriority(int threadPriority) {
ep.setThreadPriority(threadPriority);
setAttribute("threadPriority", "" + threadPriority);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -