User: simone  
  Date: 00/10/19 14:43:34

  Added:       src/main/org/jboss/ejb/deployment
                        StatefulSessionInstanceCacheConfiguration.java
                        LRUEnterpriseContextCachePolicyConfiguration.java
                        InstanceCacheSupportConfiguration.java
                        EntityInstanceCacheConfiguration.java
                        CachePolicySupportConfiguration.java
  Log:
  Bean used by EJX for the configuration of the new passivating caches
  
  Revision  Changes    Path
  1.1                  
jboss/src/main/org/jboss/ejb/deployment/StatefulSessionInstanceCacheConfiguration.java
  
  Index: StatefulSessionInstanceCacheConfiguration.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.ejb.deployment;
  
  /**
   *
   *
   * @see
   * @author Simone Bordet ([EMAIL PROTECTED])
   * @version $Revision: 1.1 $
   */
  public class StatefulSessionInstanceCacheConfiguration 
        extends InstanceCacheSupportConfiguration 
  {
        // Constants -----------------------------------------------------
  
        // Attributes ----------------------------------------------------
  
        // Static --------------------------------------------------------
  
        // Constructors --------------------------------------------------
  
        // Public --------------------------------------------------------
  
        // Z implementation ----------------------------------------------
  
        // Y overrides ---------------------------------------------------
  
        // Package protected ---------------------------------------------
  
        // Protected -----------------------------------------------------
  
        // Private -------------------------------------------------------
  
        // Inner classes -------------------------------------------------
  }
  
  
  
  1.1                  
jboss/src/main/org/jboss/ejb/deployment/LRUEnterpriseContextCachePolicyConfiguration.java
  
  Index: LRUEnterpriseContextCachePolicyConfiguration.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.ejb.deployment;
  
  import org.w3c.dom.Element;
  import org.w3c.dom.Document;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import com.dreambean.ejx.xml.XMLManager;
  
  /**
   *
   *
   * @see
   * @author Simone Bordet ([EMAIL PROTECTED])
   * @version $Revision: 1.1 $
   */
  public class LRUEnterpriseContextCachePolicyConfiguration 
        extends CachePolicySupportConfiguration 
  {
        // Constants -----------------------------------------------------
  
        // Attributes ----------------------------------------------------
        private int m_minCapacity;
        private int m_maxCapacity;
        private int m_resizerPeriod;
        private int m_overagerPeriod;
        private int m_maxBeanAge;
        private int m_minCacheMissPeriod;
        private int m_maxCacheMissPeriod;
        private double m_cacheLoadFactor;
  
        // Static --------------------------------------------------------
        private static int DEFAULT_MAX_CAPACITY;
        private static int DEFAULT_MIN_CAPACITY;
        private static int DEFAULT_RESIZER_PERIOD;
        private static int DEFAULT_OVERAGER_PERIOD;
        private static int DEFAULT_MAX_BEAN_AGE;
        private static int DEFAULT_MAX_CACHE_MISS_PERIOD;
        private static int DEFAULT_MIN_CACHE_MISS_PERIOD;
        private static double DEFAULT_CACHE_LOAD_FACTOR;
  
        // Constructors --------------------------------------------------
        public LRUEnterpriseContextCachePolicyConfiguration()
        {
                m_minCapacity = DEFAULT_MIN_CAPACITY;
                m_maxCapacity = DEFAULT_MAX_CAPACITY;
                m_resizerPeriod = DEFAULT_RESIZER_PERIOD;
                m_overagerPeriod = DEFAULT_OVERAGER_PERIOD;
                m_maxBeanAge = DEFAULT_MAX_BEAN_AGE;
                m_minCacheMissPeriod = DEFAULT_MIN_CACHE_MISS_PERIOD;
                m_maxCacheMissPeriod = DEFAULT_MAX_CACHE_MISS_PERIOD;
                m_cacheLoadFactor = DEFAULT_CACHE_LOAD_FACTOR;
        }
  
        // Public --------------------------------------------------------
        public int getMinimumCapacity() {return m_minCapacity;}
        public void setMinimumCapacity(int size) 
        {
                if (size < 1) throw new IllegalArgumentException("Minimum cache size 
less than 1");
                m_minCapacity = size;
        }
        public int getMaximumCapacity() {return m_maxCapacity;}
        public void setMaximumCapacity(int size) 
        {
                if (size < 1) throw new IllegalArgumentException("Maximum cache size 
less than 1");
                m_maxCapacity = size;
        }
        public int getResizerPeriod() {return m_resizerPeriod;}
        public void setResizerPeriod(int period) 
        {
                if (period < 0) {throw new IllegalArgumentException("Resizer period 
can't be < 0");}
                m_resizerPeriod = period;
        }
        public int getOveragerPeriod() {return m_overagerPeriod;}
        public void setOveragerPeriod(int period) 
        {
                if (period < 0) {throw new IllegalArgumentException("Overager period 
can't be < 0");}
                m_overagerPeriod = period;
        }
        public int getMaxBeanAge() {return m_maxBeanAge;}
        public void setMaxBeanAge(int age) 
        {
                if (age <= 0) {throw new IllegalArgumentException("Max bean age can't 
be <= 0");}
                m_maxBeanAge = age;
        }
        public int getMinCacheMissPeriod() {return m_minCacheMissPeriod;}
        public void setMinCacheMissPeriod(int period) 
        {
                if (period <= 0) {throw new IllegalArgumentException("Min cache miss 
period can't be <= 0");}
                m_minCacheMissPeriod = period;
        }
        public int getMaxCacheMissPeriod() {return m_maxCacheMissPeriod;}
        public void setMaxCacheMissPeriod(int period) 
        {
                if (period <= 0) {throw new IllegalArgumentException("Max cache miss 
period can't be <= 0");}
                m_maxCacheMissPeriod = period;
        }
        public double getCacheLoadFactor() {return m_cacheLoadFactor;}
        public void setCacheLoadFactor(double factor) 
        {
                if (factor <= 0.0 || factor >= 1.0) {throw new 
IllegalArgumentException("Cache load factor can't be <= 0 or >= 1");}
                m_cacheLoadFactor = factor;
        }
        
        // Z implementation ----------------------------------------------
  
        // Y overrides ---------------------------------------------------
        public Element exportXml(Document doc)
                throws Exception
        {
                
                Element policyConfig = super.exportXml(doc);
                XMLManager.addElement(policyConfig, "min-capacity" , 
Integer.toString(getMinimumCapacity()));
                XMLManager.addElement(policyConfig, "max-capacity" , 
Integer.toString(getMaximumCapacity()));
                XMLManager.addElement(policyConfig, "overager-period" , 
Integer.toString(getOveragerPeriod()));
                XMLManager.addElement(policyConfig, "resizer-period" , 
Integer.toString(getResizerPeriod()));
                XMLManager.addElement(policyConfig, "max-bean-age", 
Integer.toString(getMaxBeanAge()));
                XMLManager.addElement(policyConfig, "max-cache-miss-period" , 
Integer.toString(getMaxCacheMissPeriod()));
                XMLManager.addElement(policyConfig, "min-cache-miss-period" , 
Integer.toString(getMinCacheMissPeriod()));
                XMLManager.addElement(policyConfig, "cache-load-factor" , 
Double.toString(getCacheLoadFactor()));
                return policyConfig;
        }
                
        public void importXml(Element elt)
                throws Exception
        {
                super.importXml(elt);
                if 
(elt.getOwnerDocument().getDocumentElement().getTagName().equals(jBossEjbJar.JBOSS_DOCUMENT))
                {
                        NodeList nl = elt.getChildNodes();
                        int l = nl.getLength();
                        for (int i = 0; i < l; ++i)
                        {
                                Node n = nl.item(i);
                                String name = n.getNodeName();
                                if (name.equals("min-capacity"))
                                {
                                        int s = 0;
                                        String period = n.hasChildNodes() ? 
XMLManager.getString(n) : "";
                                        if (!period.trim().equals(""))
                                        {
                                                try {s = Integer.parseInt(period);}
                                                catch (NumberFormatException ignored) 
{}
                                        }
                                        setMinimumCapacity(s);
                                        if (DEFAULT_MIN_CAPACITY == 0)
                                        {
                                                DEFAULT_MIN_CAPACITY = s;
                                        }
                                }
                                else if (name.equals("max-capacity"))
                                {
                                        int s = 0;
                                        String period = n.hasChildNodes() ? 
XMLManager.getString(n) : "";
                                        if (!period.trim().equals(""))
                                        {
                                                try {s = Integer.parseInt(period);}
                                                catch (NumberFormatException ignored) 
{}
                                        }
                                        setMaximumCapacity(s);
                                        if (DEFAULT_MAX_CAPACITY == 0)
                                        {
                                                DEFAULT_MAX_CAPACITY = s;
                                        }
                                }
                                else if (name.equals("overager-period"))
                                {
                                        int p = 0;
                                        String period = n.hasChildNodes() ? 
XMLManager.getString(n) : "";
                                        if (!period.trim().equals(""))
                                        {
                                                try {p = Integer.parseInt(period);}
                                                catch (NumberFormatException ignored) 
{}
                                        }
                                        setOveragerPeriod(p);
                                        if (DEFAULT_OVERAGER_PERIOD == 0)
                                        {
                                                DEFAULT_OVERAGER_PERIOD = p;
                                        }
                                } 
                                else if (name.equals("resizer-period")) 
                                {
                                        int p = 0;
                                        String period = n.hasChildNodes() ? 
XMLManager.getString(n) : "";
                                        if (!period.trim().equals(""))
                                        {
                                                try {p = Integer.parseInt(period);}
                                                catch (NumberFormatException ignored) 
{}
                                        }
                                        setResizerPeriod(p);
                                        if (DEFAULT_RESIZER_PERIOD == 0)
                                        {
                                                DEFAULT_RESIZER_PERIOD = p;
                                        }
                                }
                                else if (name.equals("max-bean-age"))
                                {
                                        int a = 0;
                                        String age = n.hasChildNodes() ? 
XMLManager.getString(n) : "";
                                        if (!age.trim().equals(""))
                                        {
                                                try {a = Integer.parseInt(age);}
                                                catch (NumberFormatException ignored) 
{}
                                        }
                                        setMaxBeanAge(a);
                                        if (DEFAULT_MAX_BEAN_AGE == 0)
                                        {
                                                DEFAULT_MAX_BEAN_AGE = a;
                                        }
                                } 
                                else if (name.equals("max-cache-miss-period")) 
                                {
                                        int p = 0;
                                        String period = n.hasChildNodes() ? 
XMLManager.getString(n) : "";
                                        if (!period.trim().equals(""))
                                        {
                                                try {p = Integer.parseInt(period);}
                                                catch (NumberFormatException ignored) 
{}
                                        }
                                        setMaxCacheMissPeriod(p);
                                        if (DEFAULT_MAX_CACHE_MISS_PERIOD == 0)
                                        {
                                                DEFAULT_MAX_CACHE_MISS_PERIOD = p;
                                        }
                                }
                                else if (name.equals("min-cache-miss-period")) 
                                {
                                        int p = 0;
                                        String period = n.hasChildNodes() ? 
XMLManager.getString(n) : "";
                                        if (!period.trim().equals(""))
                                        {
                                                try {p = Integer.parseInt(period);}
                                                catch (NumberFormatException ignored) 
{}
                                        }
                                        setMinCacheMissPeriod(p);
                                        if (DEFAULT_MIN_CACHE_MISS_PERIOD == 0)
                                        {
                                                DEFAULT_MIN_CACHE_MISS_PERIOD = p;
                                        }
                                }
                                else if (name.equals("cache-load-factor")) 
                                {
                                        double f = 0.0;
                                        String factor = n.hasChildNodes() ? 
XMLManager.getString(n) : "";
                                        if (!factor.trim().equals(""))
                                        {
                                                try {f = Double.parseDouble(factor);}
                                                catch (NumberFormatException ignored) 
{}
                                        }
                                        setCacheLoadFactor(f);
                                        if (DEFAULT_CACHE_LOAD_FACTOR == 0.0)
                                        {
                                                DEFAULT_CACHE_LOAD_FACTOR = f;
                                        }
                                }
                        }
                }
        }
        // Package protected ---------------------------------------------
  
        // Protected -----------------------------------------------------
  
        // Private -------------------------------------------------------
  
        // Inner classes -------------------------------------------------
  }
  
  
  
  1.1                  
jboss/src/main/org/jboss/ejb/deployment/InstanceCacheSupportConfiguration.java
  
  Index: InstanceCacheSupportConfiguration.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.ejb.deployment;
  
  import java.awt.Component;
  import java.beans.beancontext.BeanContextSupport;
  import java.beans.beancontext.BeanContextChildComponentProxy;
  import java.beans.beancontext.BeanContextContainerProxy;
  import com.dreambean.ejx.xml.XmlExternalizable;
  import com.dreambean.ejx.xml.XMLManager;
  import org.w3c.dom.Element;
  import org.w3c.dom.Document;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  
  /**
   *
   *
   * @see
   * @author Simone Bordet ([EMAIL PROTECTED])
   * @version $Revision: 1.1 $
   */
  public class InstanceCacheSupportConfiguration 
        extends BeanContextSupport
        implements BeanContextChildComponentProxy, XmlExternalizable
  {
        // Constants -----------------------------------------------------
  
        // Attributes ----------------------------------------------------
        private String m_cachePolicyClassName;
        private Component m_component;
        private Object m_policyConfiguration;
  
        // Static --------------------------------------------------------
  
        // Constructors --------------------------------------------------
        public InstanceCacheSupportConfiguration()
        {
                // Initializing this attribute is fundamental for EJX to work 
correctly,
                // otherwise when selecting in EJX for the first time an object of 
this 
                // (sub)class that was removed and re-added, the children of this 
object 
                // are not created because setCachePolicy is not called (due to the 
fact 
                // that getCachePolicy returns null); setting it by default to the 
empty 
                // string ensure that setCachePolicy is called the first time this 
object 
                // is selected and thus its children created.  
                m_cachePolicyClassName = "";
        }
  
        // Public --------------------------------------------------------
        public void setCachePolicy(String className) 
        {
                if (className == null || className.trim().equals("")) throw new 
IllegalArgumentException("Cache policy class name not defined");
                m_cachePolicyClassName = className;
  
                if (m_policyConfiguration != null)
                {
                        remove(m_policyConfiguration);
                        m_policyConfiguration = null;
                }
  
                try
                {
                        String confName = getConfigurationClassName(className);
                        Class clazz = 
Thread.currentThread().getContextClassLoader().loadClass(confName);
                        Object obj = clazz.newInstance();
                        if (obj instanceof BeanContextChildComponentProxy || obj 
instanceof BeanContextContainerProxy)
                        {
                                m_policyConfiguration = obj;
                                add(m_policyConfiguration);
                        }
                } 
                catch (Throwable ignored) {}
        }
        public String getCachePolicy() 
        {
                return m_cachePolicyClassName;
        }
        public Object getPolicyConfiguration() 
        {
                return m_policyConfiguration;
        }
  
        // BeanContextChildComponentProxy implementation -----------------
        public Component getComponent()
        {
                if (m_component == null) m_component = new 
com.dreambean.awt.GenericCustomizer(this);
                return m_component;
        }
        // XmlExternalizable implementation ------------------------------
        public Element exportXml(Document doc)
                throws Exception
        {
                Element cacheConfig = doc.createElement("container-cache-conf");
                XMLManager.addElement(cacheConfig, "cache-policy" , getCachePolicy());
                if (m_policyConfiguration != null)
                {
                        
cacheConfig.appendChild(((XmlExternalizable)m_policyConfiguration).exportXml(doc));
                }
                return cacheConfig;
        }
                
        public void importXml(Element elt)
                throws Exception
        {
                if 
(elt.getOwnerDocument().getDocumentElement().getTagName().equals(jBossEjbJar.JBOSS_DOCUMENT))
                {
                        NodeList nl = elt.getChildNodes();
                        int l = nl.getLength();
                        for (int i = 0; i < l; ++i)
                        {
                                Node n = nl.item(i);
                                String name = n.getNodeName();
                                
                                if (name.equals("cache-policy"))
                                {
                                        setCachePolicy(n.hasChildNodes() ? 
XMLManager.getString(n) : "");
                                }
                                else if (name.equals("cache-policy-conf")) 
                                {
                                        
((XmlExternalizable)m_policyConfiguration).importXml((Element)n);
                                }
                        }
                }
        }
        
        
        // Y overrides ---------------------------------------------------
  
        // Package protected ---------------------------------------------
  
        // Protected -----------------------------------------------------
        protected String getConfigurationClassName(String c) 
        {
                String name = c.substring(c.lastIndexOf(".") + 1);
                return "org.jboss.ejb.deployment." + name + "Configuration";
        }
        
        // Private -------------------------------------------------------
  
        // Inner classes -------------------------------------------------
  }
  
  
  
  1.1                  
jboss/src/main/org/jboss/ejb/deployment/EntityInstanceCacheConfiguration.java
  
  Index: EntityInstanceCacheConfiguration.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.ejb.deployment;
  
  /**
   *
   *
   * @see
   * @author Simone Bordet ([EMAIL PROTECTED])
   * @version $Revision: 1.1 $
   */
  public class EntityInstanceCacheConfiguration 
        extends InstanceCacheSupportConfiguration 
  {
        // Constants -----------------------------------------------------
  
        // Attributes ----------------------------------------------------
  
        // Static --------------------------------------------------------
  
        // Constructors --------------------------------------------------
  
        // Public --------------------------------------------------------
  
        // Z implementation ----------------------------------------------
  
        // Y overrides ---------------------------------------------------
  
        // Package protected ---------------------------------------------
  
        // Protected -----------------------------------------------------
  
        // Private -------------------------------------------------------
  
        // Inner classes -------------------------------------------------
  }
  
  
  
  1.1                  
jboss/src/main/org/jboss/ejb/deployment/CachePolicySupportConfiguration.java
  
  Index: CachePolicySupportConfiguration.java
  ===================================================================
  /*
   * jBoss, the OpenSource EJB server
   *
   * Distributable under GPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.ejb.deployment;
  
  import java.awt.Component;
  import java.beans.beancontext.BeanContextSupport;
  import java.beans.beancontext.BeanContextChildComponentProxy;
  import com.dreambean.ejx.xml.XmlExternalizable;
  import com.dreambean.ejx.xml.XMLManager;
  import org.w3c.dom.Document;
  import org.w3c.dom.NodeList;
  import org.w3c.dom.Node;
  import org.w3c.dom.Element;
  
  /**
   * 
   *
   * @see
   * @author Simone Bordet ([EMAIL PROTECTED])
   * @version $Revision: 1.1 $
   */
  public class CachePolicySupportConfiguration
        extends BeanContextSupport
        implements BeanContextChildComponentProxy, XmlExternalizable
  {
        // Constants -----------------------------------------------------
  
        // Attributes ----------------------------------------------------
        private Component m_component;
  
        // Static --------------------------------------------------------
  
        // Constructors --------------------------------------------------
        public CachePolicySupportConfiguration() 
        {
        }
  
        // Public --------------------------------------------------------
  
        // BeanContextChildComponentProxy implementation -----------------
        public Component getComponent()
        {
                if (m_component == null) m_component = new 
com.dreambean.awt.GenericCustomizer(this);
                return m_component;
        }
        
        // XmlExternalizable implementation ------------------------------
        public Element exportXml(Document doc)
                throws Exception
        {
                Element policyConfig = doc.createElement("cache-policy-conf");
                return policyConfig;
        }
                
        public void importXml(Element elt)
                throws Exception
        {
        }
  
        // Package protected ---------------------------------------------
  
        // Protected -----------------------------------------------------
  
        // Private -------------------------------------------------------
  
        // Inner classes -------------------------------------------------
  }
  
  
  

Reply via email to