KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > ejb > base > container > util > CacheProperties


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.ejb.base.container.util;
25
26 import java.util.logging.Logger JavaDoc;
27 import java.util.logging.Level JavaDoc;
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 /**
43  * A util class to read the bean cache related entries from
44  * domain.xml and sun-ejb-jar.xml
45  *
46  * @author Mahesh Kannan
47  */

48 public class CacheProperties {
49
50     protected static Logger JavaDoc _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 JavaDoc 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             //container.setMonitorOn(ejbContainer.isMonitoringEnabled());
78
} 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 JavaDoc getVictimSelectionPolicy() {
100     return this.victimSelectionPolicy;
101     }
102         
103     public String JavaDoc toString() {
104     StringBuffer JavaDoc sbuf = new StringBuffer JavaDoc();
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 JavaDoc(ejbContainer.getCacheResizeQuantity()).intValue();
119
120     maxCacheSize =
121         new Integer JavaDoc(ejbContainer.getMaxCacheSize()).intValue();
122
123     cacheIdleTimeoutInSeconds = new Integer JavaDoc(
124         ejbContainer.getCacheIdleTimeoutInSeconds()).intValue();
125
126     removalTimeoutInSeconds =
127         new Integer JavaDoc(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