KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > cache > Tester


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.test.cache;
23
24 import java.io.File JavaDoc;
25
26 import javax.management.ObjectName JavaDoc;
27 import javax.naming.InitialContext JavaDoc;
28
29 import org.jboss.cache.Cache;
30 import org.jboss.cache.Fqn;
31 import org.jboss.cache.jmx.CacheJmxWrapperMBean;
32 import org.jboss.cache.loader.FileCacheLoader;
33 import org.jboss.mx.util.MBeanProxy;
34 import org.jboss.system.ServiceMBeanSupport;
35 import org.jboss.system.server.ServerConfig;
36
37 /**
38  * Comment
39  *
40  * @author <a HREF="mailto:bill@jboss.org">Bill Burke</a>
41  * @version $Revision: 58553 $
42  */

43 public class Tester extends ServiceMBeanSupport implements TesterMBean
44 {
45    public void test() throws Exception JavaDoc
46    {
47       ObjectName JavaDoc cacheON = new ObjectName JavaDoc("jboss.cache:service=EJB3TreeCache");
48       CacheJmxWrapperMBean mbean = (CacheJmxWrapperMBean) MBeanProxy.get(CacheJmxWrapperMBean.class, cacheON, server);
49       Cache cache = mbean.getCache();
50 // PassivationEvictionPolicy policy = (PassivationEvictionPolicy) cache.getEvictionPolicy();
51
// policy.createRegion("/mySFSB", 100, 1L);
52

53       Fqn mysfbf1234 = Fqn.fromString("/mySFSB/1234");
54       cache.put(mysfbf1234, "hello", "world");
55       System.out.println("After PUT");
56       Thread.sleep(5000);
57
58       System.out.println("WAKE UP!");
59       File JavaDoc fp = new File JavaDoc(System.getProperty(ServerConfig.SERVER_TEMP_DIR) + "/stateful/mySFSB." + FileCacheLoader.DIR_SUFFIX + "/1234." + FileCacheLoader.DIR_SUFFIX);
60       System.out.println("exists in DB: " + fp.exists());
61       if (!fp.exists()) throw new RuntimeException JavaDoc("No passivation happened.");
62       System.out.println(cache.get(mysfbf1234, "hello"));
63       System.out.println("exists in DB: " + fp.exists());
64       if (fp.exists()) throw new RuntimeException JavaDoc("Should have been removed on activation.");
65       if (cache.hasChild(mysfbf1234))
66       {
67          cache.remove("/mySFSB/1234");
68 // synchronized (policy)
69
// {
70
// policy.removeRegion("/mySFSB");
71
// }
72
cache.remove("/mySFSB");
73       }
74    }
75
76    public void testSimpleRemote() throws Exception JavaDoc
77    {
78       SimpleStatefulRemote remote = (SimpleStatefulRemote) new InitialContext JavaDoc().lookup("SimpleStatefulBean/remote");
79       remote.reset();
80       remote.setState("hello");
81       remote.longRunning();
82       if (!"hello".equals(remote.getState())) throw new RuntimeException JavaDoc("failed state");
83       if (!remote.getPostActivate()) throw new RuntimeException JavaDoc("failed to postActivate");
84       if (!remote.getPrePassivate()) throw new RuntimeException JavaDoc("failed to prePassivate");
85
86    }
87
88    public void testSimpleLocal() throws Exception JavaDoc
89    {
90       SimpleStatefulLocal local = (SimpleStatefulLocal) new InitialContext JavaDoc().lookup("SimpleStatefulBean/local");
91       local.reset();
92       local.setState("hello");
93       local.longRunning();
94       if (!"hello".equals(local.getState())) throw new RuntimeException JavaDoc("failed state");
95       if (!local.getPostActivate()) throw new RuntimeException JavaDoc("failed to postActivate");
96       if (!local.getPrePassivate()) throw new RuntimeException JavaDoc("failed to prePassivate");
97
98    }
99 }
100
Popular Tags