Package com.sun.appserv.web.cache

Examples of com.sun.appserv.web.cache.CacheManager


     */
    public void contextInitialized(ServletContextEvent sce) {
        ServletContext context = sce.getServletContext();

        // see if a cache manager is already created and set in the context
        CacheManager cm = (CacheManager)context.getAttribute(CacheManager.CACHE_MANAGER_ATTR_NAME);

        // create a new cachemanager if one is not present and use it
        // to create a new cache
        if (cm == null)
            cm = new CacheManager();

        Cache cache = null;
        try {
            cache = cm.createCache();
        } catch (Exception ex) {}

        // set the cache as a context attribute
        if (cache != null)
            context.setAttribute(Constants.JSPTAG_CACHE_KEY, cache);
View Full Code Here


        ServletContext context = sre.getServletContext();

        // Check if a cache manager has already been created and set in the
        // context
        CacheManager cm = (CacheManager)
            context.getAttribute(CacheManager.CACHE_MANAGER_ATTR_NAME);

        // Create a new cache manager if one is not present and use it
        // to create a new cache
        if (cm == null) {
            cm = new CacheManager();
        }

        Cache cache = null;
        try {
            cache = cm.createCache();
        } catch (Exception ex) {}

        // Set the cache as a request attribute
        if (cache != null) {
            ServletRequest req = sre.getServletRequest();
View Full Code Here

        HttpSession session = hse.getSession()
        ServletContext context = session.getServletContext();

        // Check if a cache manager has already been created and set in the
        // context
        CacheManager cm = (CacheManager)
            context.getAttribute(CacheManager.CACHE_MANAGER_ATTR_NAME);

        // Create a new cache manager if one is not present and use it
        // to create a new cache
        if (cm == null) {
            cm = new CacheManager();
        }

        Cache cache = null;
        try {
            cache = cm.createCache();
        } catch (Exception ex) {}

        // Set the cache as a session attribute
        if (cache != null) {
            session.setAttribute(Constants.JSPTAG_CACHE_KEY, cache);
View Full Code Here

        if (logger.isLoggable(Level.FINE)) {
            logger.fine("configuring cache for web application " + app.getPath());
        }

        // create the CacheManager object for this app
        CacheManager manager = new CacheManager();

        String name, value;
        value = cacheConfig.getAttributeValue(Cache.ENABLED);
        if (value != null) {
            boolean enabled = ConfigBean.toBoolean(value);
            manager.setEnabled(enabled);
        }

        // set cache element's attributes and properties
        value = cacheConfig.getAttributeValue(Cache.MAX_ENTRIES);
        if (value != null) {
            try {
                int maxEntries = Integer.parseInt(value.trim());
                manager.setMaxEntries(maxEntries);
            } catch (NumberFormatException e) {
                // XXX need error message
                throw new Exception("invalid max-entries", e);
            }
        }

        value = cacheConfig.getAttributeValue(Cache.TIMEOUT_IN_SECONDS);
        if (value != null) {
            try {
                int defaultTimeout = Integer.parseInt(value.trim());
                manager.setDefaultTimeout(defaultTimeout);
            } catch (NumberFormatException e) {
                // XXX need error message
                throw new Exception("invalid timeout", e);
            }
        }

        WebProperty[] props = cacheConfig.getWebProperty();
        for (int i = 0; i < props.length; i++) {
            name = props[i].getAttributeValue(WebProperty.NAME);
            value = props[i].getAttributeValue(WebProperty.VALUE);

            manager.addProperty(name, value);
        }
       
        // configure the default cache-helper
        DefaultHelper defHelperConfig = cacheConfig.getDefaultHelper();

        HashMap map = new HashMap();
        if (defHelperConfig != null) {
            props = defHelperConfig.getWebProperty();
            for (int i = 0; i < props.length; i++) {
                name = props[i].getAttributeValue(WebProperty.NAME);
                value = props[i].getAttributeValue(WebProperty.VALUE);

                map.put(name, value);
            }
        }
        manager.setDefaultHelperProps(map);

        // configure custom cache-helper classes
        for (int i = 0; i < cacheConfig.sizeCacheHelper(); i++) {
            CacheHelper helperConfig = cacheConfig.getCacheHelper(i);

            String helperName = helperConfig.getAttributeValue(
                CacheHelper.NAME);
            HashMap helperProps = new HashMap();
            props = helperConfig.getWebProperty();
            for (int j = 0; j < props.length; j++) {
                name = props[i].getAttributeValue(WebProperty.NAME);
                value = props[i].getAttributeValue(WebProperty.VALUE);

                helperProps.put(name, value);
            }
            helperProps.put("class-name",
                            helperConfig.getAttributeValue(
                            CacheHelper.CLASS_NAME));

            manager.addCacheHelperDef(helperName, helperProps);
        }

        // for each cache-mapping, create CacheMapping, setup the filter
        for (int i = 0; i < cacheConfig.sizeCacheMapping(); i++) {
            com.sun.enterprise.deployment.runtime.web.CacheMapping
                            mapConfig = cacheConfig.getCacheMapping(i);
           
            CacheMapping mapping = new CacheMapping();
            configureCacheMapping(mapConfig, mapping, logger);

            // use filter's name to refer to setup the filter
            String filterName = CACHING_FILTER_CLASSNAME + i;

            /**
             * all cache-mapings are indexed by the unique filter-name;
             * DefaultCacheHelper uses this name to access the mapping.
             */
            manager.addCacheMapping(filterName, mapping);

            // setup the ias CachingFilter definition with the context
            FilterDef filterDef = new FilterDef();
            filterDef.setFilterName(filterName);
            filterDef.setFilterClass(CACHING_FILTER_CLASSNAME);

            filterDef.addInitParameter("servletName", mapping.getServletName());
            filterDef.addInitParameter("URLPattern", mapping.getURLPattern());
            app.addFilterDef(filterDef);

            // setup the mapping for the specified servlet-name or url-pattern
            FilterMap filterMap = new FilterMap();
            filterMap.setServletName(mapping.getServletName());
            filterMap.setURLPattern(mapping.getURLPattern());
            String[] dispatchers = mapConfig.getDispatcher();
            for (int j=0; dispatchers!=null && j<dispatchers.length; j++) {
                // calls to FilterMap.setDispatcher are cumulative
                filterMap.setDispatcher(dispatchers[j]);
            }
            filterMap.setFilterName(filterName);
            app.addFilterMap(filterMap);

            if (logger.isLoggable(Level.FINE)) {
                logger.fine("added a caching filter for servlet-name = " + mapping.getServletName() + " url-pattern = " + mapping.getURLPattern());
            }
        }
       
        manager.setServletContext(app.getServletContext());
        return manager;
    }
View Full Code Here

        SunWebApp bean  = webModule.getIasWebAppConfigBean();

        // Configure the cache, cache-mapping and other settings
        if (bean != null) {
            CacheManager cm = null;
            try {
                cm = CacheModule.configureResponseCache(webModule, bean);
            } catch (Exception ee) {
                _logger.log(Level.WARNING,
                           "webmodule.listener.cachemgrException", ee);
            }
       
            if (cm != null) {
                try {
                    // first start the CacheManager, if enabled
                    cm.start();
                    if (_debugLog) {
                        _logger.fine("Cache Manager started");
                    }
                    // set this manager as a context attribute so that
                    // caching filters/tags can find it
View Full Code Here

        }
    }

    private void stopCacheManager(WebModule webModule) {
        ServletContext ctxt = webModule.getServletContext();
        CacheManager cm = (CacheManager)ctxt.getAttribute(
                                        CacheManager.CACHE_MANAGER_ATTR_NAME);
        if (cm != null) {
            try {
                cm.stop();
                if (_debugLog) {
                    _logger.fine("Cache Manager stopped");
                }
                ctxt.removeAttribute(CacheManager.CACHE_MANAGER_ATTR_NAME);
            } catch (LifecycleException ee) {
View Full Code Here

        if (logger.isLoggable(Level.FINE)) {
            logger.log(Level.FINE, CONFIGURE_CACHE, app.getPath());
        }

        // create the CacheManager object for this app
        CacheManager manager = new CacheManager();

        String name, value;
        value = cacheConfig.getAttributeValue(Cache.ENABLED);
        if (value != null) {
            boolean enabled = ConfigBeansUtilities.toBoolean(value);
            manager.setEnabled(enabled);
        }

        // set cache element's attributes and properties
        value = cacheConfig.getAttributeValue(Cache.MAX_ENTRIES);
        if (value != null) {
            try {
                int maxEntries = Integer.parseInt(value.trim());
                manager.setMaxEntries(maxEntries);
            } catch (NumberFormatException e) {
                // XXX need error message
                throw new Exception("invalid max-entries", e);
            }
        }

        value = cacheConfig.getAttributeValue(Cache.TIMEOUT_IN_SECONDS);
        if (value != null) {
            try {
                int defaultTimeout = Integer.parseInt(value.trim());
                manager.setDefaultTimeout(defaultTimeout);
            } catch (NumberFormatException e) {
                // XXX need error message
                throw new Exception("invalid timeout", e);
            }
        }

        WebProperty[] props = cacheConfig.getWebProperty();
        for (int i = 0; i < props.length; i++) {
            name = props[i].getAttributeValue(WebProperty.NAME);
            value = props[i].getAttributeValue(WebProperty.VALUE);

            manager.addProperty(name, value);
        }
       
        // configure the default cache-helper
        DefaultHelper defHelperConfig = cacheConfig.getDefaultHelper();

        HashMap<String, String> map = new HashMap<String, String>();
        if (defHelperConfig != null) {
            props = defHelperConfig.getWebProperty();
            for (int i = 0; i < props.length; i++) {
                name = props[i].getAttributeValue(WebProperty.NAME);
                value = props[i].getAttributeValue(WebProperty.VALUE);

                map.put(name, value);
            }
        }
        manager.setDefaultHelperProps(map);

        // configure custom cache-helper classes
        for (int i = 0; i < cacheConfig.sizeCacheHelper(); i++) {
            CacheHelper helperConfig = cacheConfig.getCacheHelper(i);

            String helperName = helperConfig.getAttributeValue(
                CacheHelper.NAME);
            HashMap<String, String> helperProps = new HashMap<String, String>();
            props = helperConfig.getWebProperty();
            for (int j = 0; j < props.length; j++) {
                name = props[i].getAttributeValue(WebProperty.NAME);
                value = props[i].getAttributeValue(WebProperty.VALUE);

                helperProps.put(name, value);
            }
            helperProps.put("class-name",
                            helperConfig.getAttributeValue(
                            CacheHelper.CLASS_NAME));

            manager.addCacheHelperDef(helperName, helperProps);
        }

        // for each cache-mapping, create CacheMapping, setup the filter
        for (int i = 0; i < cacheConfig.sizeCacheMapping(); i++) {
            org.glassfish.web.deployment.runtime.CacheMapping
                            mapConfig = cacheConfig.getCacheMapping(i);
           
            CacheMapping mapping = new CacheMapping();
            configureCacheMapping(mapConfig, mapping, logger);

            // use filter's name to refer to setup the filter
            String filterName = CACHING_FILTER_CLASSNAME + i;

            /**
             * all cache-mapings are indexed by the unique filter-name;
             * DefaultCacheHelper uses this name to access the mapping.
             */
            manager.addCacheMapping(filterName, mapping);

            // setup the ias CachingFilter definition with the context
            FilterDef filterDef = new FilterDef();
            filterDef.setFilterName(filterName);
            filterDef.setFilterClassName(CACHING_FILTER_CLASSNAME);

            if (mapping.getServletName() != null) {
                filterDef.addInitParameter("servletName",
                                           mapping.getServletName());
            }
            if (mapping.getURLPattern() != null) {
                filterDef.addInitParameter("URLPattern",
                                           mapping.getURLPattern());
            }

            app.addFilterDef(filterDef);

            // setup the mapping for the specified servlet-name or url-pattern
            FilterMap filterMap = new FilterMap();
            filterMap.setServletName(mapping.getServletName());
            filterMap.setURLPattern(mapping.getURLPattern());
            String[] dispatchers = mapConfig.getDispatcher();
            if (dispatchers != null) {
                EnumSet<DispatcherType> dispatcherTypes = null;
                for (String dispatcher : dispatchers) {
                    // calls to FilterMap.setDispatcher are cumulative
                    if (dispatcherTypes == null) {
                        dispatcherTypes = EnumSet.of(
                            Enum.valueOf(DispatcherType.class, dispatcher));
                    } else {
                        dispatcherTypes.add(
                            Enum.valueOf(DispatcherType.class, dispatcher));
                    }
                }
                filterMap.setDispatcherTypes(dispatcherTypes);
            }
            filterMap.setFilterName(filterName);
            app.addFilterMap(filterMap);

            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE,
                        CACHING_FILTER_ADDED,
                        new Object[] {mapping.getServletName(), mapping.getURLPattern()});
            }
        }
       
        manager.setServletContext(app.getServletContext());
        return manager;
    }
View Full Code Here

        SunWebApp bean  = webModule.getIasWebAppConfigBean();

        // Configure the cache, cache-mapping and other settings
        if (bean != null) {
            CacheManager cm = null;
            try {
                cm = CacheModule.configureResponseCache(webModule, bean);
            } catch (Exception ee) {
                _logger.log(Level.WARNING, CACHE_MRG_EXCEPTION, ee);
            }
       
            if (cm != null) {
                try {
                    // first start the CacheManager, if enabled
                    cm.start();
                    if (_logger.isLoggable(Level.FINE)) {
                        _logger.log(Level.FINE, CACHE_MANAGER_STARTED);
                    }
                    // set this manager as a context attribute so that
                    // caching filters/tags can find it
View Full Code Here

        }
    }

    private void stopCacheManager(WebModule webModule) {
        ServletContext ctxt = webModule.getServletContext();
        CacheManager cm = (CacheManager)ctxt.getAttribute(
                                        CacheManager.CACHE_MANAGER_ATTR_NAME);
        if (cm != null) {
            try {
                cm.stop();
                if (_logger.isLoggable(Level.FINE)) {
                    _logger.log(Level.FINE, CACHE_MANAGER_STOPPED);
                }
                ctxt.removeAttribute(CacheManager.CACHE_MANAGER_ATTR_NAME);
            } catch (LifecycleException ee) {
View Full Code Here

        if (logger.isLoggable(Level.FINE)) {
            logger.fine("configuring cache for web application " + app.getPath());
        }

        // create the CacheManager object for this app
        CacheManager manager = new CacheManager();

        String name, value;
        value = cacheConfig.getAttributeValue(Cache.ENABLED);
        if (value != null) {
            boolean enabled = ConfigBeansUtilities.toBoolean(value);
            manager.setEnabled(enabled);
        }

        // set cache element's attributes and properties
        value = cacheConfig.getAttributeValue(Cache.MAX_ENTRIES);
        if (value != null) {
            try {
                int maxEntries = Integer.parseInt(value.trim());
                manager.setMaxEntries(maxEntries);
            } catch (NumberFormatException e) {
                // XXX need error message
                throw new Exception("invalid max-entries", e);
            }
        }

        value = cacheConfig.getAttributeValue(Cache.TIMEOUT_IN_SECONDS);
        if (value != null) {
            try {
                int defaultTimeout = Integer.parseInt(value.trim());
                manager.setDefaultTimeout(defaultTimeout);
            } catch (NumberFormatException e) {
                // XXX need error message
                throw new Exception("invalid timeout", e);
            }
        }

        WebProperty[] props = cacheConfig.getWebProperty();
        for (int i = 0; i < props.length; i++) {
            name = props[i].getAttributeValue(WebProperty.NAME);
            value = props[i].getAttributeValue(WebProperty.VALUE);

            manager.addProperty(name, value);
        }
       
        // configure the default cache-helper
        DefaultHelper defHelperConfig = cacheConfig.getDefaultHelper();

        HashMap<String, String> map = new HashMap<String, String>();
        if (defHelperConfig != null) {
            props = defHelperConfig.getWebProperty();
            for (int i = 0; i < props.length; i++) {
                name = props[i].getAttributeValue(WebProperty.NAME);
                value = props[i].getAttributeValue(WebProperty.VALUE);

                map.put(name, value);
            }
        }
        manager.setDefaultHelperProps(map);

        // configure custom cache-helper classes
        for (int i = 0; i < cacheConfig.sizeCacheHelper(); i++) {
            CacheHelper helperConfig = cacheConfig.getCacheHelper(i);

            String helperName = helperConfig.getAttributeValue(
                CacheHelper.NAME);
            HashMap<String, String> helperProps = new HashMap<String, String>();
            props = helperConfig.getWebProperty();
            for (int j = 0; j < props.length; j++) {
                name = props[i].getAttributeValue(WebProperty.NAME);
                value = props[i].getAttributeValue(WebProperty.VALUE);

                helperProps.put(name, value);
            }
            helperProps.put("class-name",
                            helperConfig.getAttributeValue(
                            CacheHelper.CLASS_NAME));

            manager.addCacheHelperDef(helperName, helperProps);
        }

        // for each cache-mapping, create CacheMapping, setup the filter
        for (int i = 0; i < cacheConfig.sizeCacheMapping(); i++) {
            com.sun.enterprise.deployment.runtime.web.CacheMapping
                            mapConfig = cacheConfig.getCacheMapping(i);
           
            CacheMapping mapping = new CacheMapping();
            configureCacheMapping(mapConfig, mapping, logger);

            // use filter's name to refer to setup the filter
            String filterName = CACHING_FILTER_CLASSNAME + i;

            /**
             * all cache-mapings are indexed by the unique filter-name;
             * DefaultCacheHelper uses this name to access the mapping.
             */
            manager.addCacheMapping(filterName, mapping);

            // setup the ias CachingFilter definition with the context
            FilterDef filterDef = new FilterDef();
            filterDef.setFilterName(filterName);
            filterDef.setFilterClassName(CACHING_FILTER_CLASSNAME);

            if (mapping.getServletName() != null) {
                filterDef.addInitParameter("servletName",
                                           mapping.getServletName());
            }
            if (mapping.getURLPattern() != null) {
                filterDef.addInitParameter("URLPattern",
                                           mapping.getURLPattern());
            }

            app.addFilterDef(filterDef);

            // setup the mapping for the specified servlet-name or url-pattern
            FilterMap filterMap = new FilterMap();
            filterMap.setServletName(mapping.getServletName());
            filterMap.setURLPattern(mapping.getURLPattern());
            String[] dispatchers = mapConfig.getDispatcher();
            if (dispatchers != null) {
                EnumSet<DispatcherType> dispatcherTypes = null;
                for (String dispatcher : dispatchers) {
                    // calls to FilterMap.setDispatcher are cumulative
                    if (dispatcherTypes == null) {
                        dispatcherTypes = EnumSet.of(
                            Enum.valueOf(DispatcherType.class, dispatcher));
                    } else {
                        dispatcherTypes.add(
                            Enum.valueOf(DispatcherType.class, dispatcher));
                    }
                }
                filterMap.setDispatcherTypes(dispatcherTypes);
            }
            filterMap.setFilterName(filterName);
            app.addFilterMap(filterMap);

            if (logger.isLoggable(Level.FINE)) {
                logger.fine("added a caching filter for servlet-name = " + mapping.getServletName() + " url-pattern = " + mapping.getURLPattern());
            }
        }
       
        manager.setServletContext(app.getServletContext());
        return manager;
    }
View Full Code Here

TOP

Related Classes of com.sun.appserv.web.cache.CacheManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.