Methods Summary |
---|
public void | accept(org.apache.jk.core.MsgContext ep)
if( sSocket==null ) return;
synchronized(this) {
while(paused) {
try{
wait();
} catch(InterruptedException ie) {
//Ignore, since can't happen
}
}
}
SocketChannel sc=sSocket.getChannel().accept();
Socket s = sc.socket();
ep.setNote( socketNote, s );
if(log.isDebugEnabled() )
log.debug("Accepted socket " + s +" channel " + sc.isBlocking());
try {
setSocketOptions(s);
} catch(SocketException sex) {
log.debug("Error initializing Socket Options", sex);
}
requestCount++;
sc.configureBlocking(false);
InputStream is=new SocketInputStream(sc);
OutputStream os = new SocketOutputStream(sc);
ep.setNote( isNote, is );
ep.setNote( osNote, os );
ep.setControl( tp );
|
void | acceptConnections()Accept incoming connections, dispatch to the thread pool
if( running ) {
try{
MsgContext ep=createMsgContext();
ep.setSource(this);
ep.setWorkerEnv( wEnv );
this.accept(ep);
if( !running ) return;
// Since this is a long-running connection, we don't care
// about the small GC
SocketConnection ajpConn=
new SocketConnection( ep);
ajpConn.register(ep);
}catch(Exception ex) {
if (running)
log.warn("Exception executing accept" ,ex);
}
}
|
public void | addNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)
if( nSupport==null ) nSupport=new NotificationBroadcasterSupport();
nSupport.addNotificationListener(listener, filter, handback);
|
public void | close(org.apache.jk.core.MsgContext ep)
Socket s=(Socket)ep.getNote( socketNote );
SelectionKey key = s.getChannel().keyFor(selector);
if(key != null) {
key.cancel();
}
s.close();
|
public void | destroy()
running = false;
try {
/* If we disabled the channel return */
if (port == 0)
return;
tp.shutdown();
selector.wakeup().close();
sSocket.close(); // XXX?
if( tpOName != null ) {
Registry.getRegistry(null, null).unregisterComponent(tpOName);
}
if( rgOName != null ) {
Registry.getRegistry(null, null).unregisterComponent(rgOName);
}
} catch(Exception e) {
log.info("Error shutting down the channel " + port + " " +
e.toString());
if( log.isDebugEnabled() ) log.debug("Trace", e);
}
|
public int | flush(org.apache.jk.core.Msg msg, org.apache.jk.core.MsgContext ep)
OutputStream os=(OutputStream)ep.getNote( osNote );
os.flush();
return 0;
|
public java.lang.String | getAddress()
if( inet!=null)
return inet.toString();
return "/0.0.0.0";
|
public int | getBufferSize()
return bufferSize;
|
public java.lang.String | getChannelName()
String encodedAddr = "";
if (inet != null && !"0.0.0.0".equals(inet.getHostAddress())) {
encodedAddr = getAddress();
if (encodedAddr.startsWith("/"))
encodedAddr = encodedAddr.substring(1);
encodedAddr = URLEncoder.encode(encodedAddr) + "-";
}
return ("jk-" + encodedAddr + port);
|
public boolean | getDaemon()
return tp.getDaemon();
|
public int | getInstanceId()At startup we'll look for the first free port in the range.
The difference between this port and the beggining of the range
is the 'id'.
This is usefull for lb cases ( less config ).
return port-startPort;
|
public int | getMaxPort()
return maxPort;
|
public int | getMaxSpareThreads()
return tp.getMaxSpareThreads();
|
public int | getMaxThreads()
return tp.getMaxThreads();
|
public int | getMinSpareThreads()
return tp.getMinSpareThreads();
|
public boolean | getNioIsBroken()
return nioIsBroken;
|
public javax.management.MBeanNotificationInfo[] | getNotificationInfo()
return notifInfo;
|
public int | getPacketSize()
return packetSize;
|
public int | getPort()
return port;
|
public long | getRequestCount()
return requestCount;
|
public int | getServerTimeout()
return serverTimeout;
|
public int | getSoLinger()
return linger;
|
public int | getSoTimeout()
return socketTimeout;
|
public boolean | getTcpNoDelay()
return tcpNoDelay;
|
public org.apache.tomcat.util.threads.ThreadPool | getThreadPool()
return tp;
|
public void | init()jmx:managed-operation
// Find a port.
if (startPort == 0) {
port = 0;
if(log.isInfoEnabled())
log.info("JK: ajp13 disabling channelNioSocket");
running = true;
return;
}
if (maxPort < startPort)
maxPort = startPort;
ServerSocketChannel ssc = ServerSocketChannel.open();
ssc.configureBlocking(false);
for( int i=startPort; i<=maxPort; i++ ) {
try {
InetSocketAddress iddr = null;
if( inet == null ) {
iddr = new InetSocketAddress( i);
} else {
iddr=new InetSocketAddress( inet, i);
}
sSocket = ssc.socket();
sSocket.bind(iddr);
port=i;
break;
} catch( IOException ex ) {
if(log.isInfoEnabled())
log.info("Port busy " + i + " " + ex.toString());
sSocket = null;
}
}
if( sSocket==null ) {
log.error("Can't find free port " + startPort + " " + maxPort );
return;
}
if(log.isInfoEnabled())
log.info("JK: ajp13 listening on " + getAddress() + ":" + port );
selector = Selector.open();
ssc.register(selector, SelectionKey.OP_ACCEPT);
// If this is not the base port and we are the 'main' channleSocket and
// SHM didn't already set the localId - we'll set the instance id
if( "channelNioSocket".equals( name ) &&
port != startPort &&
(wEnv.getLocalId()==0) ) {
wEnv.setLocalId( port - startPort );
}
// XXX Reverse it -> this is a notification generator !!
if( next==null && wEnv!=null ) {
if( nextName!=null )
setNext( wEnv.getHandler( nextName ) );
if( next==null )
next=wEnv.getHandler( "dispatch" );
if( next==null )
next=wEnv.getHandler( "request" );
}
JMXRequestNote =wEnv.getNoteId( WorkerEnv.ENDPOINT_NOTE, "requestNote");
running = true;
// Run a thread that will accept connections.
// XXX Try to find a thread first - not sure how...
if( this.domain != null ) {
try {
tpOName=new ObjectName(domain + ":type=ThreadPool,name=" +
getChannelName());
Registry.getRegistry(null, null)
.registerComponent(tp, tpOName, null);
rgOName = new ObjectName
(domain+":type=GlobalRequestProcessor,name=" + getChannelName());
Registry.getRegistry(null, null)
.registerComponent(global, rgOName, null);
} catch (Exception e) {
log.error("Can't register threadpool" );
}
}
tp.start();
Poller pollAjp = new Poller();
tp.runIt(pollAjp);
|
public int | invoke(org.apache.jk.core.Msg msg, org.apache.jk.core.MsgContext ep)
int type=ep.getType();
switch( type ) {
case JkHandler.HANDLE_RECEIVE_PACKET:
if( log.isDebugEnabled()) log.debug("RECEIVE_PACKET ?? ");
return receive( msg, ep );
case JkHandler.HANDLE_SEND_PACKET:
return send( msg, ep );
case JkHandler.HANDLE_FLUSH:
return flush( msg, ep );
}
if( log.isTraceEnabled() )
log.trace("Call next " + type + " " + next);
// Send notification
if( nSupport!=null ) {
Notification notif=(Notification)ep.getNote(notifNote);
if( notif==null ) {
notif=new Notification("channelNioSocket.message", ep, requestCount );
ep.setNote( notifNote, notif);
}
nSupport.sendNotification(notif);
}
if( next != null ) {
return next.invoke( msg, ep );
} else {
log.info("No next ");
}
return OK;
|
public boolean | isSameAddress(org.apache.jk.core.MsgContext ep)
Socket s=(Socket)ep.getNote( socketNote );
return isSameAddress( s.getLocalAddress(), s.getInetAddress());
|
public static boolean | isSameAddress(java.net.InetAddress server, java.net.InetAddress client)Return true if the specified client and server addresses
are the same. This method works around a bug in the IBM 1.1.8 JVM on
Linux, where the address bytes are returned reversed in some
circumstances.
// Compare the byte array versions of the two addresses
byte serverAddr[] = server.getAddress();
byte clientAddr[] = client.getAddress();
if (serverAddr.length != clientAddr.length)
return (false);
boolean match = true;
for (int i = 0; i < serverAddr.length; i++) {
if (serverAddr[i] != clientAddr[i]) {
match = false;
break;
}
}
if (match)
return (true);
// Compare the reversed form of the two addresses
for (int i = 0; i < serverAddr.length; i++) {
if (serverAddr[i] != clientAddr[(serverAddr.length-1)-i])
return (false);
}
return (true);
|
public void | open(org.apache.jk.core.MsgContext ep)
|
public void | pause()
synchronized(this) {
paused = true;
}
|
public int | read(org.apache.jk.core.MsgContext ep, byte[] b, int offset, int len)Read N bytes from the InputStream, and ensure we got them all
Under heavy load we could experience many fragmented packets
just read Unix Network Programming to recall that a call to
read didn't ensure you got all the data you want
from read() Linux manual
On success, the number of bytes read is returned (zero indicates end
of file),and the file position is advanced by this number.
It is not an error if this number is smaller than the number of bytes
requested; this may happen for example because fewer bytes
are actually available right now (maybe because we were close to
end-of-file, or because we are reading from a pipe, or from a
terminal), or because read() was interrupted by a signal.
On error, -1 is returned, and errno is set appropriately. In this
case it is left unspecified whether the file position (if any) changes.
InputStream is=(InputStream)ep.getNote( isNote );
int pos = 0;
int got;
while(pos < len) {
try {
got = is.read(b, pos + offset, len - pos);
} catch(ClosedChannelException sex) {
if(pos > 0) {
log.info("Error reading data after "+pos+"bytes",sex);
} else {
log.debug("Error reading data", sex);
}
got = -1;
}
if (log.isTraceEnabled()) {
log.trace("read() " + b + " " + (b==null ? 0: b.length) + " " +
offset + " " + len + " = " + got );
}
// connection just closed by remote.
if (got <= 0) {
// This happens periodically, as apache restarts
// periodically.
// It should be more gracefull ! - another feature for Ajp14
// log.warn( "server has closed the current connection (-1)" );
return -3;
}
pos += got;
}
return pos;
|
public int | receive(org.apache.jk.core.Msg msg, org.apache.jk.core.MsgContext ep)
if (log.isTraceEnabled()) {
log.trace("receive() ");
}
byte buf[]=msg.getBuffer();
int hlen=msg.getHeaderLength();
// XXX If the length in the packet header doesn't agree with the
// actual number of bytes read, it should probably return an error
// value. Also, callers of this method never use the length
// returned -- should probably return true/false instead.
int rd = this.read(ep, buf, 0, hlen );
if(rd < 0) {
// Most likely normal apache restart.
// log.warn("Wrong message " + rd );
return rd;
}
msg.processHeader();
/* After processing the header we know the body
length
*/
int blen=msg.getLen();
// XXX check if enough space - it's assert()-ed !!!
int total_read = 0;
total_read = this.read(ep, buf, hlen, blen);
if ((total_read <= 0) && (blen > 0)) {
log.warn("can't read body, waited #" + blen);
return -1;
}
if (total_read != blen) {
log.warn( "incomplete read, waited #" + blen +
" got only " + total_read);
return -2;
}
return total_read;
|
public void | registerRequest(org.apache.coyote.Request req, org.apache.jk.core.MsgContext ep, int count)
if(this.domain != null) {
try {
RequestInfo rp=req.getRequestProcessor();
rp.setGlobalProcessor(global);
ObjectName roname = new ObjectName
(getDomain() + ":type=RequestProcessor,worker="+
getChannelName()+",name=JkRequest" +count);
ep.setNote(JMXRequestNote, roname);
Registry.getRegistry(null, null).registerComponent( rp, roname, null);
} catch( Exception ex ) {
log.warn("Error registering request");
}
}
|
public void | reinit()Called after you change some fields at runtime using jmx.
Experimental for now.
destroy();
init();
|
public void | removeNotificationListener(javax.management.NotificationListener listener)
if( nSupport!=null)
nSupport.removeNotificationListener(listener);
|
public void | resetCounters()
requestCount=0;
|
public void | resume()
synchronized(this) {
paused = false;
notify();
}
|
public int | send(org.apache.jk.core.Msg msg, org.apache.jk.core.MsgContext ep)
msg.end(); // Write the packet header
byte buf[]=msg.getBuffer();
int len=msg.getLen();
if(log.isTraceEnabled() )
log.trace("send() " + len + " " + buf[4] );
OutputStream os=(OutputStream)ep.getNote( osNote );
os.write( buf, 0, len );
return len;
|
public void | sendNewMessageNotification(javax.management.Notification notification)
if( nSupport!= null )
nSupport.sendNotification(notification);
|
public void | setAddress(java.lang.String inet)jmx:managed-attribute description="Bind on a specified address" access="READ_WRITE"
try {
this.inet= InetAddress.getByName( inet );
} catch( Exception ex ) {
log.error("Error parsing "+inet,ex);
}
|
public void | setAddress(java.net.InetAddress inet)
this.inet=inet;
|
public void | setBacklog(int i)
|
public void | setBufferSize(int bs)
if(bs > 8*1024) {
bufferSize = bs;
}
|
public void | setDaemon(boolean b)If set to false, the thread pool will be created in
non-daemon mode, and will prevent main from exiting
tp.setDaemon( b );
|
public void | setMaxPort(int i)
maxPort=i;
|
public void | setMaxSpareThreads(int i)
if( log.isDebugEnabled()) log.debug("Setting maxSpareThreads " + i);
tp.setMaxSpareThreads(i);
|
public void | setMaxThreads(int i)
if( log.isDebugEnabled()) log.debug("Setting maxThreads " + i);
tp.setMaxThreads(i);
|
public void | setMinSpareThreads(int i)
if( log.isDebugEnabled()) log.debug("Setting minSpareThreads " + i);
tp.setMinSpareThreads(i);
|
public void | setNioIsBroken(boolean nib)
nioIsBroken = nib;
|
public void | setNotificationInfo(javax.management.MBeanNotificationInfo[] info)
this.notifInfo=info;
|
public void | setPacketSize(int ps)
if(ps < 8*1024) {
ps = 8*1024;
}
packetSize = ps;
|
public void | setPort(int port)Set the port for the ajp13 channel.
To support seemless load balancing and jni, we treat this
as the 'base' port - we'll try up until we find one that is not
used. We'll also provide the 'difference' to the main coyote
handler - that will be our 'sessionID' and the position in
the scoreboard and the suffix for the unix domain socket.
jmx:managed-attribute description="Port to listen" access="READ_WRITE"
this.startPort=port;
this.port=port;
this.maxPort=port+10;
|
public void | setServerTimeout(int timeout)Sets the timeout in ms of the server sockets created by this
server. This method allows the developer to make servers
more or less responsive to having their server sockets
shut down.
By default this value is 1000ms.
this.serverTimeout = timeout;
|
public void | setSoLinger(int i)
linger=i;
|
public void | setSoTimeout(int i)
socketTimeout=i;
|
private void | setSocketOptions(java.net.Socket s)
if( socketTimeout > 0 )
s.setSoTimeout( socketTimeout );
s.setTcpNoDelay( tcpNoDelay ); // set socket tcpnodelay state
if( linger > 0 )
s.setSoLinger( true, linger);
|
public void | setTcpNoDelay(boolean b)
tcpNoDelay=b;
|
public void | start()
if( sSocket==null )
init();
resume();
|
public void | stop()
destroy();
|