com.sun.grizzly.http
Class SelectorThread

java.lang.Object
  extended by java.lang.Thread
      extended by com.sun.grizzly.http.SelectorThread
All Implemented Interfaces:
Runnable, MBeanRegistration
Direct Known Subclasses:
RailsSelectorThread, SSLSelectorThread

public class SelectorThread
extends Thread
implements MBeanRegistration

The SelectorThread class is the entry point when embedding the Grizzly Web Server. All Web Server configuration must be set on this object before invoking the listen() method. As an example:


        final SelectorThread selectorThread = new SelectorThread(){
                public void listen() throws IOException, InstantiationException{
                    super.listen();
                    System.out.println("Server started in " + (System.currentTimeMillis() - t1)
                            + " milliseconds.");
                }
        };
        selectorThread.setAlgorithmClassName(StaticStreamAlgorithm.class.getName());       
        selectorThread.setPort(port);
        SelectorThread.setWebAppRootPath(folder);
        Adapter adapter = new StaticResourcesAdapter(folder);
        ((StaticResourcesAdapter)adapter).setRootFolder(folder);
        selectorThread.setAdapter(adapter);
        selectorThread.setDisplayConfiguration(true);
        selectorThread.listen(); 
 

Author:
Jean-Francois Arcand

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
 
Field Summary
protected  ConcurrentLinkedQueue<ProcessorTask> activeProcessorTasks
          List of active ProcessorTask.
protected  Adapter adapter
          Associated adapter.
protected  Class algorithmClass
          The Algorithm used to predict the end of the NIO stream
protected  String algorithmClassName
          The Algorithm used to parse the NIO stream.
protected  boolean asyncExecution
          Is asynchronous mode enabled?
protected  AsyncHandler asyncHandler
          When the asynchronous mode is enabled, the execution of this object will be delegated to the AsyncHandler
protected  boolean bufferResponse
          Buffer the response until the buffer is full.
protected  String compressableMimeTypes
           
protected  String compression
          Compression value.
protected  int compressionMinSize
           
protected  Controller controller
          The Grizzly's Controller.
static String DEFAULT_ALGORITHM
          The default NIO stream algorithm.
protected static boolean defaultAlgorithmInstalled
          Is the DEFAULT_ALGORITHM used.
protected  String defaultResponseType
          The default response-type
protected  boolean disableUploadTimeout
          Flag to disable setting a different time-out on uploads.
protected  boolean displayConfiguration
          If true, display the NIO configuration information.
protected  String domain
           
protected  boolean enableNioLogging
          Grizzly own debug flag.
protected  FileCacheFactory fileCacheFactory
          The FileCacheFactory associated with this Selector
protected  String forcedRequestType
          The forced request-type
protected  RequestGroupInfo globalRequestProcessor
          Monitoring object used to store information.
protected  ObjectName globalRequestProcessorName
           
protected  InetAddress inet
           
protected  boolean initialized
           
protected  boolean isFileCacheEnabled
          Is the FileCache enabled.
protected  boolean isLargeFileCacheEnabled
          Is the large FileCache enabled.
protected  boolean isMonitoringEnabled
          Is monitoring already started.
protected  KeepAliveCountManager keepAliveCounter
          Keep-Alive subsystem.
protected  int keepAliveThreadCount
           
protected  int keepAliveTimeoutInSeconds
           
protected  int linger
           
protected static Logger logger
          The logger used by the grizzly classes.
protected  int maxCacheEntries
          The maximum entries in the fileCache
protected  long maxEntrySize
          The maximum size of a cached resources.
protected  int maxHttpHeaderSize
          Default HTTP header buffer size.
protected  int maxKeepAliveRequests
           
protected  long maxLargeFileCacheSize
          The maximum cached bytes
protected  int maxPostSize
           
protected  int maxQueueSizeInBytes
          Maximum pending connection before refusing requests.
protected  long maxSmallFileCacheSize
          The maximum cached bytes
protected  int maxThreads
          Maximum number of WorkerThread
protected  long minEntrySize
          The maximum size of a cached resources.
protected  int minWorkerThreads
          Minimum numbers of WorkerThread created
protected  MBeanServer mserver
           
protected  String noCompressionUserAgents
           
protected  ObjectName oname
           
protected  boolean oOBInline
           
protected  String pipelineClassName
          The default Pipeline used.
protected  PipelineStatistic pipelineStat
          Placeholder for Pipeline statistic.
protected  int port
           
protected  PUReadFilter portUnificationFilter
          Port unification filter
protected  LinkedListPipeline processorPipeline
          The queue shared by this thread and the code>ProcessorTask.
protected  ConcurrentLinkedQueue<ProcessorTask> processorTasks
          ConcurrentLinkedQueue used as an object pool.
protected  ObjectName processorWorkerThreadName
           
protected  HashMap<String,Object> properties
          Holder for our configured properties.
protected  boolean rcmSupport
          RCM support
protected  int readThreadsCount
          The number of SelectorReadThread
protected  boolean recycleTasks
          Recycle the Task after running them
protected  int requestBufferSize
          The input request buffer size.
protected  String restrictedUserAgents
           
protected static String rootFolder
          The root folder where application are deployed
protected  boolean running
           
protected  int secondsMaxAge
          Timeout before remove the static resource from the cache.
protected  Selector selector
          The Selector used by the connector.
protected  TCPSelectorHandler selectorHandler
          SelectorHandler current SelectorThread is based on
protected static int selectorTimeout
          The Selector timeout value.
static String SERVER_NAME
           
protected  int serverTimeout
           
protected  int socketTimeout
           
protected  int ssBackLog
          Server socket backlog.
protected  boolean tcpNoDelay
           
protected  int threadsIncrement
          The number used when increamenting the Pipeline thread pool.
protected  int threadsTimeout
          The timeout used by the thread when processing a request.
protected  int uploadTimeout
          Maximum timeout on uploads.
protected  boolean useByteBufferView
          Create view ByteBuffer from another ByteBuffer
protected  boolean useDirectByteBuffer
          Is the ByteBuffer used by the ReadTask use direct ByteBuffer or not.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
SelectorThread()
          Create the Selector object.
 
Method Summary
 void cancelKey(SelectionKey key)
          Cancel the current SelectionKey
protected  void clearTasks()
          Clear all cached Tasks
protected  void configureCompression(DefaultProcessorTask processorTask)
           
protected  void configureFilters(ProtocolChain protocolChain)
          Adds and configures ProtocolChain's filters
 void configurePortUnification(List<ProtocolFinder> protocolFinders, List<ProtocolHandler> protocolHandlers, List<PUPreProcessor> preProcessors)
          Configures port unification depending on passed Lists
 void configurePortUnification(Properties props)
          Configures port unification depending on passed Properties
protected  ProcessorTask configureProcessorTask(DefaultProcessorTask task)
           
protected  void configureSelectorHandler(TCPSelectorHandler selectorHandler)
          Configure TCPSelectorHandler
protected  ProtocolFilter createHttpParserFilter()
          Create HTTP parser ProtocolFilter
protected  ProtocolFilter createRaFilter()
          Create and configure resource allocation ProtocolFilter
protected  TCPSelectorHandler createSelectorHandler()
          Create TCPSelectorHandler
 void disableMonitoring()
          Disable gathering of monitoring datas.
protected  void disablePipelineStats()
          Removes PipelineStatistic from every Pipeline, when monitoring has been turned off.
 void enableMonitoring()
          Enable gathering of monitoring datas.
protected  void enablePipelineStats()
          Injects PipelineStatistic into every Pipeline, for monitoring purposes.
 void enableRcmSupport(boolean rcmSupport)
          Enable Application Resource Allocation Grizzly Extension.
 ConcurrentLinkedQueue<ProcessorTask> getActiveProcessorTasks()
           
 Adapter getAdapter()
          Get the associated adapter.
 InetAddress getAddress()
           
 String getAlgorithmClassName()
           
 AsyncHandler getAsyncHandler()
          Return the AsyncHandler used when asynchronous execution is enabled.
 boolean getBufferResponse()
          Return true if the reponse is buffered.
 int getBufferSize()
          Return the request input buffer size
 ClassLoader getClassLoader()
           
 String getCompressableMimeTypes()
           
 String getCompression()
           
 int getCompressionMinSize()
           
 Controller getController()
           
 int getCurrentBusyProcessorThreads()
          Provides the count of request threads that are currently being processed by the container
 String getDefaultResponseType()
           
 boolean getDisableUploadTimeout()
          Get the flag that controls upload time-outs.
 String getDomain()
           
 boolean getEnableAsyncExecution()
          Return true when asynchronous execution is enabled.
 String getForcedRequestType()
           
 RequestGroupInfo getGlobalRequestProcessor()
           
 InetAddress getInet()
           
 KeepAliveCountManager getKeepAliveCounter()
           
 KeepAliveStats getKeepAliveStats()
           
 int getKeepAliveThreadCount()
          Gets the number of keep-alive threads.
 int getKeepAliveTimeoutInSeconds()
          Gets the number of seconds before a keep-alive connection that has been idle times out and is closed.
 boolean getLargeFileCacheEnabled()
          Is the large file cache support enabled.
 int getLinger()
           
 Management getManagement()
           
 int getMaxCacheEntries()
          Return the maximum entries this cache can contains.
 long getMaxEntrySize()
          Get the maximum size a FileCacheEntry can have.
 int getMaxHttpHeaderSize()
           
 int getMaxKeepAliveRequests()
           
 long getMaxLargeCacheSize()
          Get the maximum cache size
 int getMaxPostSize()
           
 int getMaxQueueSizeInBytes()
           
 long getMaxSmallCacheSize()
          Get the maximum cache size
 int getMaxThreads()
           
 long getMinEntrySize()
          Get the maximum size a FileCacheEntry can have.
 int getMinWorkerThreads()
           
 String getNoCompressionUserAgents()
           
 ObjectName getObjectName()
           
 String getPipelineClassName()
           
 int getPort()
           
 int getPortLowLevel()
          Similar to getPort(), but getting port number directly from connection (ServerSocket, DatagramSocket).
 Pipeline getProcessorPipeline()
           
 ProcessorTask getProcessorTask()
          Return a ProcessorTask from the pool.
 Object getProperty(String name)
          Return a configured property.
 int getQueueSizeInBytes()
          Get the maximum pending connection this Pipeline can handle.
 RequestGroupInfo getRequestGroupInfo()
           
 String getRestrictedUserAgents()
           
 boolean getReuseAddress()
           
 Selector getSelector()
           
static SelectorThread getSelector(int port)
          Return the SelectorThread which listen on port, or null if there is no SelectorThread.
 int getSelectorReadThreadsCount()
           
static Enumeration<SelectorThread> getSelectors()
          Return an Enumeration of the active SelectorThreads
 SelectorThreadKeyHandler getSelectorThreadKeyHandler()
           
static int getSelectorTimeout()
           
 int getServerTimeout()
           
 int getSocketTimeout()
           
 int getSsBackLog()
           
 boolean getTcpNoDelay()
           
 int getThreadsIncrement()
           
 int getUploadTimeout()
          Get the upload timeout.
static String getWebAppRootPath()
          Return the folder's root where application are deployed.
protected  void initAlgorithm()
          Load using reflection the Algorithm class.
protected  void initController()
          Initialize the Grizzly Framework classes.
 void initEndpoint()
          initialized the endpoint by creating the ServerScoketChannel and by initializing the server socket.
protected  void initFileCacheFactory()
          Initialize the fileCacheFactory associated with this instance
protected  void initKeepAliveCounter()
          Initialize the keep-alive mechanism.
protected  void initMonitoringLevel()
           
protected  void initPipeline()
          Init the Pipelines used by the WorkerThreads.
protected  void initProcessorTask(int size)
          Create a pool of ProcessorTask
 boolean isEnableNioLogging()
           
 boolean isFileCacheEnabled()
          Is the fileCache enabled.
 boolean isMonitoringEnabled()
          Returns true if monitoring has been enabled, false otherwise.
 boolean isRcmSupported()
          Returns whether Application Resource Allocation Grizzly Extension is supported
 boolean isRunning()
           
 boolean isUseByteBufferView()
           
 boolean isUseDirectByteBuffer()
           
 void listen()
          Start the SelectorThread using its own thread and don't block the Thread.
static Logger logger()
          Return the logger used by the Grizzly classes.
protected  LinkedListPipeline newPipeline(int maxThreads, int minThreads, String name, int port, int priority)
          Create a new Pipeline instance using the pipelineClassName value.
protected  ProcessorTask newProcessorTask(boolean initialize)
          Create ProcessorTask objects and configure it to be ready to proceed request.
 void postDeregister()
           
 void postRegister(Boolean registrationDone)
           
 void preDeregister()
           
 ObjectName preRegister(MBeanServer server, ObjectName name)
           
protected  void rampUpProcessorTask()
          Initialize ProcessorTask
protected  void reconfigureAsyncExecution()
          Reconfigure Grizzly Asynchronous Request Processing(ARP) internal objects.
protected  void registerComponents()
          Register JMX components.
 void registerKey(SelectionKey key)
          Register a SelectionKey to this Selector running of this thread.
 void removeCacheEntry(String contextPath)
          Remove a context path from the FileCache.
 void removeProperty(String name)
          remove a configured property.
 void returnTask(Task task)
          Returns the Task object to the pool.
 void run()
          Start the endpoint (this)
 void setAdapter(Adapter adapter)
          Set the associated adapter.
 void setAddress(InetAddress inet)
           
 void setAlgorithmClassName(String algorithmClassName)
           
 void setAsyncHandler(AsyncHandler asyncHandler)
          Set the AsyncHandler used when asynchronous execution is enabled.
 void setBufferResponse(boolean bufferResponse)
          trueif the reponse willk be buffered.
 void setBufferSize(int requestBufferSize)
          Set the request input buffer size
 void setClassLoader(ClassLoader classLoader)
          Set the ClassLoader used to load configurable classes (Pipeline, StreamAlgorithm).
 void setCompressableMimeTypes(String compressableMimeTypes)
           
 void setCompression(String compression)
           
 void setCompressionMinSize(int compressionMinSize)
           
 void setController(Controller controller)
           
 void setDefaultResponseType(String defaultResponseType)
           
 void setDisableUploadTimeout(boolean isDisabled)
          Set the flag to control upload time-outs.
 void setDisplayConfiguration(boolean displayConfiguration)
           
 void setEnableAsyncExecution(boolean asyncExecution)
          Enable the AsyncHandler used when asynchronous
 void setEnableNioLogging(boolean enableNioLogging)
           
 void setFileCacheIsEnabled(boolean isFileCacheEnabled)
          Is the file caching mechanism enabled.
 void setForcedRequestType(String forcedRequestType)
           
 void setInet(InetAddress inet)
           
 void setKeepAliveThreadCount(int threadCount)
          Sets the number of keep-alive threads.
 void setKeepAliveTimeoutInSeconds(int timeout)
          Sets the number of seconds before a keep-alive connection that has been idle times out and is closed.
 void setLargeFileCacheEnabled(boolean isLargeEnabled)
          Is the large file cache support enabled.
 void setLinger(int i)
           
static void setLogger(Logger l)
          Set the logger used by this instance.
 void setManagement(Management jmxManagement)
           
 void setMaxCacheEntries(int mEntries)
          Set the maximum entries this cache can contains.
 void setMaxEntrySize(long mEntrySize)
          Set the maximum size a FileCacheEntry can have.
 void setMaxHttpHeaderSize(int maxHttpHeaderSize)
           
 void setMaxKeepAliveRequests(int mkar)
          Set the maximum number of Keep-Alive requests that we will honor.
 void setMaxLargeCacheSize(long mCacheSize)
          Set the maximum cache size
 void setMaxPostSize(int maxPostSize)
           
 void setMaxQueueSizeInBytes(int maxQueueSizeInBytes)
           
 void setMaxSmallCacheSize(long mCacheSize)
          Set the maximum cache size
 void setMaxThreads(int maxThreads)
           
 void setMinEntrySize(long mSize)
          Set the maximum size a FileCacheEntry can have.
 void setMinThreads(int minWorkerThreads)
          The minimun threads created at startup.
 void setMinWorkerThreads(int minWorkerThreads)
           
 void setNoCompressionUserAgents(String noCompressionUserAgents)
           
 void setPipelineClassName(String pipelineClassName)
           
 void setPort(int port)
           
 void setProperty(String name, Object value)
          Set a configured property.
 void setRestrictedUserAgents(String restrictedUserAgents)
           
 void setReuseAddress(boolean reuseAddress)
           
 void setSecondsMaxAge(int sMaxAges)
          The timeout in seconds before remove a FileCacheEntry from the fileCache
 void setSelectorReadThreadsCount(int readThreadsCount)
           
static void setSelectorTimeout(int aSelectorTimeout)
           
 void setServerTimeout(int timeout)
          Sets the timeout in ms of the server sockets created by this server.
protected  void setSocketOptions(Socket socket)
           
 void setSocketTimeout(int socketTimeout)
           
 void setSsBackLog(int ssBackLog)
           
 void setTcpNoDelay(boolean b)
           
 void setThreadsIncrement(int threadsIncrement)
           
 void setUploadTimeout(int uploadTimeout)
          Set the upload timeout.
 void setUseByteBufferView(boolean useByteBufferView)
           
 void setUseDirectByteBuffer(boolean useDirectByteBuffer)
           
static void setWebAppRootPath(String rf)
          Set the document root folder
 void startEndpoint()
          Start the Acceptor Thread and wait for incoming connection, in a non blocking mode.
protected  void startListener()
          Start a non blocking Selector object.
protected  void startPipelines()
          Starts the Pipeline used by this Selector
 void stopEndpoint()
           
protected  void stopPipelines()
          Stop the Pipeline used by this Selector
protected  void unregisterComponents()
          Unregister components.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SERVER_NAME

public static final String SERVER_NAME

serverTimeout

protected int serverTimeout

inet

protected InetAddress inet

port

protected int port

initialized

protected boolean initialized

running

protected volatile boolean running

domain

protected String domain

oname

protected ObjectName oname

globalRequestProcessorName

protected ObjectName globalRequestProcessorName

mserver

protected MBeanServer mserver

processorWorkerThreadName

protected ObjectName processorWorkerThreadName

tcpNoDelay

protected boolean tcpNoDelay

linger

protected int linger

socketTimeout

protected int socketTimeout

maxKeepAliveRequests

protected int maxKeepAliveRequests

keepAliveThreadCount

protected int keepAliveThreadCount

compression

protected String compression
Compression value.


noCompressionUserAgents

protected String noCompressionUserAgents

restrictedUserAgents

protected String restrictedUserAgents

compressableMimeTypes

protected String compressableMimeTypes

compressionMinSize

protected int compressionMinSize

bufferResponse

protected boolean bufferResponse
Buffer the response until the buffer is full.


maxHttpHeaderSize

protected int maxHttpHeaderSize
Default HTTP header buffer size.


maxPostSize

protected int maxPostSize

selector

protected Selector selector
The Selector used by the connector.


selectorHandler

protected TCPSelectorHandler selectorHandler
SelectorHandler current SelectorThread is based on


adapter

protected Adapter adapter
Associated adapter.


processorPipeline

protected LinkedListPipeline processorPipeline
The queue shared by this thread and the code>ProcessorTask.


pipelineStat

protected PipelineStatistic pipelineStat
Placeholder for Pipeline statistic.


pipelineClassName

protected String pipelineClassName
The default Pipeline used.


maxThreads

protected int maxThreads
Maximum number of WorkerThread


minWorkerThreads

protected int minWorkerThreads
Minimum numbers of WorkerThread created


threadsIncrement

protected int threadsIncrement
The number used when increamenting the Pipeline thread pool.


threadsTimeout

protected int threadsTimeout
The timeout used by the thread when processing a request.


useDirectByteBuffer

protected boolean useDirectByteBuffer
Is the ByteBuffer used by the ReadTask use direct ByteBuffer or not.


globalRequestProcessor

protected RequestGroupInfo globalRequestProcessor
Monitoring object used to store information.


displayConfiguration

protected boolean displayConfiguration
If true, display the NIO configuration information.


isMonitoringEnabled

protected boolean isMonitoringEnabled
Is monitoring already started.


requestBufferSize

protected int requestBufferSize
The input request buffer size.


useByteBufferView

protected boolean useByteBufferView
Create view ByteBuffer from another ByteBuffer


keepAliveTimeoutInSeconds

protected int keepAliveTimeoutInSeconds

recycleTasks

protected boolean recycleTasks
Recycle the Task after running them


selectorTimeout

protected static int selectorTimeout
The Selector timeout value. By default, it is set to 60000 miliseconds (as in the j2se 1.5 ORB).


maxQueueSizeInBytes

protected int maxQueueSizeInBytes
Maximum pending connection before refusing requests.


algorithmClass

protected Class algorithmClass
The Algorithm used to predict the end of the NIO stream


algorithmClassName

protected String algorithmClassName
The Algorithm used to parse the NIO stream.


DEFAULT_ALGORITHM

public static final String DEFAULT_ALGORITHM
The default NIO stream algorithm.


ssBackLog

protected int ssBackLog
Server socket backlog.


defaultResponseType

protected String defaultResponseType
The default response-type


forcedRequestType

protected String forcedRequestType
The forced request-type


rootFolder

protected static String rootFolder
The root folder where application are deployed


controller

protected Controller controller
The Grizzly's Controller.


rcmSupport

protected boolean rcmSupport
RCM support


portUnificationFilter

protected PUReadFilter portUnificationFilter
Port unification filter


oOBInline

protected boolean oOBInline

properties

protected HashMap<String,Object> properties
Holder for our configured properties.


processorTasks

protected ConcurrentLinkedQueue<ProcessorTask> processorTasks
ConcurrentLinkedQueue used as an object pool. If the list becomes empty, new ProcessorTask will be automatically added to the list.


activeProcessorTasks

protected ConcurrentLinkedQueue<ProcessorTask> activeProcessorTasks
List of active ProcessorTask.


readThreadsCount

protected int readThreadsCount
The number of SelectorReadThread


logger

protected static Logger logger
The logger used by the grizzly classes.


disableUploadTimeout

protected boolean disableUploadTimeout
Flag to disable setting a different time-out on uploads.


uploadTimeout

protected int uploadTimeout
Maximum timeout on uploads. 5 minutes as in Apache HTTPD server.


keepAliveCounter

protected KeepAliveCountManager keepAliveCounter
Keep-Alive subsystem. If a client opens a socket but never close it, the SelectionKey will stay forever in the Selector keys, and this will eventualy produce a memory leak.


fileCacheFactory

protected FileCacheFactory fileCacheFactory
The FileCacheFactory associated with this Selector


secondsMaxAge

protected int secondsMaxAge
Timeout before remove the static resource from the cache.


maxCacheEntries

protected int maxCacheEntries
The maximum entries in the fileCache


minEntrySize

protected long minEntrySize
The maximum size of a cached resources.


maxEntrySize

protected long maxEntrySize
The maximum size of a cached resources.


maxLargeFileCacheSize

protected long maxLargeFileCacheSize
The maximum cached bytes


maxSmallFileCacheSize

protected long maxSmallFileCacheSize
The maximum cached bytes


isFileCacheEnabled

protected boolean isFileCacheEnabled
Is the FileCache enabled.


isLargeFileCacheEnabled

protected boolean isLargeFileCacheEnabled
Is the large FileCache enabled.


asyncExecution

protected boolean asyncExecution
Is asynchronous mode enabled?


asyncHandler

protected AsyncHandler asyncHandler
When the asynchronous mode is enabled, the execution of this object will be delegated to the AsyncHandler


defaultAlgorithmInstalled

protected static boolean defaultAlgorithmInstalled
Is the DEFAULT_ALGORITHM used.


enableNioLogging

protected boolean enableNioLogging
Grizzly own debug flag.

Constructor Detail

SelectorThread

public SelectorThread()
Create the Selector object. Each instance of this class will listen to a specific port.

Method Detail

getSelector

public static final SelectorThread getSelector(int port)
Return the SelectorThread which listen on port, or null if there is no SelectorThread.


getSelectors

public static final Enumeration<SelectorThread> getSelectors()
Return an Enumeration of the active SelectorThreads


registerKey

public void registerKey(SelectionKey key)
Register a SelectionKey to this Selector running of this thread.


initController

protected void initController()
Initialize the Grizzly Framework classes.


createSelectorHandler

protected TCPSelectorHandler createSelectorHandler()
Create TCPSelectorHandler


configureSelectorHandler

protected void configureSelectorHandler(TCPSelectorHandler selectorHandler)
Configure TCPSelectorHandler


createRaFilter

protected ProtocolFilter createRaFilter()
Create and configure resource allocation ProtocolFilter

Returns:
resource allocation ProtocolFilter

createHttpParserFilter

protected ProtocolFilter createHttpParserFilter()
Create HTTP parser ProtocolFilter

Returns:
HTTP parser ProtocolFilter

configureFilters

protected void configureFilters(ProtocolChain protocolChain)
Adds and configures ProtocolChain's filters

Parameters:
ProtocolChain - to configure

configurePortUnification

public void configurePortUnification(Properties props)
Configures port unification depending on passed Properties

Parameters:
props - Properties. If props is null - port unification will be configured from System properties

configurePortUnification

public void configurePortUnification(List<ProtocolFinder> protocolFinders,
                                     List<ProtocolHandler> protocolHandlers,
                                     List<PUPreProcessor> preProcessors)
Configures port unification depending on passed Lists

Parameters:
protocolFinders - ProtocolFinders
protocolHandlers - ProtocolHandlers
preProcessors - PUPreProcessors

newPipeline

protected LinkedListPipeline newPipeline(int maxThreads,
                                         int minThreads,
                                         String name,
                                         int port,
                                         int priority)
Create a new Pipeline instance using the pipelineClassName value.


initFileCacheFactory

protected void initFileCacheFactory()
Initialize the fileCacheFactory associated with this instance


enablePipelineStats

protected void enablePipelineStats()
Injects PipelineStatistic into every Pipeline, for monitoring purposes.


disablePipelineStats

protected void disablePipelineStats()
Removes PipelineStatistic from every Pipeline, when monitoring has been turned off.


initAlgorithm

protected void initAlgorithm()
Load using reflection the Algorithm class.


initKeepAliveCounter

protected void initKeepAliveCounter()
Initialize the keep-alive mechanism.


initPipeline

protected void initPipeline()
Init the Pipelines used by the WorkerThreads.


initProcessorTask

protected void initProcessorTask(int size)
Create a pool of ProcessorTask


rampUpProcessorTask

protected void rampUpProcessorTask()
Initialize ProcessorTask


newProcessorTask

protected ProcessorTask newProcessorTask(boolean initialize)
Create ProcessorTask objects and configure it to be ready to proceed request.


configureProcessorTask

protected ProcessorTask configureProcessorTask(DefaultProcessorTask task)

reconfigureAsyncExecution

protected void reconfigureAsyncExecution()
Reconfigure Grizzly Asynchronous Request Processing(ARP) internal objects.


getProcessorTask

public ProcessorTask getProcessorTask()
Return a ProcessorTask from the pool. If the pool is empty, create a new instance.


run

public void run()
Start the endpoint (this)

Specified by:
run in interface Runnable
Overrides:
run in class Thread

initEndpoint

public void initEndpoint()
                  throws IOException,
                         InstantiationException
initialized the endpoint by creating the ServerScoketChannel and by initializing the server socket.

Throws:
IOException
InstantiationException

stopEndpoint

public void stopEndpoint()

startEndpoint

public void startEndpoint()
                   throws IOException,
                          InstantiationException
Start the Acceptor Thread and wait for incoming connection, in a non blocking mode.

Throws:
IOException
InstantiationException

listen

public void listen()
            throws IOException,
                   InstantiationException
Start the SelectorThread using its own thread and don't block the Thread. This method should be used when Grizzly is embedded.

Throws:
IOException
InstantiationException

startPipelines

protected void startPipelines()
Starts the Pipeline used by this Selector


stopPipelines

protected void stopPipelines()
Stop the Pipeline used by this Selector


startListener

protected void startListener()
Start a non blocking Selector object.


cancelKey

public void cancelKey(SelectionKey key)
Cancel the current SelectionKey


returnTask

public void returnTask(Task task)
Returns the Task object to the pool.


clearTasks

protected void clearTasks()
Clear all cached Tasks


setMaxThreads

public void setMaxThreads(int maxThreads)

getMaxThreads

public int getMaxThreads()

getPortLowLevel

public int getPortLowLevel()
Similar to getPort(), but getting port number directly from connection (ServerSocket, DatagramSocket). So if default port number 0 was set during initialization, then getPort() will return 0, but getPortLowLevel() will return port number assigned by OS.

Returns:
port number, or -1 if SelectorThread was not started

getPort

public int getPort()

setPort

public void setPort(int port)

getAddress

public InetAddress getAddress()

setAddress

public void setAddress(InetAddress inet)

isRunning

public boolean isRunning()

getCurrentBusyProcessorThreads

public int getCurrentBusyProcessorThreads()
Provides the count of request threads that are currently being processed by the container

Returns:
The count of busy threads

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.


getTcpNoDelay

public boolean getTcpNoDelay()

setTcpNoDelay

public void setTcpNoDelay(boolean b)

getLinger

public int getLinger()

setLinger

public void setLinger(int i)

getServerTimeout

public int getServerTimeout()

getInet

public InetAddress getInet()

setInet

public void setInet(InetAddress inet)

getSocketTimeout

public int getSocketTimeout()

setSocketTimeout

public void setSocketTimeout(int socketTimeout)

getQueueSizeInBytes

public int getQueueSizeInBytes()
Get the maximum pending connection this Pipeline can handle.


getMaxKeepAliveRequests

public int getMaxKeepAliveRequests()

setMaxKeepAliveRequests

public void setMaxKeepAliveRequests(int mkar)
Set the maximum number of Keep-Alive requests that we will honor.


setKeepAliveTimeoutInSeconds

public void setKeepAliveTimeoutInSeconds(int timeout)
Sets the number of seconds before a keep-alive connection that has been idle times out and is closed.

Parameters:
timeout - Keep-alive timeout in number of seconds

getKeepAliveTimeoutInSeconds

public int getKeepAliveTimeoutInSeconds()
Gets the number of seconds before a keep-alive connection that has been idle times out and is closed.

Returns:
Keep-alive timeout in number of seconds

getKeepAliveThreadCount

public int getKeepAliveThreadCount()
Gets the number of keep-alive threads.

Returns:
number of keep-alive threads

setKeepAliveThreadCount

public void setKeepAliveThreadCount(int threadCount)
Sets the number of keep-alive threads.

Parameters:
threadCount - Number of keep-alive threads

setAdapter

public void setAdapter(Adapter adapter)
Set the associated adapter.

Parameters:
adapter - the new adapter

getAdapter

public Adapter getAdapter()
Get the associated adapter.

Returns:
the associated adapter

setSocketOptions

protected void setSocketOptions(Socket socket)

getObjectName

public ObjectName getObjectName()

getDomain

public String getDomain()

preRegister

public ObjectName preRegister(MBeanServer server,
                              ObjectName name)
                       throws Exception
Specified by:
preRegister in interface MBeanRegistration
Throws:
Exception

postRegister

public void postRegister(Boolean registrationDone)
Specified by:
postRegister in interface MBeanRegistration

preDeregister

public void preDeregister()
                   throws Exception
Specified by:
preDeregister in interface MBeanRegistration
Throws:
Exception

postDeregister

public void postDeregister()
Specified by:
postDeregister in interface MBeanRegistration

registerComponents

protected void registerComponents()
Register JMX components.


unregisterComponents

protected void unregisterComponents()
Unregister components.


getManagement

public Management getManagement()

setManagement

public void setManagement(Management jmxManagement)

enableMonitoring

public void enableMonitoring()
Enable gathering of monitoring datas.


disableMonitoring

public void disableMonitoring()
Disable gathering of monitoring datas.


isMonitoringEnabled

public boolean isMonitoringEnabled()
Returns true if monitoring has been enabled, false otherwise.


getRequestGroupInfo

public RequestGroupInfo getRequestGroupInfo()

getKeepAliveStats

public KeepAliveStats getKeepAliveStats()

initMonitoringLevel

protected void initMonitoringLevel()

getMaxHttpHeaderSize

public int getMaxHttpHeaderSize()

setMaxHttpHeaderSize

public void setMaxHttpHeaderSize(int maxHttpHeaderSize)

setMinThreads

public void setMinThreads(int minWorkerThreads)
The minimun threads created at startup.


setBufferSize

public void setBufferSize(int requestBufferSize)
Set the request input buffer size


getBufferSize

public int getBufferSize()
Return the request input buffer size


getSelector

public Selector getSelector()

getController

public Controller getController()

setController

public void setController(Controller controller)

removeCacheEntry

public void removeCacheEntry(String contextPath)
Remove a context path from the FileCache.


setSecondsMaxAge

public void setSecondsMaxAge(int sMaxAges)
The timeout in seconds before remove a FileCacheEntry from the fileCache


setMaxCacheEntries

public void setMaxCacheEntries(int mEntries)
Set the maximum entries this cache can contains.


getMaxCacheEntries

public int getMaxCacheEntries()
Return the maximum entries this cache can contains.


setMinEntrySize

public void setMinEntrySize(long mSize)
Set the maximum size a FileCacheEntry can have.


getMinEntrySize

public long getMinEntrySize()
Get the maximum size a FileCacheEntry can have.


setMaxEntrySize

public void setMaxEntrySize(long mEntrySize)
Set the maximum size a FileCacheEntry can have.


getMaxEntrySize

public long getMaxEntrySize()
Get the maximum size a FileCacheEntry can have.


setMaxLargeCacheSize

public void setMaxLargeCacheSize(long mCacheSize)
Set the maximum cache size


getMaxLargeCacheSize

public long getMaxLargeCacheSize()
Get the maximum cache size


setMaxSmallCacheSize

public void setMaxSmallCacheSize(long mCacheSize)
Set the maximum cache size


getMaxSmallCacheSize

public long getMaxSmallCacheSize()
Get the maximum cache size


isFileCacheEnabled

public boolean isFileCacheEnabled()
Is the fileCache enabled.


setFileCacheIsEnabled

public void setFileCacheIsEnabled(boolean isFileCacheEnabled)
Is the file caching mechanism enabled.


setLargeFileCacheEnabled

public void setLargeFileCacheEnabled(boolean isLargeEnabled)
Is the large file cache support enabled.


getLargeFileCacheEnabled

public boolean getLargeFileCacheEnabled()
Is the large file cache support enabled.


setEnableAsyncExecution

public void setEnableAsyncExecution(boolean asyncExecution)
Enable the AsyncHandler used when asynchronous


getEnableAsyncExecution

public boolean getEnableAsyncExecution()
Return true when asynchronous execution is enabled.


setAsyncHandler

public void setAsyncHandler(AsyncHandler asyncHandler)
Set the AsyncHandler used when asynchronous execution is enabled.


getAsyncHandler

public AsyncHandler getAsyncHandler()
Return the AsyncHandler used when asynchronous execution is enabled.


setLogger

public static void setLogger(Logger l)
Set the logger used by this instance.


logger

public static Logger logger()
Return the logger used by the Grizzly classes.


setWebAppRootPath

public static void setWebAppRootPath(String rf)
Set the document root folder


getWebAppRootPath

public static String getWebAppRootPath()
Return the folder's root where application are deployed.


getBufferResponse

public boolean getBufferResponse()
Return true if the reponse is buffered.


setBufferResponse

public void setBufferResponse(boolean bufferResponse)
trueif the reponse willk be buffered.


enableRcmSupport

public void enableRcmSupport(boolean rcmSupport)
Enable Application Resource Allocation Grizzly Extension.


isRcmSupported

public boolean isRcmSupported()
Returns whether Application Resource Allocation Grizzly Extension is supported

Returns:
is RCM supported

getKeepAliveCounter

public KeepAliveCountManager getKeepAliveCounter()

configureCompression

protected void configureCompression(DefaultProcessorTask processorTask)

getCompression

public String getCompression()

setCompression

public void setCompression(String compression)

getNoCompressionUserAgents

public String getNoCompressionUserAgents()

setNoCompressionUserAgents

public void setNoCompressionUserAgents(String noCompressionUserAgents)

getRestrictedUserAgents

public String getRestrictedUserAgents()

setRestrictedUserAgents

public void setRestrictedUserAgents(String restrictedUserAgents)

getCompressableMimeTypes

public String getCompressableMimeTypes()

setCompressableMimeTypes

public void setCompressableMimeTypes(String compressableMimeTypes)

getCompressionMinSize

public int getCompressionMinSize()

setCompressionMinSize

public void setCompressionMinSize(int compressionMinSize)

getSelectorReadThreadsCount

public int getSelectorReadThreadsCount()

setSelectorReadThreadsCount

public void setSelectorReadThreadsCount(int readThreadsCount)

getProcessorPipeline

public Pipeline getProcessorPipeline()

getPipelineClassName

public String getPipelineClassName()

setPipelineClassName

public void setPipelineClassName(String pipelineClassName)

getMinWorkerThreads

public int getMinWorkerThreads()

setMinWorkerThreads

public void setMinWorkerThreads(int minWorkerThreads)

getThreadsIncrement

public int getThreadsIncrement()

setThreadsIncrement

public void setThreadsIncrement(int threadsIncrement)

isUseDirectByteBuffer

public boolean isUseDirectByteBuffer()

setUseDirectByteBuffer

public void setUseDirectByteBuffer(boolean useDirectByteBuffer)

getGlobalRequestProcessor

public RequestGroupInfo getGlobalRequestProcessor()

setDisplayConfiguration

public void setDisplayConfiguration(boolean displayConfiguration)

isUseByteBufferView

public boolean isUseByteBufferView()

setUseByteBufferView

public void setUseByteBufferView(boolean useByteBufferView)

getSelectorTimeout

public static int getSelectorTimeout()

setSelectorTimeout

public static void setSelectorTimeout(int aSelectorTimeout)

getMaxQueueSizeInBytes

public int getMaxQueueSizeInBytes()

setMaxQueueSizeInBytes

public void setMaxQueueSizeInBytes(int maxQueueSizeInBytes)

getAlgorithmClassName

public String getAlgorithmClassName()

setAlgorithmClassName

public void setAlgorithmClassName(String algorithmClassName)

getSsBackLog

public int getSsBackLog()

setSsBackLog

public void setSsBackLog(int ssBackLog)

getDefaultResponseType

public String getDefaultResponseType()

setDefaultResponseType

public void setDefaultResponseType(String defaultResponseType)

getForcedRequestType

public String getForcedRequestType()

setForcedRequestType

public void setForcedRequestType(String forcedRequestType)

getActiveProcessorTasks

public ConcurrentLinkedQueue<ProcessorTask> getActiveProcessorTasks()

getClassLoader

public ClassLoader getClassLoader()

setClassLoader

public void setClassLoader(ClassLoader classLoader)
Set the ClassLoader used to load configurable classes (Pipeline, StreamAlgorithm).


isEnableNioLogging

public boolean isEnableNioLogging()

setEnableNioLogging

public void setEnableNioLogging(boolean enableNioLogging)

getMaxPostSize

public int getMaxPostSize()

setMaxPostSize

public void setMaxPostSize(int maxPostSize)

setReuseAddress

public void setReuseAddress(boolean reuseAddress)

getReuseAddress

public boolean getReuseAddress()

getSelectorThreadKeyHandler

public SelectorThreadKeyHandler getSelectorThreadKeyHandler()

setDisableUploadTimeout

public void setDisableUploadTimeout(boolean isDisabled)
Set the flag to control upload time-outs.


getDisableUploadTimeout

public boolean getDisableUploadTimeout()
Get the flag that controls upload time-outs.


setUploadTimeout

public void setUploadTimeout(int uploadTimeout)
Set the upload timeout.


getUploadTimeout

public int getUploadTimeout()
Get the upload timeout.


getProperty

public Object getProperty(String name)
Return a configured property.


setProperty

public void setProperty(String name,
                        Object value)
Set a configured property.


removeProperty

public void removeProperty(String name)
remove a configured property.



Copyright © 2011 SUN Microsystems. All Rights Reserved.