Apache Tomcat 6.0.53

org.apache.jk.common
Class ChannelNioSocket

java.lang.Object
  extended by org.apache.jk.core.JkHandler
      extended by org.apache.jk.common.ChannelNioSocket
All Implemented Interfaces:
java.util.EventListener, javax.management.MBeanRegistration, javax.management.NotificationBroadcaster, javax.management.NotificationListener, JkChannel

public class ChannelNioSocket
extends JkHandler
implements javax.management.NotificationBroadcaster, JkChannel

Accept ( and send ) TCP messages.

Author:
Costin Manolache, Bill Barker jmx:mbean name="jk:service=ChannelNioSocket" description="Accept socket connections" jmx:notification name="org.apache.coyote.INVOKE jmx:notification-handler name="org.apache.jk.JK_SEND_PACKET jmx:notification-handler name="org.apache.jk.JK_RECEIVE_PACKET jmx:notification-handler name="org.apache.jk.JK_FLUSH Jk can use multiple protocols/transports. Various container adapters should load this object ( as a bean ), set configurations and use it. Note that the connector will handle all incoming protocols - it's not specific to ajp1x. The protocol is abstracted by MsgContext/Message/Channel. A lot of the 'original' behavior is hardcoded - this uses Ajp13 wire protocol, TCP, Ajp14 API etc. As we add other protocols/transports/APIs this will change, the current goal is to get the same level of functionality as in the original jk connector. XXX Make the 'message type' pluggable

Nested Class Summary
protected  class ChannelNioSocket.Poller
           
protected  class ChannelNioSocket.SocketConnection
           
protected  class ChannelNioSocket.SocketInputStream
           
protected  class ChannelNioSocket.SocketOutputStream
           
 
Field Summary
protected  boolean running
           
 
Fields inherited from class org.apache.jk.core.JkHandler
domain, ERROR, HANDLE_FLUSH, HANDLE_RECEIVE_PACKET, HANDLE_SEND_PACKET, HANDLE_THREAD_END, id, LAST, mserver, name, next, nextName, OK, oname, properties, wEnv
 
Constructor Summary
ChannelNioSocket()
          jmx:managed-constructor description="default constructor"
 
Method Summary
 void accept(MsgContext ep)
           
 void addNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)
           
 void close(MsgContext ep)
           
 void destroy()
          Clean up and stop the handler
 int flush(Msg msg, MsgContext ep)
          Flush the data to the client.
 java.lang.String getAddress()
           
 int getBufferSize()
           
 java.lang.String getChannelName()
          Return the identifying name of this Channel.
 boolean getDaemon()
           
 int getInstanceId()
          At startup we'll look for the first free port in the range.
 int getMaxPort()
           
 int getMaxSpareThreads()
           
 int getMaxThreads()
           
 int getMinSpareThreads()
           
 boolean getNioIsBroken()
           
 javax.management.MBeanNotificationInfo[] getNotificationInfo()
           
 int getPacketSize()
           
 int getPort()
           
 long getRequestCount()
           
 int getServerTimeout()
           
 int getSoLinger()
           
 int getSoTimeout()
           
 boolean getTcpNoDelay()
           
 ThreadPool getThreadPool()
           
 void init()
          jmx:managed-operation
 int invoke(Msg msg, MsgContext ep)
          Invoke the request chain.
static boolean isSameAddress(java.net.InetAddress server, java.net.InetAddress client)
          Return true if the specified client and server addresses are the same.
 boolean isSameAddress(MsgContext ep)
          Confirm that a shutdown request was recieved form us.
 void open(MsgContext ep)
           
 void pause()
           
 int read(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.
 int receive(Msg msg, MsgContext ep)
          Recieve a message from the client.
 void registerRequest(Request req, MsgContext ep, int count)
          Register a new Request in the Request pool.
 void reinit()
          Called after you change some fields at runtime using jmx.
 void removeNotificationListener(javax.management.NotificationListener listener)
           
 void resetCounters()
           
 void resume()
           
 int send(Msg msg, MsgContext ep)
          Send a message back to the client.
 void sendNewMessageNotification(javax.management.Notification notification)
           
 void setAddress(java.net.InetAddress inet)
           
 void setAddress(java.lang.String inet)
          jmx:managed-attribute description="Bind on a specified address" access="READ_WRITE"
 void setBacklog(int i)
           
 void setBufferSize(int bs)
           
 void setDaemon(boolean b)
          If set to false, the thread pool will be created in non-daemon mode, and will prevent main from exiting
 void setMaxPort(int i)
           
 void setMaxSpareThreads(int i)
           
 void setMaxThreads(int i)
           
 void setMinSpareThreads(int i)
           
 void setNioIsBroken(boolean nib)
           
 void setNotificationInfo(javax.management.MBeanNotificationInfo[] info)
           
 void setPacketSize(int ps)
           
 void setPort(int port)
          Set the port for the ajp13 channel.
 void setServerTimeout(int timeout)
          Sets the timeout in ms of the server sockets created by this server.
 void setSoLinger(int i)
           
 void setSoTimeout(int i)
           
 void setTcpNoDelay(boolean b)
           
 void start()
           
 void stop()
           
 
Methods inherited from class org.apache.jk.core.JkHandler
addHandlerCallback, createMsgContext, createMsgContext, getDomain, getId, getName, getNext, getObjectName, getProperty, handleNotification, postDeregister, postRegister, preDeregister, preRegister, setId, setName, setNext, setNext, setProperty, setWorkerEnv
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.jk.core.JkChannel
createMsgContext
 

Field Detail

running

protected boolean running
Constructor Detail

ChannelNioSocket

public ChannelNioSocket()
jmx:managed-constructor description="default constructor"

Method Detail

getThreadPool

public ThreadPool getThreadPool()

getRequestCount

public long getRequestCount()

setPort

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"


getPort

public int getPort()

setAddress

public void setAddress(java.net.InetAddress inet)

setBufferSize

public void setBufferSize(int bs)

getBufferSize

public int getBufferSize()

setPacketSize

public void setPacketSize(int ps)

getPacketSize

public int getPacketSize()

setAddress

public void setAddress(java.lang.String inet)
jmx:managed-attribute description="Bind on a specified address" access="READ_WRITE"


getAddress

public java.lang.String getAddress()

setServerTimeout

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.


getServerTimeout

public int getServerTimeout()

setTcpNoDelay

public void setTcpNoDelay(boolean b)

getTcpNoDelay

public boolean getTcpNoDelay()

setSoLinger

public void setSoLinger(int i)

getSoLinger

public int getSoLinger()

setSoTimeout

public void setSoTimeout(int i)

getSoTimeout

public int getSoTimeout()

setMaxPort

public void setMaxPort(int i)

getMaxPort

public int getMaxPort()

getInstanceId

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 ).


setDaemon

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


getDaemon

public boolean getDaemon()

setMaxThreads

public void setMaxThreads(int i)

setMinSpareThreads

public void setMinSpareThreads(int i)

setMaxSpareThreads

public void setMaxSpareThreads(int i)

getMaxThreads

public int getMaxThreads()

getMinSpareThreads

public int getMinSpareThreads()

getMaxSpareThreads

public int getMaxSpareThreads()

setBacklog

public void setBacklog(int i)

setNioIsBroken

public void setNioIsBroken(boolean nib)

getNioIsBroken

public boolean getNioIsBroken()

pause

public void pause()
           throws java.lang.Exception
Overrides:
pause in class JkHandler
Throws:
java.lang.Exception

resume

public void resume()
Overrides:
resume in class JkHandler

accept

public void accept(MsgContext ep)
            throws java.io.IOException
Throws:
java.io.IOException

resetCounters

public void resetCounters()

reinit

public void reinit()
            throws java.io.IOException
Called after you change some fields at runtime using jmx. Experimental for now.

Throws:
java.io.IOException

init

public void init()
          throws java.io.IOException
jmx:managed-operation

Overrides:
init in class JkHandler
Throws:
java.io.IOException

start

public void start()
           throws java.io.IOException
Throws:
java.io.IOException

stop

public void stop()
          throws java.io.IOException
Throws:
java.io.IOException

registerRequest

public void registerRequest(Request req,
                            MsgContext ep,
                            int count)
Description copied from interface: JkChannel
Register a new Request in the Request pool.

Specified by:
registerRequest in interface JkChannel

open

public void open(MsgContext ep)
          throws java.io.IOException
Throws:
java.io.IOException

close

public void close(MsgContext ep)
           throws java.io.IOException
Throws:
java.io.IOException

destroy

public void destroy()
             throws java.io.IOException
Description copied from class: JkHandler
Clean up and stop the handler

Overrides:
destroy in class JkHandler
Throws:
java.io.IOException

send

public int send(Msg msg,
                MsgContext ep)
         throws java.io.IOException
Description copied from interface: JkChannel
Send a message back to the client.

Specified by:
send in interface JkChannel
Parameters:
msg - The message to send.
ep - The connection point for this request.
Throws:
java.io.IOException

flush

public int flush(Msg msg,
                 MsgContext ep)
          throws java.io.IOException
Description copied from interface: JkChannel
Flush the data to the client.

Specified by:
flush in interface JkChannel
Throws:
java.io.IOException

receive

public int receive(Msg msg,
                   MsgContext ep)
            throws java.io.IOException
Description copied from interface: JkChannel
Recieve a message from the client.

Specified by:
receive in interface JkChannel
Parameters:
msg - The place to recieve the data into.
ep - The connection point for this request.
Throws:
java.io.IOException

read

public int read(MsgContext ep,
                byte[] b,
                int offset,
                int len)
         throws java.io.IOException
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.

Throws:
java.io.IOException

invoke

public int invoke(Msg msg,
                  MsgContext ep)
           throws java.io.IOException
Description copied from interface: JkChannel
Invoke the request chain.

Specified by:
invoke in interface JkChannel
Overrides:
invoke in class JkHandler
Throws:
java.io.IOException

isSameAddress

public boolean isSameAddress(MsgContext ep)
Description copied from interface: JkChannel
Confirm that a shutdown request was recieved form us.

Specified by:
isSameAddress in interface JkChannel

getChannelName

public java.lang.String getChannelName()
Description copied from interface: JkChannel
Return the identifying name of this Channel.

Specified by:
getChannelName in interface JkChannel

isSameAddress

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.

Parameters:
server - The server's InetAddress
client - The client's InetAddress

sendNewMessageNotification

public void sendNewMessageNotification(javax.management.Notification notification)

addNotificationListener

public void addNotificationListener(javax.management.NotificationListener listener,
                                    javax.management.NotificationFilter filter,
                                    java.lang.Object handback)
                             throws java.lang.IllegalArgumentException
Specified by:
addNotificationListener in interface javax.management.NotificationBroadcaster
Throws:
java.lang.IllegalArgumentException

removeNotificationListener

public void removeNotificationListener(javax.management.NotificationListener listener)
                                throws javax.management.ListenerNotFoundException
Specified by:
removeNotificationListener in interface javax.management.NotificationBroadcaster
Throws:
javax.management.ListenerNotFoundException

setNotificationInfo

public void setNotificationInfo(javax.management.MBeanNotificationInfo[] info)

getNotificationInfo

public javax.management.MBeanNotificationInfo[] getNotificationInfo()
Specified by:
getNotificationInfo in interface javax.management.NotificationBroadcaster

Apache Tomcat 6.0.53

Copyright © 2000-2017 Apache Software Foundation. All Rights Reserved.