org.apache.jk.common
Class ChannelSocket

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

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

Accept ( and send ) TCP messages.

Author:
Costin Manolache

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
ChannelSocket()
           
 
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()
           
 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()
           
 javax.management.MBeanNotificationInfo[] getNotificationInfo()
           
 int getPort()
           
 long getRequestCount()
           
 int getServerTimeout()
           
 int getSoLinger()
           
 int getSoTimeout()
           
 boolean getTcpNoDelay()
           
 ThreadPool getThreadPool()
           
 void init()
          Should register the request types it can handle, same style as apache2.
 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)
           
 void setBacklog(int i)
           
 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 setNotificationInfo(javax.management.MBeanNotificationInfo[] info)
           
 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, 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

ChannelSocket

public ChannelSocket()
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.


getPort

public int getPort()

setAddress

public void setAddress(java.net.InetAddress inet)

setAddress

public void setAddress(java.lang.String inet)

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)

pause

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

resume

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

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
Description copied from class: JkHandler
Should register the request types it can handle, same style as apache2.

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


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