org.glassfish.grizzly.web
Class WebFilter<T extends WebFilterConfig>

java.lang.Object
  extended by org.glassfish.grizzly.filterchain.FilterAdapter
      extended by org.glassfish.grizzly.web.WebFilter<T>
All Implemented Interfaces:
MBeanRegistration, Filter
Direct Known Subclasses:
AsyncWebFilter

public class WebFilter<T extends WebFilterConfig>
extends FilterAdapter
implements MBeanRegistration

The WebFilter is the extry point when writing Web application build on Grizzly. You can create a WebFilter by simply doing:



      Transport transport = TransportFactory.getInstance().createTCPTransport();

        WebFilterConfig webConfig = new WebFilterConfig();
        webConfig.setAdapter(adapter);
        webConfig.setDisplayConfiguration(true);

        WebFilter webFilter = new WebFilter("MyHtttpServer", webConfig);
        webFilter.enableMonitoring();

        transport.getFilterChain().add(new TransportFilter());
        transport.getFilterChain().add(webFilter);
        try {
            webFilter.initialize();
            transport.bind(PORT);
            transport.start();
        } catch (Exception ex) {
          ...
      }


 


Field Summary
protected  LinkedTransferQueue<ProcessorTask> activeProcessorTasks
          List of active ProcessorTask.
protected  T config
           
protected  RequestGroupInfo globalRequestProcessor
          Monitoring object used to store information.
protected  ObjectName globalRequestProcessorName
           
protected  WebFilterJMXManager jmxManager
           
protected static Logger logger
          The logger used by the grizzly classes.
protected  String name
           
protected  LinkedTransferQueue<ProcessorTask> processorTasks
          ConcurrentLinkedQueue used as an object pool.
protected  ObjectName processorWorkerThreadName
           
protected static StringManager sm
          The string manager for this package.
protected  ThreadPoolStatistic threadPoolStat
          Placeholder for ExecutorService statistic.
 
Constructor Summary
WebFilter()
          Create the WebFilter.
WebFilter(String name)
          Create the WebFilter with the specific name.
WebFilter(String name, T config)
          Create the WebFilter with the specific name.
 
Method Summary
protected  void configureProcessorTask(ProcessorTask processorTask, FilterChainContext context)
          Configure ProcessorTask.
 void disableMonitoring()
          Disable gathering of monitoring data.
protected  void disableThreadPoolStats()
          Removes ThreadPoolStatistic from every ExecutorService, when monitoring has been turned off.
protected  void displayConfiguration()
          Display the Grizzly configuration parameters.
 void enableMonitoring()
          Enable gathering of monitoring data.
protected  void enableThreadPoolStats()
          Injects ThreadPoolStatistic into every ExecutorService, for monitoring purposes.
 LinkedTransferQueue<ProcessorTask> getActiveProcessorTasks()
           
 T getConfig()
           
 WebFilterJMXManager getJmxManager()
           
 KeepAliveStats getKeepAliveStats()
           
 String getName()
           
 ProcessorTask getProcessorTask(FilterChainContext ctx)
          Return a ProcessorTask from the pool.
 RequestGroupInfo getRequestGroupInfo()
           
 ThreadPoolStatistic getThreadPoolStatistic()
           
 NextAction handleAccept(FilterChainContext ctx, NextAction nextAction)
           
 NextAction handleClose(FilterChainContext ctx, NextAction nextAction)
           
 NextAction handleRead(FilterChainContext ctx, NextAction nextAction)
           
 void initialize()
          initialized the endpoint by creating the ServerScoketChannel and by initializing the server socket.
protected  ProcessorTask initializeProcessorTask(ProcessorTask task)
           
protected  void initMonitoringLevel()
          Initialize the ThreadPoolStat instance.
protected  void initProcessorTasks(int size)
          Create a pool of ProcessorTask
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.
 void postDeregister()
           
 void postRegister(Boolean registrationDone)
           
 void preDeregister()
           
 ObjectName preRegister(MBeanServer server, ObjectName name)
           
protected  void rampUpProcessorTasks()
          Initialize ProcessorTask
 void registerComponents()
          Register JMX components supported by this WebFilter.
 void release()
           
 void returnTask(Task task)
          Returns the Task object to the pool.
 void setConfig(T config)
           
 void setJmxManager(WebFilterJMXManager jmxManager)
           
static void setLogger(Logger l)
          Set the logger used by this instance.
 void setName(String name)
           
 void setRequestProcessor(RequestGroupInfo requestProcessor)
           
protected  void unregisterComponents()
          Unregister JMX components supported by this WebFilter.
 
Methods inherited from class org.glassfish.grizzly.filterchain.FilterAdapter
exceptionOccurred, getFilterChain, getIndex, handleConnect, handleWrite, isIndexable, postAccept, postClose, postConnect, postRead, postWrite, setIndex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

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


sm

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


name

protected String name

config

protected T extends WebFilterConfig config

jmxManager

protected WebFilterJMXManager jmxManager

threadPoolStat

protected ThreadPoolStatistic threadPoolStat
Placeholder for ExecutorService statistic.


processorTasks

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


activeProcessorTasks

protected LinkedTransferQueue<ProcessorTask> activeProcessorTasks
List of active ProcessorTask.


globalRequestProcessor

protected RequestGroupInfo globalRequestProcessor
Monitoring object used to store information.


globalRequestProcessorName

protected ObjectName globalRequestProcessorName

processorWorkerThreadName

protected ObjectName processorWorkerThreadName
Constructor Detail

WebFilter

public WebFilter()
Create the WebFilter.


WebFilter

public WebFilter(String name)
Create the WebFilter with the specific name.


WebFilter

public WebFilter(String name,
                 T config)
Create the WebFilter with the specific name.

Method Detail

handleRead

public NextAction handleRead(FilterChainContext ctx,
                             NextAction nextAction)
                      throws IOException
Specified by:
handleRead in interface Filter
Overrides:
handleRead in class FilterAdapter
Throws:
IOException

handleAccept

public NextAction handleAccept(FilterChainContext ctx,
                               NextAction nextAction)
                        throws IOException
Specified by:
handleAccept in interface Filter
Overrides:
handleAccept in class FilterAdapter
Throws:
IOException

handleClose

public NextAction handleClose(FilterChainContext ctx,
                              NextAction nextAction)
                       throws IOException
Specified by:
handleClose in interface Filter
Overrides:
handleClose in class FilterAdapter
Throws:
IOException

configureProcessorTask

protected void configureProcessorTask(ProcessorTask processorTask,
                                      FilterChainContext context)
Configure ProcessorTask.


getName

public String getName()

setName

public void setName(String name)

getConfig

public T getConfig()

setConfig

public void setConfig(T config)

getJmxManager

public WebFilterJMXManager getJmxManager()

setJmxManager

public void setJmxManager(WebFilterJMXManager jmxManager)

getThreadPoolStatistic

public ThreadPoolStatistic getThreadPoolStatistic()

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.


initProcessorTasks

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


rampUpProcessorTasks

protected void rampUpProcessorTasks()
Initialize ProcessorTask


newProcessorTask

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


initializeProcessorTask

protected ProcessorTask initializeProcessorTask(ProcessorTask task)

getProcessorTask

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


initialize

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

Throws:
IOException

release

public void release()

returnTask

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


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

enableMonitoring

public void enableMonitoring()
Enable gathering of monitoring data.


disableMonitoring

public void disableMonitoring()
Disable gathering of monitoring data.


getKeepAliveStats

public KeepAliveStats getKeepAliveStats()

registerComponents

public void registerComponents()
Register JMX components supported by this WebFilter. This include FileCache, RequestInfo, KeepAliveCountManager 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 WebFilter. This include FileCache, RequestInfo, KeepAliveCountManager , StatsThreadPool and ProcessorTask. The Management.unregisterComponent(javax.management.ObjectName) will be invoked during the registration process.


getRequestGroupInfo

public RequestGroupInfo getRequestGroupInfo()

setRequestProcessor

public void setRequestProcessor(RequestGroupInfo requestProcessor)

initMonitoringLevel

protected void initMonitoringLevel()
Initialize the ThreadPoolStat instance.


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.


displayConfiguration

protected void displayConfiguration()
Display the Grizzly configuration parameters.


getActiveProcessorTasks

public LinkedTransferQueue<ProcessorTask> getActiveProcessorTasks()


Copyright © 2009 SUN Microsystems. All Rights Reserved.