1 23 24 package com.sun.ejb.base.container.util; 25 26 import java.util.logging.Logger ; 27 import java.util.logging.Level ; 28 29 import com.sun.enterprise.config.ConfigException; 30 import com.sun.enterprise.config.serverbeans.*; 31 32 import com.sun.enterprise.deployment.EjbDescriptor; 33 import com.sun.enterprise.deployment.runtime.IASEjbExtraDescriptors; 34 import com.sun.enterprise.deployment.runtime.BeanCacheDescriptor; 35 36 import com.sun.enterprise.server.ServerContext; 37 import com.sun.enterprise.server.ApplicationServer; 38 import com.sun.enterprise.util.Utility; 39 40 import com.sun.logging.LogDomains; 41 42 48 public class CacheProperties { 49 50 protected static Logger _logger = 51 LogDomains.getLogger(LogDomains.EJB_LOGGER); 52 53 private int maxCacheSize ; 54 private int numberOfVictimsToSelect ; 55 private int cacheIdleTimeoutInSeconds ; 56 private int removalTimeoutInSeconds; 57 58 private String victimSelectionPolicy; 59 60 public CacheProperties(EjbDescriptor desc) { 61 62 try { 63 BeanCacheDescriptor beanCacheDes = null; 64 Config cfg = null; 65 66 IASEjbExtraDescriptors iased = desc.getIASEjbExtraDescriptors(); 67 if( iased != null) { 68 beanCacheDes = iased.getBeanCache(); 69 } 70 71 EjbContainer ejbContainer = null; 72 ServerContext sc = ApplicationServer.getServerContext(); 73 cfg = ServerBeansFactory.getConfigBean(sc.getConfigContext()); 74 ejbContainer = cfg.getEjbContainer(); 75 76 loadProperties(ejbContainer, beanCacheDes); 77 } catch (ConfigException ex) { 79 _logger.log(Level.SEVERE, "", ex); 80 } 81 } 82 83 public int getMaxCacheSize() { 84 return this.maxCacheSize; 85 } 86 87 public int getNumberOfVictimsToSelect() { 88 return this.numberOfVictimsToSelect; 89 } 90 91 public int getCacheIdleTimeoutInSeconds() { 92 return this.cacheIdleTimeoutInSeconds; 93 } 94 95 public int getRemovalTimeoutInSeconds() { 96 return this.removalTimeoutInSeconds; 97 } 98 99 public String getVictimSelectionPolicy() { 100 return this.victimSelectionPolicy; 101 } 102 103 public String toString() { 104 StringBuffer sbuf = new StringBuffer (); 105 sbuf.append("maxSize: ").append(maxCacheSize) 106 .append("; victims: ").append(numberOfVictimsToSelect) 107 .append("; idleTimeout: ").append(cacheIdleTimeoutInSeconds) 108 .append("; removalTimeout: ").append(removalTimeoutInSeconds) 109 .append("; policy: ").append(victimSelectionPolicy); 110 111 return sbuf.toString(); 112 } 113 114 private void loadProperties(EjbContainer ejbContainer, 115 BeanCacheDescriptor beanCacheDes) 116 { 117 numberOfVictimsToSelect = 118 new Integer (ejbContainer.getCacheResizeQuantity()).intValue(); 119 120 maxCacheSize = 121 new Integer (ejbContainer.getMaxCacheSize()).intValue(); 122 123 cacheIdleTimeoutInSeconds = new Integer ( 124 ejbContainer.getCacheIdleTimeoutInSeconds()).intValue(); 125 126 removalTimeoutInSeconds = 127 new Integer (ejbContainer.getRemovalTimeoutInSeconds()).intValue(); 128 129 victimSelectionPolicy = ejbContainer.getVictimSelectionPolicy(); 130 131 if (beanCacheDes != null) { 132 int temp = 0; 133 if ((temp = beanCacheDes.getResizeQuantity()) != -1) { 134 this.numberOfVictimsToSelect = temp; 135 } 136 if ((temp = beanCacheDes.getMaxCacheSize()) != -1) { 137 this.maxCacheSize = temp; 138 } 139 if ((temp = beanCacheDes.getCacheIdleTimeoutInSeconds()) != -1){ 140 this.cacheIdleTimeoutInSeconds = temp; 141 } 142 if ((temp = beanCacheDes.getRemovalTimeoutInSeconds()) != -1) { 143 this.removalTimeoutInSeconds = temp; 144 } 145 if (( beanCacheDes.getVictimSelectionPolicy()) != null) { 146 this.victimSelectionPolicy = 147 beanCacheDes.getVictimSelectionPolicy(); 148 } 149 } 150 } 151 152 } 153 154 | Popular Tags |