org.mortbay.jetty
Class AbstractConnector

java.lang.Object
  extended byorg.mortbay.component.AbstractLifeCycle
      extended byorg.mortbay.jetty.AbstractConnector
All Implemented Interfaces:
Buffers, Connector, LifeCycle
Direct Known Subclasses:
BlockingChannelConnector, SelectChannelConnector, SocketConnector

public abstract class AbstractConnector
extends AbstractLifeCycle
implements Connector

Abstract Connector implementation. This abstract implemenation of the Connector interface provides:

Author:
gregw TODO - allow multiple Acceptor threads

Field Summary
protected  int _lowResourceMaxIdleTime
           
protected  int _maxIdleTime
           
protected  int _soLingerTime
           
 
Constructor Summary
AbstractConnector()
           
 
Method Summary
protected abstract  void accept(int acceptorID)
           
protected  void configure(Socket socket)
           
protected  void connectionClosed(HttpConnection connection)
           
protected  void connectionOpened(HttpConnection connection)
           
 void customize(EndPoint endpoint, Request request)
          Customize a request for an endpoint.
protected  void doStart()
           
protected  void doStop()
           
 int getAcceptors()
           
 int getAcceptQueueSize()
           
 Buffer getBuffer(int size)
           
 int getConfidentialPort()
           
 String getConfidentialScheme()
           
 int getConnections()
           
 long getConnectionsDurationAve()
           
 long getConnectionsDurationMax()
           
 long getConnectionsDurationMin()
           
 long getConnectionsDurationTotal()
           
 int getConnectionsOpen()
           
 int getConnectionsOpenMax()
           
 int getConnectionsOpenMin()
           
 int getConnectionsRequestsAve()
           
 int getConnectionsRequestsMax()
           
 int getConnectionsRequestsMin()
           
 int getHeaderBufferSize()
           
 String getHost()
           
 int getIntegralPort()
           
 String getIntegralScheme()
           
 int getLowResourceMaxIdleTime()
           
 int getMaxIdleTime()
           
 String getName()
           
 int getPort()
           
 int getRequestBufferSize()
           
 int getRequests()
           
 boolean getResolveNames()
           
 int getResponseBufferSize()
           
 Server getServer()
           
 long getSoLingerTime()
           
 boolean getStatsOn()
           
 long getStatsOnMs()
           
 ThreadPool getThreadPool()
           
 boolean isConfidential(Request request)
           
 boolean isIntegral(Request request)
           
 void join()
           
protected abstract  Buffer newBuffer(int size)
           
 Continuation newContinuation()
           
abstract  void open()
          Opens the connector
 void returnBuffer(Buffer buffer)
           
 void setAcceptors(int acceptors)
           
 void setAcceptQueueSize(int acceptQueueSize)
           
 void setConfidentialPort(int confidentialPort)
           
 void setConfidentialScheme(String confidentialScheme)
           
 void setHeaderBufferSize(int headerBufferSize)
          Set the size of the buffer to be used for request and response headers.
 void setHost(String host)
           
 void setIntegralPort(int integralPort)
           
 void setIntegralScheme(String integralScheme)
           
 void setLowResourceMaxIdleTime(int maxIdleTime)
           
 void setMaxIdleTime(int maxIdleTime)
           
 void setName(String name)
           
 void setPort(int port)
           
 void setRequestBufferSize(int requestBufferSize)
          Set the size of the content buffer for receiving requests.
 void setResolveNames(boolean resolve)
           
 void setResponseBufferSize(int responseBufferSize)
          Set the size of the content buffer for sending responses.
 void setServer(Server server)
           
 void setSoLingerTime(int soLingerTime)
           
 void setStatsOn(boolean on)
           
 void setThreadPool(ThreadPool pool)
           
 void statsReset()
          Reset statistics.
 String toString()
           
 
Methods inherited from class org.mortbay.component.AbstractLifeCycle
isFailed, isRunning, isStarted, isStarting, isStopping, start, stop
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.mortbay.jetty.Connector
close, getConnection, getLocalPort
 
Methods inherited from interface org.mortbay.component.LifeCycle
isFailed, isRunning, isStarted, isStarting, isStopping, start, stop
 

Field Detail

_maxIdleTime

protected int _maxIdleTime

_lowResourceMaxIdleTime

protected int _lowResourceMaxIdleTime

_soLingerTime

protected int _soLingerTime
Constructor Detail

AbstractConnector

public AbstractConnector()
Method Detail

open

public abstract void open()
                   throws IOException
Description copied from interface: Connector
Opens the connector

Specified by:
open in interface Connector
Throws:
IOException

getServer

public Server getServer()
Specified by:
getServer in interface Connector

setServer

public void setServer(Server server)
Specified by:
setServer in interface Connector

getThreadPool

public ThreadPool getThreadPool()

setThreadPool

public void setThreadPool(ThreadPool pool)

setHost

public void setHost(String host)
Specified by:
setHost in interface Connector

getHost

public String getHost()
Specified by:
getHost in interface Connector

setPort

public void setPort(int port)
Specified by:
setPort in interface Connector
Parameters:
port - The port fto listen of for connections or 0 if any available port may be used.

getPort

public int getPort()
Specified by:
getPort in interface Connector
Returns:
The configured port for the connector or 0 if any available port may be used.

getHeaderBufferSize

public int getHeaderBufferSize()
Specified by:
getHeaderBufferSize in interface Connector
Returns:
Returns the headerBufferSize.

setHeaderBufferSize

public void setHeaderBufferSize(int headerBufferSize)
Description copied from interface: Connector
Set the size of the buffer to be used for request and response headers. An idle connection will at most have one buffer of this size allocated.

Specified by:
setHeaderBufferSize in interface Connector
Parameters:
headerBufferSize - The headerBufferSize to set.

getMaxIdleTime

public int getMaxIdleTime()
Specified by:
getMaxIdleTime in interface Connector
Returns:
Returns the maxIdleTime.

setMaxIdleTime

public void setMaxIdleTime(int maxIdleTime)
Specified by:
setMaxIdleTime in interface Connector
Parameters:
maxIdleTime - The maxIdleTime to set.

getLowResourceMaxIdleTime

public int getLowResourceMaxIdleTime()
Specified by:
getLowResourceMaxIdleTime in interface Connector
Returns:
Returns the maxIdleTime.

setLowResourceMaxIdleTime

public void setLowResourceMaxIdleTime(int maxIdleTime)
Specified by:
setLowResourceMaxIdleTime in interface Connector
Parameters:
maxIdleTime - The maxIdleTime to set.

getRequestBufferSize

public int getRequestBufferSize()
Specified by:
getRequestBufferSize in interface Connector
Returns:
Returns the requestBufferSize.

setRequestBufferSize

public void setRequestBufferSize(int requestBufferSize)
Description copied from interface: Connector
Set the size of the content buffer for receiving requests. These buffers are only used for active connections that have requests with bodies that will not fit within the header buffer.

Specified by:
setRequestBufferSize in interface Connector
Parameters:
requestBufferSize - The requestBufferSize to set.

getResponseBufferSize

public int getResponseBufferSize()
Specified by:
getResponseBufferSize in interface Connector
Returns:
Returns the responseBufferSize.

setResponseBufferSize

public void setResponseBufferSize(int responseBufferSize)
Description copied from interface: Connector
Set the size of the content buffer for sending responses. These buffers are only used for active connections that are sending responses with bodies that will not fit within the header buffer.

Specified by:
setResponseBufferSize in interface Connector
Parameters:
responseBufferSize - The responseBufferSize to set.

getSoLingerTime

public long getSoLingerTime()
Returns:
Returns the soLingerTime.

getAcceptQueueSize

public int getAcceptQueueSize()
Returns:
Returns the acceptQueueSize.

setAcceptQueueSize

public void setAcceptQueueSize(int acceptQueueSize)
Parameters:
acceptQueueSize - The acceptQueueSize to set.

getAcceptors

public int getAcceptors()
Returns:
Returns the number of acceptor threads.

setAcceptors

public void setAcceptors(int acceptors)
Parameters:
acceptors - The number of acceptor threads to set.

setSoLingerTime

public void setSoLingerTime(int soLingerTime)
Parameters:
soLingerTime - The soLingerTime to set.

doStart

protected void doStart()
                throws Exception
Overrides:
doStart in class AbstractLifeCycle
Throws:
Exception

doStop

protected void doStop()
               throws Exception
Overrides:
doStop in class AbstractLifeCycle
Throws:
Exception

join

public void join()
          throws InterruptedException
Throws:
InterruptedException

configure

protected void configure(Socket socket)
                  throws IOException
Throws:
IOException

customize

public void customize(EndPoint endpoint,
                      Request request)
               throws IOException
Description copied from interface: Connector
Customize a request for an endpoint. Called on every request to allow customization of the request for the particular endpoint (eg security properties from a SSL connection).

Specified by:
customize in interface Connector
Parameters:
endpoint -
request -
Throws:
IOException

newBuffer

protected abstract Buffer newBuffer(int size)

getBuffer

public Buffer getBuffer(int size)
Specified by:
getBuffer in interface Buffers

returnBuffer

public void returnBuffer(Buffer buffer)
Specified by:
returnBuffer in interface Buffers

getConfidentialPort

public int getConfidentialPort()
Specified by:
getConfidentialPort in interface Connector

getConfidentialScheme

public String getConfidentialScheme()
Specified by:
getConfidentialScheme in interface Connector

isIntegral

public boolean isIntegral(Request request)
Specified by:
isIntegral in interface Connector

getIntegralPort

public int getIntegralPort()
Specified by:
getIntegralPort in interface Connector

getIntegralScheme

public String getIntegralScheme()
Specified by:
getIntegralScheme in interface Connector

isConfidential

public boolean isConfidential(Request request)
Specified by:
isConfidential in interface Connector

setConfidentialPort

public void setConfidentialPort(int confidentialPort)
Parameters:
confidentialPort - The confidentialPort to set.

setConfidentialScheme

public void setConfidentialScheme(String confidentialScheme)
Parameters:
confidentialScheme - The confidentialScheme to set.

setIntegralPort

public void setIntegralPort(int integralPort)
Parameters:
integralPort - The integralPort to set.

setIntegralScheme

public void setIntegralScheme(String integralScheme)
Parameters:
integralScheme - The integralScheme to set.

newContinuation

public Continuation newContinuation()
Specified by:
newContinuation in interface Connector

accept

protected abstract void accept(int acceptorID)
                        throws IOException,
                               InterruptedException
Throws:
IOException
InterruptedException

getResolveNames

public boolean getResolveNames()
Specified by:
getResolveNames in interface Connector
Returns:
true if names resolution should be done.

setResolveNames

public void setResolveNames(boolean resolve)

toString

public String toString()

getName

public String getName()
Specified by:
getName in interface Connector
Returns:
the name of the connector. Defaults to the HostName:port

setName

public void setName(String name)

getRequests

public int getRequests()
Specified by:
getRequests in interface Connector
Returns:
Get the number of requests handled by this context since last call of statsReset(). If setStatsOn(false) then this is undefined.

getConnectionsDurationMin

public long getConnectionsDurationMin()
Specified by:
getConnectionsDurationMin in interface Connector
Returns:
Returns the connectionsDurationMin.

getConnectionsDurationTotal

public long getConnectionsDurationTotal()
Specified by:
getConnectionsDurationTotal in interface Connector
Returns:
Returns the connectionsDurationTotal.

getConnectionsOpenMin

public int getConnectionsOpenMin()
Specified by:
getConnectionsOpenMin in interface Connector
Returns:
Returns the connectionsOpenMin.

getConnectionsRequestsMin

public int getConnectionsRequestsMin()
Specified by:
getConnectionsRequestsMin in interface Connector
Returns:
Returns the connectionsRequestsMin.

getConnections

public int getConnections()
Specified by:
getConnections in interface Connector
Returns:
Number of connections accepted by the server since statsReset() called. Undefined if setStatsOn(false).

getConnectionsOpen

public int getConnectionsOpen()
Specified by:
getConnectionsOpen in interface Connector
Returns:
Number of connections currently open that were opened since statsReset() called. Undefined if setStatsOn(false).

getConnectionsOpenMax

public int getConnectionsOpenMax()
Specified by:
getConnectionsOpenMax in interface Connector
Returns:
Maximum number of connections opened simultaneously since statsReset() called. Undefined if setStatsOn(false).

getConnectionsDurationAve

public long getConnectionsDurationAve()
Specified by:
getConnectionsDurationAve in interface Connector
Returns:
Average duration in milliseconds of open connections since statsReset() called. Undefined if setStatsOn(false).

getConnectionsDurationMax

public long getConnectionsDurationMax()
Specified by:
getConnectionsDurationMax in interface Connector
Returns:
Maximum duration in milliseconds of an open connection since statsReset() called. Undefined if setStatsOn(false).

getConnectionsRequestsAve

public int getConnectionsRequestsAve()
Specified by:
getConnectionsRequestsAve in interface Connector
Returns:
Average number of requests per connection since statsReset() called. Undefined if setStatsOn(false).

getConnectionsRequestsMax

public int getConnectionsRequestsMax()
Specified by:
getConnectionsRequestsMax in interface Connector
Returns:
Maximum number of requests per connection since statsReset() called. Undefined if setStatsOn(false).

statsReset

public void statsReset()
Reset statistics.

Specified by:
statsReset in interface Connector

setStatsOn

public void setStatsOn(boolean on)
Specified by:
setStatsOn in interface Connector

getStatsOn

public boolean getStatsOn()
Specified by:
getStatsOn in interface Connector
Returns:
True if statistics collection is turned on.

getStatsOnMs

public long getStatsOnMs()
Specified by:
getStatsOnMs in interface Connector
Returns:
Timestamp stats were started at.

connectionOpened

protected void connectionOpened(HttpConnection connection)

connectionClosed

protected void connectionClosed(HttpConnection connection)