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.naming.InitialContext ; 30 import org.jboss.annotation.ejb.cache.simple.CacheConfig; 31 32 38 @Stateful 39 @CacheConfig(maxSize = 1000, idleTimeoutSeconds = 1) 40 @Local (SimpleStatefulLocal.class) 41 @Remote (SimpleStatefulRemote.class) 42 public class SimpleStatefulBean implements java.io.Serializable , SimpleStatefulRemote, SimpleStatefulLocal 43 { 44 public static boolean postActivateCalled = false; 45 public static boolean prePassivateCalled = false; 46 47 private String state; 48 49 public long bench(int iterations) throws Exception 50 { 51 InitialContext ctx = new InitialContext (); 52 SimpleStatefulLocal local = (SimpleStatefulLocal) ctx.lookup("SimpleStatefulBean/local"); 53 long start = System.currentTimeMillis(); 54 for (int i = 0; i < iterations; i++) 55 { 56 local.getState(); 57 } 58 long end = System.currentTimeMillis() - start; 59 System.out.println(iterations + " simple iterations took: " + end); 60 return end; 61 } 62 63 public void longRunning() throws Exception 64 { 65 Thread.sleep(11000); 66 } 67 68 public boolean getPostActivate() 69 { 70 return postActivateCalled; 71 } 72 73 public boolean getPrePassivate() 74 { 75 return prePassivateCalled; 76 } 77 78 public void setState(String state) 79 { 80 this.state = state; 81 } 82 83 public String getState() 84 { 85 return this.state; 86 } 87 88 public void reset() 89 { 90 state = null; 91 postActivateCalled = false; 92 prePassivateCalled = false; 93 } 94 95 @PostActivate 96 public void postActivate() 97 { 98 postActivateCalled = true; 99 } 100 101 @PrePassivate 102 public void prePassivate() 103 { 104 prePassivateCalled = true; 105 } 106 107 108 } 109 | Popular Tags |