FileDocCategorySizeDatePackage
CacheMgr.javaAPI DocGlassfish v2 API8989Fri May 04 22:24:44 BST 2007com.sun.enterprise.admin.wsmgmt.repository.impl.cache

CacheMgr

public class CacheMgr extends Object
Responsible for keeping track of the deployed applications and stand alone ejb and web modules with web services. This is a singleton for the domain. This class is intended to run on the Administration Server.
author
Nazrul Islam
since
J2SE 5.0

Fields Summary
private static CacheMgr
_mgr
private Map
_j2eeApplications
private Map
_ejbModules
private Map
_webModules
private static final String
EJB
private static final String
WEB
private static final String
CACHE_FILE
private static Logger
_logger
Constructors Summary
private CacheMgr()
Private constructor. Loads the cache index from the persistent store.

        load();
    
Methods Summary
voidaddEjbModule(java.lang.String name)
Adds an ejb module to the cache.

param
name name of the stand alone ejb module with web services

        _ejbModules.put(name, name);
    
voidaddJ2eeApplication(java.lang.String name, java.util.List ejbBundles, java.util.List webBundles)
Adds an application to the cache.

param
name name of the application
param
ejbBundles ejb bundles with web services
param
webBundles web bundles with web services


        J2eeApplication app = new J2eeApplication(name, ejbBundles, webBundles);
        _j2eeApplications.put(name, app);
    
voidaddWebModule(java.lang.String name)
Adds a web module to the cache.

param
name name of the stand alone web module with web services

        _webModules.put(name, name);
    
public java.util.MapgetEjbModules()
Returns all stand alone ejb modules with web services.

return
stand alone ejb module with web services

        return _ejbModules;
    
public static synchronized com.sun.enterprise.admin.wsmgmt.repository.impl.cache.CacheMgrgetInstance()
Returns the singleton instance of this class.

return
sigleton instance of this class

        if (_mgr == null) {
            _mgr = new CacheMgr();
        }

        return _mgr;
    
public java.util.MapgetJ2eeApplications()
Returns all j2ee applications with web services.

return
j2ee applications with web services

        return _j2eeApplications;
    
private java.lang.StringgetPropertyFile()
Returns the persistent cache index location.

return
the persistent cache file location

        String iRoot = 
            System.getProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY);
        String file = iRoot + File.separator + PEFileLayout.GENERATED_DIR 
                    + File.separator + CACHE_FILE;
        return file;
    
public java.util.MapgetWebModules()
Returns all stand alone web apps with web services.

return
web apps with web services

        return _webModules;
    
private voidload()
Reads from the persistent cache index property file.


        FileInputStream fis = null;
        try {
            File file = new File(getPropertyFile());

            // abort if file does not exist
            if (!file.exists()) {
                return;
            }

            fis = new FileInputStream(file);
            Properties pro = new Properties();
            pro.load(fis);

            for (Enumeration e = pro.keys(); e.hasMoreElements();) {
                String key = (String) e.nextElement();
                String val = pro.getProperty(key);

                if (EJB.equals(val)) {
                    _ejbModules.put(key, key);
                } else if (WEB.equals(val)) {
                    _webModules.put(key, key);
                } else {
                    J2eeApplication app = new J2eeApplication(key, val);
                    _j2eeApplications.put(key, app);
                }
            }
        } catch (Exception e) {
            _logger.log(Level.FINE, 
                "Error while loading ws-mgmt cache file", e);
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (Exception e) { }
            }
        }
    
java.lang.StringremoveEjbModule(java.lang.String name)
Removes an ejb module from cache.

param
name name of the stand alone ejb module

        return (String) _ejbModules.remove(name);
    
J2eeApplicationremoveJ2eeApplication(java.lang.String name)
Removes an application from the cache.

param
name name of the application

        return (J2eeApplication) _j2eeApplications.remove(name);
    
java.lang.StringremoveWebModule(java.lang.String name)
Removes a web module from cache.

param
name name of the stand alone web module

        return (String) _webModules.remove(name);
    
voidsave()
Saves the current in memory cache indexes to a property file.


        FileOutputStream fos = null;
        try {
            Properties pro = new Properties();

            Collection eValues = _ejbModules.values();
            for (Iterator iter=eValues.iterator(); iter.hasNext();) {
                String ejbMod = (String) iter.next();
                pro.put(ejbMod, EJB);
            }
            Collection wValues = _webModules.values();
            for (Iterator iter=wValues.iterator(); iter.hasNext();) {
                String webMod = (String) iter.next();
                pro.put(webMod, WEB);
            }
            Collection aValues = _j2eeApplications.values();
            for (Iterator iter=aValues.iterator(); iter.hasNext();) {
                J2eeApplication app = (J2eeApplication) iter.next();
                pro.put(app.getName(), app.getPersistentValue());
            }

            File file = new File(getPropertyFile());
            fos = new FileOutputStream(file);
            pro.store(fos, "");

        } catch (Exception e) {
            _logger.log(Level.FINE, "Error while saving ws-mgmt cache file", e);
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (Exception e) { }
            }
        }