com.sun.grizzly.http
Class SelectorThread

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

public class SelectorThread
extends Object
implements Runnable, MBeanRegistration, GrizzlyListener

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

Field Summary
protected  Queue<ProcessorTask> activeProcessorTasks
          List of active ProcessorTask.
protected  Adapter adapter
          Associated adapter.
protected  Class algorithmClass
          TheStreamAlgorithm used to predict the end of the NIO stream
protected  String algorithmClassName
          TheStreamAlgorithm 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 static boolean enableNioLogging
          Grizzly own debug flag.
protected  FileCacheFactory fileCacheFactory
          The FileCacheFactory associated with this Selector
protected  String forcedRequestType
          The forced request-type
protected  boolean forceKeepAlive
           
protected  RequestGroupInfo globalRequestProcessor
          Monitoring object used to store information.
protected  ObjectName globalRequestProcessorName
           
protected  InetAddress inet
           
protected  boolean initialized
           
protected  boolean isAsyncHttpWriteEnabled
          Is Async HTTP write enabled.
protected  boolean isFileCacheEnabled
          Is the FileCache enabled.
protected  boolean isLargeFileCacheEnabled
          Is the large FileCache enabled.
protected  boolean isMonitoringEnabled
          Is monitoring already started.
protected  KeepAliveStats keepAliveStats
          Keep-alive stats
protected  int keepAliveThreadCount
           
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  long maxLargeFileCacheSize
          The maximum cached bytes
protected  int maxPostSize
           
protected  long maxSmallFileCacheSize
          The maximum cached bytes
protected  long minEntrySize
          The maximum size of a cached resources.
protected  MBeanServer mserver
           
protected  String noCompressionUserAgents
           
protected  ObjectName oname
           
protected  boolean oOBInline
           
protected  int port
           
protected  PUReadFilter portUnificationFilter
          Port unification filter
protected  ProcessorTaskFactory processorTaskFactory
           
protected  Queue<ProcessorTask> processorTasks
          Queue 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 read threads.
protected  int requestBufferSize
          The input request buffer size.
protected  String restrictedUserAgents
           
protected  String rootFolder
          The root folder where application are deployed
protected  AtomicBoolean 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 ConcurrentHashMap<Integer,SelectorThread> selectorThreads
          Static list of current instance of this class.
protected  int selectorTimeout
          The Selector timeout value.
static String SERVER_NAME
           
protected  int serverTimeout
           
protected static StringManager sm
          The string manager for this package.
protected  int socketTimeout
           
protected  int ssBackLog
          Server socket backlog.
protected  boolean tcpNoDelay
           
protected  ExecutorService threadPool
          The queue shared by this thread and the code>ProcessorTask.
protected  ThreadPoolStatistic threadPoolStat
          Placeholder for ExecutorService statistic.
protected  int transactionTimeout
          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.
 
Constructor Summary
SelectorThread()
          Create the Selector object.
 
Method Summary
 void addAsyncEnabledContextPath(String s)
          Add a context-path that will be allowed to execute using the AsyncHandler.
 void cancelKey(SelectionKey key)
          Cancel the current SelectionKey
protected  void clearTasks()
          Clear all cached Tasks
protected  void configureCompression(ProcessorTask processorTask)
           
protected  void configureFileCacheFactory()
           
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(ProcessorTask task)
           
protected  void configureProtocolChain()
          Configure SelectorThread ProtocolChain
protected  void configureSelectorHandler(TCPSelectorHandler selectorHandler)
          Configure TCPSelectorHandler
protected  FileCacheFactory createFileCacheFactory()
           
protected  ProtocolFilter createHttpParserFilter()
          Create HTTP parser ProtocolFilter
protected  KeepAliveStats createKeepAliveStats()
           
protected  ProtocolFilter createRaFilter()
          Create and configure resource allocation ProtocolFilter
protected  SelectorThreadKeyHandler createSelectionKeyHandler()
          Create SelectorThreadKeyHandler
protected  TCPSelectorHandler createSelectorHandler()
          Create TCPSelectorHandler
 void disableMonitoring()
          Disable gathering of monitoring data.
protected  void disableThreadPoolStats()
          Removes ThreadPoolStatistic from every ExecutorService, when monitoring has been turned off.
 void enableMonitoring()
          Enable gathering of monitoring data.
 void enableRcmSupport(boolean rcmSupport)
          Enable Application Resource Allocation Grizzly Extension.
protected  void enableThreadPoolStats()
          Injects ThreadPoolStatistic into every ExecutorService, for monitoring purposes.
 Queue<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 getCoreThreads()
           
 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()
           
 boolean getForceKeepAlive()
          Is keep-alive forced?
 InetAddress getInet()
           
 KeepAliveStats getKeepAliveStats()
           
 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()
          Return the Management interface, or null if JMX management is no enabled.
 int getMaxCacheEntries()
          Return the maximum entries this cache can contains.
 long getMaxEntrySize()
          Get the maximum size a FileCache.FileCacheEntry can have.
 int getMaxHttpHeaderSize()
           
 int getMaxKeepAliveRequests()
           
 long getMaxLargeCacheSize()
          Get the maximum cache size
 int getMaxPostSize()
           
 long getMaxSmallCacheSize()
          Get the maximum cache size
 int getMaxThreads()
           
 long getMinEntrySize()
          Get the maximum size a FileCache.FileCacheEntry can have.
 String getNoCompressionUserAgents()
           
 ObjectName getObjectName()
           
 int getPort()
           
 int getPortLowLevel()
          Deprecated. - uses getPort() instead
 ProcessorTask getProcessorTask()
          Return a ProcessorTask from the pool.
 ProcessorTaskFactory getProcessorTaskFactory()
          Get ProcessorTaskFactory.
 Object getProperty(String name)
          Return a configured property.
 ProtocolChain getProtocolChain()
          Return thr ProtocolChain used by this instance.
 RequestGroupInfo getRequestGroupInfo()
           
 String getRestrictedUserAgents()
           
 boolean getReuseAddress()
           
 Selector getSelector()
          Deprecated. To get the right Selector, please request context associated SelectorHandler: SelectorHandler.getSelector()
static SelectorThread getSelector(InetAddress address, int port)
           
static SelectorThread getSelector(int port)
          Deprecated. This method is not safe when a machine with multiple listeners are bound to different addresses using the same port. Use getSelector(java.net.InetAddress, int).
 TCPSelectorHandler getSelectorHandler()
          Deprecated. use SelectorHandler, which is usually provided by the current Context.
 int getSelectorReadThreadsCount()
           
static Enumeration<SelectorThread> getSelectors()
          Return an Enumeration of the active SelectorThreads
 SelectorThreadKeyHandler getSelectorThreadKeyHandler()
           
 int getSelectorTimeout()
           
 int getSendBufferSize()
           
 int getServerTimeout()
           
 int getSocketTimeout()
           
 int getSsBackLog()
           
 boolean getTcpNoDelay()
           
 ExecutorService getThreadPool()
           
 String getThreadPoolClassname()
           
 int getTransactionTimeout()
          Set the maximum time, in milliseconds, a WorkerThread executing an instance of this class can execute.
 int getUploadTimeout()
          Get the upload timeout.
 String getWebAppRootPath()
          Return the folder's root where application are deployed.
protected  void initAlgorithm()
          Load using reflection theStreamAlgorithm 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 initMonitoringLevel()
          Initialize the ThreadPoolStatistic instance.
protected  void initProcessorTask(int size)
          Create a pool of ProcessorTask
 void initThreadPool()
          Init the StatsThreadPools used by the WorkerThreads.
 boolean isAsyncHttpWriteEnabled()
          Is async HTTP write enabled
static 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 isUseChunking()
          Is chunking encoding used.
 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  ProcessorTask newProcessorTask(boolean initialize)
          Create ProcessorTask objects and configure it to be ready to proceed request.
protected  ExecutorService newThreadPool(int maxQueueSize, String name, int port, int priority)
          Create a new StatsThreadPool instance.
 void postDeregister()
           
 void postRegister(Boolean registrationDone)
           
 void preDeregister()
           
 ObjectName preRegister(MBeanServer server, ObjectName name)
           
 String protocol()
          Return the protocol supported by this GrizzlyListener
protected  void rampUpProcessorTask()
          Initialize ProcessorTask
protected  void reconfigureAdapter()
           
protected  void reconfigureAsyncExecution()
          Reconfigure Grizzly Asynchronous Request Processing(ARP) internal objects.
 void registerComponents()
          Register JMX components supported by this SelectorThread.
 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 setAsyncHttpWriteEnabled(boolean isAsyncHttpWriteEnabled)
          Set if async HTTP write 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 (ExecutorService, StreamAlgorithm).
 void setCompressableMimeTypes(String compressableMimeTypes)
           
 void setCompression(String compression)
           
 void setCompressionMinSize(int compressionMinSize)
           
 void setController(Controller controller)
           
 void setCoreThreads(int coreThreads)
           
 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
static void setEnableNioLogging(boolean enl)
           
 void setFileCacheIsEnabled(boolean isFileCacheEnabled)
          Is the file caching mechanism enabled.
 void setForcedRequestType(String forcedRequestType)
           
 void setForceKeepAlive(boolean forceKeepAlive)
          Force keep-alive no mather what the client support.
 void setInet(InetAddress inet)
           
 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)
          Set the Management interface.
 void setMaxCacheEntries(int mEntries)
          Set the maximum entries this cache can contains.
 void setMaxEntrySize(long mEntrySize)
          Set the maximum size a FileCache.FileCacheEntry can have.
 void setMaxHttpHeaderSize(int maxHttpHeaderSize)
           
 void setMaxKeepAliveRequests(int maxKeepAliveRequests)
          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 setMaxSmallCacheSize(long mCacheSize)
          Set the maximum cache size
 void setMaxThreads(int maxThreads)
           
 void setMinEntrySize(long mSize)
          Set the maximum size a FileCache.FileCacheEntry can have.
 void setNoCompressionUserAgents(String noCompressionUserAgents)
           
 void setPort(int port)
           
 void setProcessorTaskFactory(ProcessorTaskFactory processorTaskFactory)
          Sets ProcessorTaskFactory.
 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 FileCache.FileCacheEntry from the FileCache
 void setSelectorReadThreadsCount(int readThreadsCount)
           
 void setSelectorTimeout(int aSelectorTimeout)
           
 void setSendBufferSize(int sendBufferSize)
           
 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 setThreadPool(ExecutorService threadPool)
          Set the ExecutorService this class should use.
 void setThreadPoolClassname(String threadPoolClassname)
           
 void setTransactionTimeout(int transactionTimeout)
          Set the maximum time, in milliseconds, a WorkerThread processing an instance of this class.
 void setUploadTimeout(int uploadTimeout)
          Set the upload timeout.
 void setUseByteBufferView(boolean useByteBufferView)
           
 void setUseChunking(boolean useChunking)
          Enable chunking the http response.
 void setUseDirectByteBuffer(boolean useDirectByteBuffer)
           
 void setWebAppRootPath(String rf)
          Set the document root folder
 void start()
          Start using the Controller's internal Thread Pool.
 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 startThreadPool()
          Starts the ExecutorService used by this Selector
 void stopEndpoint()
           
protected  void stopThreadPool()
          Stop the ExecutorService used by this Selector
protected  void unregisterComponents()
          Unregister JMX components supported by this SelectorThread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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 final AtomicBoolean 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

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.


isAsyncHttpWriteEnabled

protected boolean isAsyncHttpWriteEnabled
Is Async HTTP write enabled.


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.


threadPool

protected ExecutorService threadPool
The queue shared by this thread and the code>ProcessorTask.


threadPoolStat

protected ThreadPoolStatistic threadPoolStat
Placeholder for ExecutorService statistic.


transactionTimeout

protected int transactionTimeout
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.


keepAliveStats

protected KeepAliveStats keepAliveStats
Keep-alive stats


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


selectorTimeout

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


algorithmClass

protected Class algorithmClass
TheStreamAlgorithm used to predict the end of the NIO stream


algorithmClassName

protected String algorithmClassName
TheStreamAlgorithm 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 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 final Queue<ProcessorTask> processorTasks
Queue used as an object pool. If the list becomes empty, new ProcessorTask will be automatically added to the list.


activeProcessorTasks

protected final Queue<ProcessorTask> activeProcessorTasks
List of active ProcessorTask.


readThreadsCount

protected int readThreadsCount
The number of read threads.


logger

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


sm

protected static final StringManager sm
The string manager for this package.


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.


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 static boolean enableNioLogging
Grizzly own debug flag.


selectorThreads

protected static final ConcurrentHashMap<Integer,SelectorThread> selectorThreads
Static list of current instance of this class.


forceKeepAlive

protected boolean forceKeepAlive

processorTaskFactory

protected volatile ProcessorTaskFactory processorTaskFactory
Constructor Detail

SelectorThread

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

Method Detail

getSelector

@Deprecated
public static SelectorThread getSelector(int port)
Deprecated. This method is not safe when a machine with multiple listeners are bound to different addresses using the same port. Use getSelector(java.net.InetAddress, int).

Return the SelectorThread which listen on port, or null if there is no SelectorThread.


getSelector

public static SelectorThread getSelector(InetAddress address,
                                         int port)

getSelectors

public static 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


createSelectionKeyHandler

protected SelectorThreadKeyHandler createSelectionKeyHandler()
Create SelectorThreadKeyHandler


configureProtocolChain

protected void configureProtocolChain()
Configure SelectorThread ProtocolChain


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:
{@link - 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

getProtocolChain

public ProtocolChain getProtocolChain()
Return thr ProtocolChain used by this instance.

Returns:
ProtocolChain

newThreadPool

protected ExecutorService newThreadPool(int maxQueueSize,
                                        String name,
                                        int port,
                                        int priority)
Create a new StatsThreadPool instance.


initFileCacheFactory

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


createFileCacheFactory

protected FileCacheFactory createFileCacheFactory()

configureFileCacheFactory

protected void configureFileCacheFactory()

enableThreadPoolStats

protected void enableThreadPoolStats()
Injects ThreadPoolStatistic into every ExecutorService, for monitoring purposes.


disableThreadPoolStats

protected void disableThreadPoolStats()
Removes ThreadPoolStatistic from every ExecutorService, when monitoring has been turned off.


initAlgorithm

protected void initAlgorithm()
Load using reflection theStreamAlgorithm class.


initThreadPool

public void initThreadPool()
Init the StatsThreadPools 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(ProcessorTask task)

reconfigureAsyncExecution

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


reconfigureAdapter

protected void reconfigureAdapter()

getProcessorTask

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


start

public void start()
Start using the Controller's internal Thread Pool.


run

public void run()
Start the endpoint (this)

Specified by:
run in interface Runnable

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.

Specified by:
listen in interface GrizzlyListener
Throws:
IOException
InstantiationException

startThreadPool

protected void startThreadPool()
Starts the ExecutorService used by this Selector


stopThreadPool

protected void stopThreadPool()
Stop the ExecutorService 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


getPortLowLevel

public int getPortLowLevel()
Deprecated. - uses getPort() instead

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

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)

getMaxKeepAliveRequests

public int getMaxKeepAliveRequests()

setMaxKeepAliveRequests

public void setMaxKeepAliveRequests(int maxKeepAliveRequests)
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

setAdapter

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

Specified by:
setAdapter in interface GrizzlyListener
Parameters:
adapter - the new adapter

getAdapter

public Adapter getAdapter()
Get the associated adapter.

Specified by:
getAdapter in interface GrizzlyListener
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

public void registerComponents()
Register JMX components supported by this SelectorThread. This include FileCache, RequestInfo, KeepAliveStats and StatsThreadPool. The Management.registerComponent(java.lang.Object, javax.management.ObjectName, java.lang.String) will be invoked during the registration process.


unregisterComponents

protected void unregisterComponents()
Unregister JMX components supported by this SelectorThread. This include FileCache, RequestInfo, KeepAliveStats , StatsThreadPool and ProcessorTask. The Management.unregisterComponent(javax.management.ObjectName) will be invoked during the registration process.


getManagement

public Management getManagement()
Return the Management interface, or null if JMX management is no enabled.

Returns:
the Management

setManagement

public void setManagement(Management jmxManagement)
Set the Management interface. Setting this interface automatically expose Grizzly HTTP Engine mbeans.

Parameters:
jmxManagement -

enableMonitoring

public void enableMonitoring()
Enable gathering of monitoring data.


disableMonitoring

public void disableMonitoring()
Disable gathering of monitoring data.


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()
Initialize the ThreadPoolStatistic instance.


getMaxHttpHeaderSize

public int getMaxHttpHeaderSize()

setMaxHttpHeaderSize

public void setMaxHttpHeaderSize(int maxHttpHeaderSize)

isAsyncHttpWriteEnabled

public boolean isAsyncHttpWriteEnabled()
Is async HTTP write enabled

Returns:
true, if async HTTP write enabled, or false otherwise.

setAsyncHttpWriteEnabled

public void setAsyncHttpWriteEnabled(boolean isAsyncHttpWriteEnabled)
Set if async HTTP write enabled

Parameters:
isAsyncHttpWriteEnabled - true, if async HTTP write enabled, or false otherwise.

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()
Deprecated. To get the right Selector, please request context associated SelectorHandler: SelectorHandler.getSelector()

Get main Selector


getSelectorHandler

public TCPSelectorHandler getSelectorHandler()
Deprecated. use SelectorHandler, which is usually provided by the current Context.

Get main SelectorHandler


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 FileCache.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 FileCache.FileCacheEntry can have.


getMinEntrySize

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


setMaxEntrySize

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


getMaxEntrySize

public long getMaxEntrySize()
Get the maximum size a FileCache.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 void setWebAppRootPath(String rf)
Set the document root folder


getWebAppRootPath

public 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

configureCompression

protected void configureCompression(ProcessorTask 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)

getThreadPool

public ExecutorService getThreadPool()

setThreadPool

public void setThreadPool(ExecutorService threadPool)
Set the ExecutorService this class should use. A ExecutorService must ensure its ThreadFactory return Thread which are instance of HttpWorkerThread.

Parameters:
threadPool - - the thread pool used by this instance.

isUseDirectByteBuffer

public boolean isUseDirectByteBuffer()

setUseDirectByteBuffer

public void setUseDirectByteBuffer(boolean useDirectByteBuffer)

setDisplayConfiguration

public void setDisplayConfiguration(boolean displayConfiguration)

isUseByteBufferView

public boolean isUseByteBufferView()

setUseByteBufferView

public void setUseByteBufferView(boolean useByteBufferView)

getSelectorTimeout

public int getSelectorTimeout()

setSelectorTimeout

public void setSelectorTimeout(int aSelectorTimeout)

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 Queue<ProcessorTask> getActiveProcessorTasks()

getClassLoader

public ClassLoader getClassLoader()

setClassLoader

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


isEnableNioLogging

public static boolean isEnableNioLogging()

setEnableNioLogging

public static void setEnableNioLogging(boolean enl)

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.


getTransactionTimeout

public int getTransactionTimeout()
Set the maximum time, in milliseconds, a WorkerThread executing an instance of this class can execute.

Returns:
the maximum time, in milliseconds

setTransactionTimeout

public void setTransactionTimeout(int transactionTimeout)
Set the maximum time, in milliseconds, a WorkerThread processing an instance of this class.

Parameters:
transactionTimeout - the maximum time, in milliseconds.

isUseChunking

public boolean isUseChunking()
Is chunking encoding used. Default is true;

Returns:
Is chunking encoding used.

setUseChunking

public void setUseChunking(boolean useChunking)
Enable chunking the http response. Default is true.

Parameters:
useChunking -

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.


getMaxThreads

public int getMaxThreads()

setMaxThreads

public void setMaxThreads(int maxThreads)

getCoreThreads

public int getCoreThreads()

setCoreThreads

public void setCoreThreads(int coreThreads)

getThreadPoolClassname

public String getThreadPoolClassname()

setThreadPoolClassname

public void setThreadPoolClassname(String threadPoolClassname)

protocol

public String protocol()
Return the protocol supported by this GrizzlyListener

Specified by:
protocol in interface GrizzlyListener

setForceKeepAlive

public void setForceKeepAlive(boolean forceKeepAlive)
Force keep-alive no mather what the client support.


getForceKeepAlive

public boolean getForceKeepAlive()
Is keep-alive forced?


addAsyncEnabledContextPath

public void addAsyncEnabledContextPath(String s)
Add a context-path that will be allowed to execute using the AsyncHandler.

Parameters:
s - A context-path that will be allowed to execute using the

createKeepAliveStats

protected KeepAliveStats createKeepAliveStats()

getSendBufferSize

public int getSendBufferSize()
Returns:
the sendBufferSize

setSendBufferSize

public void setSendBufferSize(int sendBufferSize)
Parameters:
sendBufferSize - the sendBufferSize to set

getProcessorTaskFactory

public ProcessorTaskFactory getProcessorTaskFactory()
Get ProcessorTaskFactory.

Returns:
ProcessorTaskFactory

setProcessorTaskFactory

public void setProcessorTaskFactory(ProcessorTaskFactory processorTaskFactory)
Sets ProcessorTaskFactory.

Parameters:
processorTaskFactory -


Copyright © 2012 Oracle Corporation. All Rights Reserved.