001: /*
002: * JOnAS: Java(TM) Open Application Server
003: * Copyright (C) 1999 Bull S.A.
004: * Contact: jonas-team@objectweb.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: EntityBean.java 8050 2006-02-23 16:07:37Z durieuxp $
023: * --------------------------------------------------------------------------
024: */
025:
026: package org.objectweb.jonas.container;
027:
028: import org.objectweb.jonas_ejb.container.EntityCounters;
029: import org.objectweb.jonas_ejb.container.JEntityFactory;
030: import org.objectweb.jonas_ejb.deployment.api.EntityDesc;
031:
032: /**
033: * This class implements the EntityBean type specified in JSR77
034: * @author Adriana Danes
035: *
036: */
037: public class EntityBean extends EJB {
038:
039: private String persistency;
040:
041: public EntityBean(String objectName,
042: JEntityFactory factoryToManage, String persistency) {
043: super (objectName, factoryToManage);
044: this .persistency = persistency;
045: }
046:
047: /**
048: * get persistency type
049: */
050: public String getPersistency() {
051: return persistency;
052: }
053:
054: /**
055: * get passivation time out
056: * @return passivation timeout in seconds
057: */
058: public int getPassivationTimeOut() {
059: return ((JEntityFactory) ejbToManage).getPassivationTimeout();
060: }
061:
062: /**
063: * set passivation time out
064: * @param timeOut passivation timeout in seconds
065: */
066: public void setPassivationTimeOut(int timeOut) {
067: ((JEntityFactory) ejbToManage).setPassivationTimeout(timeOut);
068: }
069:
070: /**
071: * get inactivity time out
072: * @return inactivity timeout in seconds
073: */
074: public int getInactivityTimeOut() {
075: return ((JEntityFactory) ejbToManage).getInactivityTimeout();
076: }
077:
078: /**
079: * get deadlock time out
080: * @return deadlock timeout in seconds
081: */
082: public int getDeadlockTimeOut() {
083: return ((JEntityFactory) ejbToManage).getDeadlockTimeout();
084: }
085:
086: /**
087: * get read time out
088: * @return read timeout in seconds
089: */
090: public int getReadTimeOut() {
091: return ((JEntityFactory) ejbToManage).getReadTimeout();
092: }
093:
094: /**
095: * @return true if bean is shared
096: */
097: public boolean getShared() {
098: return ((JEntityFactory) ejbToManage).isShared();
099: }
100:
101: /**
102: * @return true if bean has hard limit
103: */
104: public boolean getHardLimit() {
105: return ((JEntityFactory) ejbToManage).isHardLimit();
106: }
107:
108: /**
109: * @return min-pool-size value
110: */
111: public int getMinPoolSize() {
112: return ((JEntityFactory) ejbToManage).getMinPoolSize();
113: }
114:
115: /**
116: * @return max-cache-size value
117: */
118: public int getMaxCacheSize() {
119: return ((JEntityFactory) ejbToManage).getMaxCacheSize();
120: }
121:
122: /**
123: * @return pool-size value
124: */
125: public int getPoolSize() {
126: return ((JEntityFactory) ejbToManage).getPoolSize();
127: }
128:
129: /**
130: * @return current number of waiters for a bean instance
131: */
132: public int getCurrentWaiters() {
133: return ((JEntityFactory) ejbToManage).getCurrentWaiters();
134: }
135:
136: /**
137: * @return EJB Container lock policy
138: */
139: public String getLockPolicy() {
140: int lockPolicy = ((JEntityFactory) ejbToManage).getLockPolicy();
141: String sLockPolicy = null;
142: switch (lockPolicy) {
143: case EntityDesc.LOCK_CONTAINER_READ_UNCOMMITTED:
144: sLockPolicy = "container-read-uncommitted";
145: break;
146: case EntityDesc.LOCK_CONTAINER_SERIALIZED:
147: sLockPolicy = "container-serialized";
148: break;
149: case EntityDesc.LOCK_CONTAINER_SERIALIZED_TRANSACTED:
150: sLockPolicy = "container-serialized-transacted";
151: break;
152: case EntityDesc.LOCK_CONTAINER_READ_COMMITTED:
153: sLockPolicy = "container-read-committed";
154: break;
155: case EntityDesc.LOCK_DATABASE:
156: sLockPolicy = "database";
157: break;
158: case EntityDesc.LOCK_READ_ONLY:
159: sLockPolicy = "read-only";
160: break;
161: case EntityDesc.LOCK_CONTAINER_READ_WRITE:
162: sLockPolicy = "container-read-write";
163: break;
164: }
165: return sLockPolicy;
166: }
167:
168: public boolean getPrefetch() {
169: return ((JEntityFactory) ejbToManage).isPrefetch();
170: }
171:
172: /**
173: * @return Cache Size value
174: */
175: public int getCacheSize() {
176: return ((JEntityFactory) ejbToManage).getCacheSize();
177: }
178:
179: /**
180: * Instance Counters (inTx, outTx, idle, passive, removed)
181: * @return table of int values for Entity counters
182: */
183: public Integer[] getEntityCounters() {
184: EntityCounters ec = ((JEntityFactory) ejbToManage)
185: .getEntityCounters();
186: Integer[] result = new Integer[6];
187: result[0] = new Integer(ec.inTx);
188: result[1] = new Integer(ec.outTx);
189: result[2] = new Integer(ec.idle);
190: result[3] = new Integer(ec.passive);
191: result[4] = new Integer(ec.removed);
192: result[5] = new Integer(ec.pk);
193: return result;
194: }
195:
196: /**
197: * Synchronize bean state for all its instances outside transactions
198: */
199: public void synchronize() {
200: ((JEntityFactory) ejbToManage).syncDirty(true);
201: }
202:
203: /**
204: * Reduce number of instances in memory
205: */
206: public void reduceCache() {
207: ((JEntityFactory) ejbToManage).reduceCache();
208: }
209: }
|