1 22 package org.jboss.ejb3.test.cache; 23 24 import javax.ejb.Local ; 25 import javax.ejb.PostActivate ; 26 import javax.ejb.PrePassivate ; 27 import javax.ejb.Remote ; 28 import javax.ejb.Stateful ; 29 import javax.ejb.Remove ; 30 import javax.naming.InitialContext ; 31 import org.jboss.annotation.ejb.cache.Cache; 32 import org.jboss.annotation.ejb.cache.tree.CacheConfig; 33 34 40 @Stateful 41 @Cache(org.jboss.ejb3.cache.tree.StatefulTreeCache.class) 42 @CacheConfig(name = "jboss.cache:service=EJB3SFSBClusteredCache", maxSize = 1000, idleTimeoutSeconds = 1) 43 @Local (StatefulLocal.class) 44 @Remote (StatefulRemote.class) 45 public class StatefulBean implements StatefulRemote, java.io.Serializable , StatefulLocal 46 { 47 public static boolean postActivateCalled = false; 48 public static boolean prePassivateCalled = false; 49 50 private String state; 51 52 public long bench(int iterations) throws Exception 53 { 54 InitialContext ctx = new InitialContext (); 55 StatefulLocal local = (StatefulLocal) ctx.lookup("StatefulBean/local"); 56 long start = System.currentTimeMillis(); 57 for (int i = 0; i < iterations; i++) 58 { 59 local.getState(); 60 } 61 long end = System.currentTimeMillis() - start; 62 System.out.println(iterations + " stateful iterations took: " + end); 63 return end; 64 } 65 66 public void longRunning() throws Exception 67 { 68 Thread.sleep(11000); 69 } 70 71 @Remove 72 public void done() { 73 } 74 75 public boolean getPostActivate() 76 { 77 return postActivateCalled; 78 } 79 80 public boolean getPrePassivate() 81 { 82 return prePassivateCalled; 83 } 84 85 public void setState(String state) 86 { 87 this.state = state; 88 } 89 90 public String getState() 91 { 92 return this.state; 93 } 94 95 public void reset() 96 { 97 state = null; 98 postActivateCalled = false; 99 prePassivateCalled = false; 100 } 101 102 @PostActivate 103 public void postActivate() 104 { 105 postActivateCalled = true; 106 } 107 108 @PrePassivate 109 public void prePassivate() 110 { 111 prePassivateCalled = true; 112 } 113 114 115 } 116 | Popular Tags |