001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.cache.bean;
023:
024: import org.jboss.cache.CacheException;
025: import org.jboss.cache.TreeCache;
026: import org.jboss.cache.lock.IsolationLevel;
027:
028: import javax.ejb.CreateException;
029: import javax.ejb.SessionBean;
030: import javax.ejb.SessionContext;
031: import java.util.Map;
032: import java.util.Set;
033: import java.util.Vector;
034:
035: /**
036: * Proxy to the TreeCache MBean. Mainly used to be able to transport transactions from a test
037: * client to a TreeCache.
038: *
039: * @version $Revision: 57211 $
040: * @ejb.bean type="Stateful"
041: * name="test/TreeCacheTester"
042: * jndi-name="ejb/test/TreeCacheTester"
043: * view-type="remote"
044: * @ejb.transaction type="Supports"
045: */
046: public class TreeCacheTesterBean implements SessionBean {
047: TreeCache cache = null;
048:
049: /**
050: * @throws CreateException
051: * @ejb.create-method
052: */
053: public void ejbCreate() throws CreateException {
054: log("I'm being created");
055: }
056:
057: /**
058: * @param cluster_name
059: * @param props
060: * @param caching_mode
061: * @throws CreateException
062: * @ejb.create-method
063: */
064: public void ejbCreate(String cluster_name, String props,
065: int caching_mode) throws CreateException {
066: try {
067: // cache=new TreeCache(cluster_name, props, 10000);
068: cache = new TreeCache();
069: cache.setClusterName(cluster_name);
070: cache.setClusterProperties(props);
071: cache.setCacheMode(caching_mode);
072: cache
073: .setTransactionManagerLookupClass("org.jboss.cache.JBossTransactionManagerLookup");
074: cache.startService();
075: } catch (Exception e) {
076: throw new CreateException(e.toString());
077: }
078: }
079:
080: // /**
081: // *
082: // * @param name
083: // * @ejb.create-method
084: // */
085: // public void ejbCreate(String name) throws CreateException {
086: // MBeanServer server=null;
087: // ObjectName cache_service;
088: //
089: // try {
090: // this.name=name;
091: // cache_service=ObjectName.getInstance(name);
092: //
093: // // is this the right way to get hold of the JBoss MBeanServer ?
094: // List servers=MBeanServerFactory.findMBeanServer(null);
095: // if(servers == null || servers.size() == 0)
096: // throw new CreateException("TreeCacheTesterBean.ejbCreate(): no MBeanServers found");
097: // server=(MBeanServer)servers.get(0);
098: // cache=(TreeCacheMBean)MBeanProxy.create(TreeCacheMBean.class, cache_service, server);
099: // }
100: // catch(Exception ex) {
101: // throw new CreateException(ex.toString());
102: // }
103: // }
104:
105: public void ejbActivate() {
106: }
107:
108: public void ejbPassivate() {
109: }
110:
111: public void ejbRemove() {
112: log("I'm being removed");
113: if (cache != null) {
114: cache.stopService();
115: cache = null;
116: }
117: }
118:
119: public void setSessionContext(SessionContext ctx) {
120: }
121:
122: /**
123: * @return
124: * @ejb.interface-method
125: */
126: public Vector getMembers() {
127: return cache.getMembers();
128: }
129:
130: /**
131: * @param mode
132: * @ejb.interface-method
133: */
134: public void setCacheMode(int mode) throws Exception {
135: cache.setCacheMode(mode);
136: }
137:
138: /**
139: * @param level
140: * @ejb.interface-method
141: */
142: public void setIsolationLevel(IsolationLevel level) {
143: cache.setIsolationLevel(level);
144: }
145:
146: /**
147: * @param fqn
148: * @return
149: * @ejb.interface-method
150: */
151: public Set getKeys(String fqn) throws CacheException {
152: return cache.getKeys(fqn);
153: }
154:
155: /**
156: * @param fqn
157: * @param key
158: * @return
159: * @ejb.interface-method
160: */
161: public Object get(String fqn, String key) throws CacheException {
162: return cache.get(fqn, key);
163: }
164:
165: /**
166: * @param fqn
167: * @return
168: * @ejb.interface-method
169: */
170: public boolean exists(String fqn) {
171: return cache.exists(fqn);
172: }
173:
174: /**
175: * @param fqn
176: * @param data
177: * @throws Exception
178: * @ejb.interface-method
179: */
180: public void put(String fqn, Map data) throws Exception {
181: cache.put(fqn, data);
182: }
183:
184: /**
185: * @param fqn
186: * @param key
187: * @param value
188: * @return
189: * @throws Exception
190: * @ejb.interface-method
191: */
192: public Object put(String fqn, String key, Object value)
193: throws Exception {
194: return cache.put(fqn, key, value);
195: }
196:
197: /**
198: * @param fqn
199: * @throws Exception
200: * @ejb.interface-method
201: */
202: public void remove(String fqn) throws Exception {
203: cache.remove(fqn);
204: }
205:
206: /**
207: * @param fqn
208: * @param key
209: * @return
210: * @throws Exception
211: * @ejb.interface-method
212: */
213: public Object remove(String fqn, String key) throws Exception {
214: return cache.remove(fqn, key);
215: }
216:
217: /**
218: * @param fqn
219: * @ejb.interface-method
220: */
221: public void releaseAllLocks(String fqn) {
222: cache.releaseAllLocks(fqn);
223: }
224:
225: /**
226: * @param fqn
227: * @return
228: * @ejb.interface-method
229: */
230: public String print(String fqn) {
231: return cache.print(fqn);
232: }
233:
234: /**
235: * @param fqn
236: * @return
237: * @ejb.interface-method
238: */
239: public Set getChildrenNames(String fqn) throws CacheException {
240: return cache.getChildrenNames(fqn);
241: }
242:
243: /**
244: * @return
245: * @ejb.interface-method
246: */
247: public String printDetails() {
248: return cache.printDetails();
249: }
250:
251: /**
252: * @return
253: * @ejb.interface-method
254: */
255: public String printLockInfo() {
256: return cache.printLockInfo();
257: }
258:
259: /**
260: * @ejb.interface-method
261: * @param members
262: * @param method
263: * @param args
264: * @param synchronous
265: * @param exclude_self
266: * @param timeout
267: * @return
268: * @throws Exception
269: */
270: // public List callRemoteMethods(Vector members, Method method, Object[] args,
271: // boolean synchronous, boolean exclude_self,
272: // long timeout) throws Exception {
273: // return cache.callRemoteMethods(members, method, args, synchronous,
274: // exclude_self, timeout);
275: // }
276: /**
277: * @param members
278: * @param method_name
279: * @param types
280: * @param args
281: * @param synchronous
282: * @param exclude_self
283: * @param timeout
284: * @return
285: * @throws Exception
286: * @ejb.interface-method
287: */
288: // public List callRemoteMethods(Vector members, String method_name, Class[] types,
289: // Object[] args, boolean synchronous,
290: // boolean exclude_self, long timeout) throws Exception {
291: // return cache.callRemoteMethods(members, method_name, types, args,
292: // synchronous, exclude_self, timeout);
293: // }
294: private void log(String msg) {
295: System.out.println("-- [" + Thread.currentThread().getName()
296: + "]: " + msg);
297: }
298:
299: }
|