Class AtmosphereFramework


  • public class AtmosphereFramework
    extends java.lang.Object
    The AtmosphereFramework is the entry point for the framework. This class can be used to from Servlet/filter to dispatch AtmosphereRequest and AtmosphereResponse. The framework can also be configured using the setXXX method. The life cycle of this class is
     AtmosphereFramework f = new AtmosphereFramework();
     f.init();
     f.doCometSupport(AtmosphereRequest, AtmosphereResource);
     f.destroy();
     
    Author:
    Jeanfrancois Arcand
    • Field Detail

      • DEFAULT_ATMOSPHERE_CONFIG_PATH

        public static final java.lang.String DEFAULT_ATMOSPHERE_CONFIG_PATH
        See Also:
        Constant Field Values
      • DEFAULT_LIB_PATH

        public static final java.lang.String DEFAULT_LIB_PATH
        See Also:
        Constant Field Values
      • DEFAULT_HANDLER_PATH

        public static final java.lang.String DEFAULT_HANDLER_PATH
        See Also:
        Constant Field Values
      • logger

        protected static final org.slf4j.Logger logger
      • broadcasterFilters

        protected final java.util.List<java.lang.String> broadcasterFilters
      • possibleComponentsCandidate

        protected final java.util.ArrayList<java.lang.String> possibleComponentsCandidate
      • initParams

        protected final java.util.HashMap<java.lang.String,​java.lang.String> initParams
      • isCometSupportConfigured

        protected final java.util.concurrent.atomic.AtomicBoolean isCometSupportConfigured
      • isFilter

        protected final boolean isFilter
      • broadcasterTypes

        protected final java.util.concurrent.ConcurrentLinkedQueue<java.lang.String> broadcasterTypes
      • objectFactoryType

        protected final java.util.concurrent.ConcurrentLinkedQueue<java.lang.String> objectFactoryType
      • mappingRegex

        protected java.lang.String mappingRegex
      • useNativeImplementation

        protected boolean useNativeImplementation
      • useBlockingImplementation

        protected boolean useBlockingImplementation
      • useStreamForFlushingComments

        protected boolean useStreamForFlushingComments
      • useServlet30

        protected boolean useServlet30
      • broadcasterClassName

        protected java.lang.String broadcasterClassName
      • isCometSupportSpecified

        protected boolean isCometSupportSpecified
      • isBroadcasterSpecified

        protected boolean isBroadcasterSpecified
      • isSessionSupportSpecified

        protected boolean isSessionSupportSpecified
      • isThrowExceptionOnClonedRequestSpecified

        protected boolean isThrowExceptionOnClonedRequestSpecified
      • broadcasterFactoryClassName

        protected java.lang.String broadcasterFactoryClassName
      • broadcasterCacheClassName

        protected java.lang.String broadcasterCacheClassName
      • webSocketEnabled

        protected boolean webSocketEnabled
      • broadcasterLifeCyclePolicy

        protected java.lang.String broadcasterLifeCyclePolicy
      • webSocketProtocolClassName

        protected java.lang.String webSocketProtocolClassName
      • handlersPath

        protected java.lang.String handlersPath
      • servletConfig

        protected javax.servlet.ServletConfig servletConfig
      • autoDetectHandlers

        protected boolean autoDetectHandlers
      • atmosphereDotXmlPath

        protected java.lang.String atmosphereDotXmlPath
      • metaServicePath

        protected java.lang.String metaServicePath
      • scanDone

        protected boolean scanDone
      • annotationProcessorClassName

        protected java.lang.String annotationProcessorClassName
      • broadcasterListeners

        protected final java.util.List<BroadcasterListener> broadcasterListeners
      • webSocketProcessorClassName

        protected java.lang.String webSocketProcessorClassName
      • webSocketProtocolInitialized

        protected boolean webSocketProtocolInitialized
      • libPath

        protected java.lang.String libPath
      • isInit

        protected boolean isInit
      • sharedThreadPools

        protected boolean sharedThreadPools
      • packages

        protected final java.util.List<java.lang.String> packages
      • annotationPackages

        protected final java.util.LinkedList<java.lang.String> annotationPackages
      • allowAllClassesScan

        protected boolean allowAllClassesScan
      • annotationFound

        protected boolean annotationFound
      • executeFirstSet

        protected boolean executeFirstSet
      • isDestroyed

        protected final java.util.concurrent.atomic.AtomicBoolean isDestroyed
      • externalizeDestroy

        protected boolean externalizeDestroy
      • excludedInterceptors

        protected final java.util.List<java.lang.String> excludedInterceptors
      • defaultSerializerClassName

        protected java.lang.String defaultSerializerClassName
      • defaultSerializerClass

        protected java.lang.Class<Serializer> defaultSerializerClass
      • shutdownHook

        protected java.lang.Thread shutdownHook
      • DEFAULT_ATMOSPHERE_INTERCEPTORS

        public static final java.util.List<java.lang.Class<? extends AtmosphereInterceptor>> DEFAULT_ATMOSPHERE_INTERCEPTORS
    • Constructor Detail

      • AtmosphereFramework

        public AtmosphereFramework()
        Create an AtmosphereFramework.
      • AtmosphereFramework

        public AtmosphereFramework​(javax.servlet.ServletConfig sc)
                            throws javax.servlet.ServletException
        Create an AtmosphereFramework and initialize it via init(javax.servlet.ServletConfig).
        Throws:
        javax.servlet.ServletException
      • AtmosphereFramework

        public AtmosphereFramework​(boolean isFilter,
                                   boolean autoDetectHandlers)
        Create an AtmosphereFramework.
        Parameters:
        isFilter - true if this instance is used as an AtmosphereFilter
    • Method Detail

      • setAndConfigureAtmosphereResourceFactory

        public void setAndConfigureAtmosphereResourceFactory​(AtmosphereResourceFactory arFactory)
      • normalizePath

        public java.lang.String normalizePath​(java.lang.String path)
      • removeAllInitParams

        public AtmosphereFramework removeAllInitParams()
        Remove all init parameters.
      • addInitParameter

        public AtmosphereFramework addInitParameter​(java.lang.String name,
                                                    java.lang.String value)
        Add init-param like if they were defined in web.xml
        Parameters:
        name - The name
        value - The value
      • readSystemProperties

        protected void readSystemProperties()
      • patchContainer

        public void patchContainer()
        Path specific container using their own property.
      • init

        public AtmosphereFramework init()
        Initialize the AtmosphereFramework. Invoke this method after having properly configured this class using the setters.
      • init

        public AtmosphereFramework init​(javax.servlet.ServletConfig sc)
                                 throws javax.servlet.ServletException
        Initialize the AtmosphereFramework using the ServletContext.
        Parameters:
        sc - the ServletContext
        Throws:
        javax.servlet.ServletException
      • preventOOM

        protected void preventOOM()
        Prevent Atmosphere from scanning the entire class path.
      • init

        public AtmosphereFramework init​(javax.servlet.ServletConfig sc,
                                        boolean wrap)
                                 throws javax.servlet.ServletException
        Initialize the AtmosphereFramework using the ServletContext.
        Parameters:
        sc - the ServletContext
        Throws:
        javax.servlet.ServletException
      • servletConfig

        protected void servletConfig​(javax.servlet.ServletConfig sc,
                                     boolean wrap)
      • reconfigureInitParams

        public void reconfigureInitParams​(boolean reconfigureInitParams)
      • universe

        protected void universe()
      • analytics

        protected void analytics()
      • configureAtmosphereInterceptor

        protected void configureAtmosphereInterceptor​(javax.servlet.ServletConfig sc)
        Configure the list of AtmosphereInterceptor.
        Parameters:
        sc - a ServletConfig
      • configureWebDotXmlAtmosphereHandler

        protected void configureWebDotXmlAtmosphereHandler​(javax.servlet.ServletConfig sc)
      • configureScanningPackage

        protected void configureScanningPackage​(javax.servlet.ServletConfig sc,
                                                java.lang.String value)
      • defaultPackagesToScan

        protected void defaultPackagesToScan()
      • configureBroadcasterFactory

        public void configureBroadcasterFactory()
      • configureBroadcaster

        protected void configureBroadcaster()
      • installAnnotationProcessor

        protected void installAnnotationProcessor​(javax.servlet.ServletConfig sc)
      • doInitParamsForWebSocket

        protected void doInitParamsForWebSocket​(javax.servlet.ServletConfig sc)
      • doInitParams

        protected void doInitParams​(javax.servlet.ServletConfig sc)
        Read init params from web.xml and apply them.
        Parameters:
        sc - ServletConfig
      • doInitParams

        protected void doInitParams​(javax.servlet.ServletConfig sc,
                                    boolean reconfigure)
        Read init params from web.xml and apply them.
        Parameters:
        sc - ServletConfig
      • loadConfiguration

        public void loadConfiguration​(javax.servlet.ServletConfig sc)
                               throws javax.servlet.ServletException
        Throws:
        javax.servlet.ServletException
      • detectSupportedFramework

        protected boolean detectSupportedFramework​(javax.servlet.ServletConfig sc)
                                            throws java.lang.Exception
        Auto-detect Jersey when no atmosphere.xml file is specified.
        Parameters:
        sc - ServletConfig
        Returns:
        true if Jersey classes are detected
        Throws:
        java.lang.ClassNotFoundException
        java.lang.Exception
      • configureDetectedFramework

        protected void configureDetectedFramework​(ReflectorServletProcessor rsp,
                                                  boolean isJersey)
      • lookupDefaultBroadcasterType

        protected java.lang.String lookupDefaultBroadcasterType​(java.lang.String defaultB)
      • sessionSupport

        public void sessionSupport​(boolean sessionSupport)
      • initAtmosphereHandler

        public void initAtmosphereHandler​(javax.servlet.ServletConfig sc)
                                   throws javax.servlet.ServletException
        Parameters:
        sc - the ServletConfig
        Throws:
        javax.servlet.ServletException
      • initAtmosphereHandler

        public void initAtmosphereHandler()
                                   throws javax.servlet.ServletException
        Throws:
        javax.servlet.ServletException
      • checkWebSocketSupportState

        public void checkWebSocketSupportState()
      • initWebSocket

        public void initWebSocket()
      • initEndpointMapper

        public void initEndpointMapper()
      • closeAtmosphereResource

        protected void closeAtmosphereResource()
      • destroyInterceptors

        protected void destroyInterceptors()
      • loadMetaService

        protected void loadMetaService()
      • loadAtmosphereDotXml

        protected void loadAtmosphereDotXml​(java.io.InputStream stream,
                                            java.lang.ClassLoader c)
                                     throws java.io.IOException,
                                            javax.servlet.ServletException
        Load AtmosphereHandler defined under META-INF/atmosphere.xml.
        Parameters:
        stream - The input stream we read from.
        c - The classloader
        Throws:
        java.io.IOException
        javax.servlet.ServletException
      • autoDetectContainer

        protected void autoDetectContainer()
        Auto detect the underlying Servlet Container we are running on.
      • autoDetectAtmosphereHandlers

        public void autoDetectAtmosphereHandlers​(javax.servlet.ServletContext servletContext,
                                                 java.lang.ClassLoader classloader)
                                          throws java.net.MalformedURLException
        Auto detect instance of AtmosphereHandler in case META-INF/atmosphere.xml is missing.
        Parameters:
        servletContext - ServletContext
        classloader - ClassLoader to load the class.
        Throws:
        java.net.MalformedURLException
      • loadAtmosphereHandlersFromPath

        public void loadAtmosphereHandlersFromPath​(java.lang.ClassLoader classloader,
                                                   java.lang.String realPath)
      • autoDetectWebSocketHandler

        protected void autoDetectWebSocketHandler​(javax.servlet.ServletContext servletContext,
                                                  java.lang.ClassLoader classloader)
                                           throws java.net.MalformedURLException
        Auto detect instance of WebSocketHandler in case META-INF/atmosphere.xml is missing.
        Parameters:
        servletContext - ServletContext
        classloader - ClassLoader to load the class.
        Throws:
        java.net.MalformedURLException
      • loadWebSocketFromPath

        protected void loadWebSocketFromPath​(java.lang.ClassLoader classloader,
                                             java.lang.String realPath)
      • doCometSupport

        public Action doCometSupport​(AtmosphereRequest req,
                                     AtmosphereResponse res)
                              throws java.io.IOException,
                                     javax.servlet.ServletException
        Invoke the proprietary AsyncSupport.
        Parameters:
        req -
        res -
        Returns:
        an Action
        Throws:
        java.io.IOException
        javax.servlet.ServletException
      • getDefaultBroadcasterClassName

        public java.lang.String getDefaultBroadcasterClassName()
        Return the default Broadcaster class name.
        Returns:
        the broadcasterClassName
      • setDefaultBroadcasterClassName

        public AtmosphereFramework setDefaultBroadcasterClassName​(java.lang.String bccn)
        Set the default Broadcaster class name.
        Parameters:
        bccn - the broadcasterClassName to set
      • isUseStreamForFlushingComments

        public boolean isUseStreamForFlushingComments()
        true if Atmosphere uses AtmosphereResponseImpl.getOutputStream() by default for write operation.
        Returns:
        the useStreamForFlushingComments
      • isUseServlet30

        public boolean isUseServlet30()
      • setUseStreamForFlushingComments

        public AtmosphereFramework setUseStreamForFlushingComments​(boolean useStreamForFlushingComments)
        Set to true so Atmosphere uses AtmosphereResponseImpl.getOutputStream() by default for write operation. Default is false.
        Parameters:
        useStreamForFlushingComments - the useStreamForFlushingComments to set
      • getBroadcasterCacheClassName

        public java.lang.String getBroadcasterCacheClassName()
        Return the BroadcasterCache class name.
        Returns:
        the BroadcasterCache class name
      • setBroadcasterCacheClassName

        public AtmosphereFramework setBroadcasterCacheClassName​(java.lang.String broadcasterCacheClassName)
        Set the BroadcasterCache class name.
        Parameters:
        broadcasterCacheClassName -
      • addBroadcasterType

        public AtmosphereFramework addBroadcasterType​(java.lang.String broadcasterTypeString)
        Add a new Broadcaster class name that AtmosphereServlet can use when initializing requests, and when the atmosphere.xml broadcaster element is unspecified.
        Parameters:
        broadcasterTypeString -
      • broadcasterTypes

        public java.util.concurrent.ConcurrentLinkedQueue<java.lang.String> broadcasterTypes()
      • getWebSocketProtocolClassName

        public java.lang.String getWebSocketProtocolClassName()
      • setWebSocketProtocolClassName

        public AtmosphereFramework setWebSocketProtocolClassName​(java.lang.String webSocketProtocolClassName)
      • configureQueryStringAsRequest

        protected java.util.Map<java.lang.String,​java.lang.String> configureQueryStringAsRequest​(AtmosphereRequest request)
      • isUseNativeImplementation

        public boolean isUseNativeImplementation()
      • setUseNativeImplementation

        public AtmosphereFramework setUseNativeImplementation​(boolean useNativeImplementation)
      • isUseBlockingImplementation

        public boolean isUseBlockingImplementation()
      • setUseBlockingImplementation

        public AtmosphereFramework setUseBlockingImplementation​(boolean useBlockingImplementation)
      • getAtmosphereDotXmlPath

        public java.lang.String getAtmosphereDotXmlPath()
      • setAtmosphereDotXmlPath

        public AtmosphereFramework setAtmosphereDotXmlPath​(java.lang.String atmosphereDotXmlPath)
      • getHandlersPath

        public java.lang.String getHandlersPath()
      • setHandlersPath

        public AtmosphereFramework setHandlersPath​(java.lang.String handlersPath)
      • getLibPath

        public java.lang.String getLibPath()
        Return the location of the JARs containing the application classes. Default is WEB-INF/lib.
        Returns:
        the location of the JARs containing the application classes. Default is WEB-INF/lib
      • setLibPath

        public AtmosphereFramework setLibPath​(java.lang.String libPath)
        Set the location of the JARs containing the application.
        Parameters:
        libPath - the location of the JARs containing the application.
        Returns:
        this
      • getWebSocketProcessorClassName

        public java.lang.String getWebSocketProcessorClassName()
        The current WebSocketProcessor used to handle websocket requests.
        Returns:
        WebSocketProcessor
      • addDefaultOrAppInterceptors

        protected void addDefaultOrAppInterceptors()
      • getServletContext

        public javax.servlet.ServletContext getServletContext()
        Return the ServletContext
        Returns:
        the ServletContext
      • getServletConfig

        public javax.servlet.ServletConfig getServletConfig()
      • broadcasterFilters

        public java.util.List<java.lang.String> broadcasterFilters()
        Return the list of BroadcastFilters.
        Returns:
        the list of BroadcastFilters
      • isShareExecutorServices

        public boolean isShareExecutorServices()
        Returns true if ExecutorService is shared among all components.
        Returns:
        true if ExecutorService is shared amongst all components
      • shareExecutorServices

        public AtmosphereFramework shareExecutorServices​(boolean sharedThreadPools)
        Set to true to have a ExecutorService shared among all components.
        Parameters:
        sharedThreadPools -
        Returns:
        this
      • autoConfigureService

        protected void autoConfigureService​(javax.servlet.ServletContext sc)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • addAnnotationPackage

        public AtmosphereFramework addAnnotationPackage​(java.lang.Class<?> clazz)
        Add support for package detection of Atmosphere's Component.
        Parameters:
        clazz - a Class
        Returns:
        this.
      • initialized

        public boolean initialized()
        Return true if the init() has been sucessfully executed.
        Returns:
        true if the init() has been sucessfully executed.
      • packages

        public java.util.List<java.lang.String> packages()
      • customAnnotationPackages

        public java.util.List<java.lang.String> customAnnotationPackages()
        Return the list of packages the framework should look for AtmosphereAnnotation.
        Returns:
        the list of packages the framework should look for AtmosphereAnnotation
      • addCustomAnnotationPackage

        public AtmosphereFramework addCustomAnnotationPackage​(java.lang.Class p)
        Add a package containing classes annotated with AtmosphereAnnotation.
        Parameters:
        p - a package
        Returns:
        this;
      • newClassInstance

        public <T,​U extends T> T newClassInstance​(java.lang.Class<T> classType,
                                                        java.lang.Class<U> defaultType)
                                                 throws java.lang.InstantiationException,
                                                        java.lang.IllegalAccessException
        Instantiate a class
        Parameters:
        classType - The Required Class's Type
        defaultType - The default implementation of the Class's Type.
        Returns:
        the an instance of defaultType
        Throws:
        java.lang.InstantiationException
        java.lang.IllegalAccessException
      • objectFactory

        public void objectFactory​(AtmosphereObjectFactory objectFactory)
        Set an object used for class instantiation. Allows for integration with dependency injection frameworks.
        Parameters:
        objectFactory -
      • externalizeDestroy

        public AtmosphereFramework externalizeDestroy​(boolean externalizeDestroy)
        If set to true, the task of finishing the request/response lifecycle will not be handled by this class.
        Parameters:
        externalizeDestroy -
        Returns:
        this
      • isBroadcasterSpecified

        public boolean isBroadcasterSpecified()
        Was a Broadcaster defined in web.xml or programmatically added.
        Returns:
        true is defined.
      • configureObjectFactory

        protected void configureObjectFactory()
      • isAServletFilter

        public boolean isAServletFilter()
      • objectFactoryType

        public java.util.concurrent.ConcurrentLinkedQueue<java.lang.String> objectFactoryType()
      • mappingRegex

        public java.lang.String mappingRegex()
      • setUseServlet30

        public void setUseServlet30​(boolean useServlet30)
      • webSocketEnabled

        public boolean webSocketEnabled()
      • broadcasterLifeCyclePolicy

        public java.lang.String broadcasterLifeCyclePolicy()
      • broadcasterLifeCyclePolicy

        public AtmosphereFramework broadcasterLifeCyclePolicy​(java.lang.String broadcasterLifeCyclePolicy)
      • sharedThreadPools

        public boolean sharedThreadPools()
      • sharedThreadPools

        public AtmosphereFramework sharedThreadPools​(boolean sharedThreadPools)
      • allowAllClassesScan

        public boolean allowAllClassesScan()
      • allowAllClassesScan

        public AtmosphereFramework allowAllClassesScan​(boolean allowAllClassesScan)
      • externalizeDestroy

        public boolean externalizeDestroy()
      • excludedInterceptors

        public java.util.List<java.lang.String> excludedInterceptors()
      • getDefaultSerializerClassName

        public java.lang.String getDefaultSerializerClassName()
        Get the default Serializer class name to use for AtmosphereResources.
        Returns:
        the class name as a string, might be null if not configured
      • getDefaultSerializerClass

        public java.lang.Class<Serializer> getDefaultSerializerClass()
        Get the default Serializer class to use for AtmosphereResources.
        Returns:
        the class, might be null if not configured
      • setDefaultSerializerClassName

        public AtmosphereFramework setDefaultSerializerClassName​(java.lang.String defaultSerializerClassName)
        Set the default Serializer class name to use for AtmosphereResources.
        Parameters:
        defaultSerializerClassName - the class name to use
        Returns:
        this
      • isDestroyed

        public boolean isDestroyed()
        Return true is the destroy() method has been invoked.
        Returns:
        true is the destroy() method has been invoked.
      • onPreInit

        protected void onPreInit()
      • onPostInit

        protected void onPostInit()
      • onPreDestroy

        protected void onPreDestroy()
      • onPostDestroy

        protected void onPostDestroy()
      • uuidProvider

        public AtmosphereFramework uuidProvider​(UUIDProvider uuidProvider)
        Set a UUID like implementation for generating random UUID String
        Parameters:
        uuidProvider -
        Returns:
        this
      • initializationError

        public void initializationError​(java.lang.IllegalStateException initializationError)
        If a ContainerInitializer fail, log the excetion here.
        Parameters:
        initializationError -