01: /*
02: * JBoss, Home of Professional Open Source.
03: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
04: * as indicated by the @author tags. See the copyright.txt file in the
05: * distribution for a full listing of individual contributors.
06: *
07: * This is free software; you can redistribute it and/or modify it
08: * under the terms of the GNU Lesser General Public License as
09: * 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 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: /**
33: * Comment
34: *
35: * @author <a href="mailto:bill@jboss.org">Bill Burke</a>
36: * @version $Revision: 57207 $
37: */
38: @Stateful
39: @CacheConfig(maxSize=1000,idleTimeoutSeconds=1)
40: @Local(SimpleStatefulLocal.class)
41: @Remote(SimpleStatefulRemote.class)
42: public class SimpleStatefulBean implements java.io.Serializable,
43: SimpleStatefulRemote, SimpleStatefulLocal {
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: InitialContext ctx = new InitialContext();
51: SimpleStatefulLocal local = (SimpleStatefulLocal) ctx
52: .lookup("SimpleStatefulBean/local");
53: long start = System.currentTimeMillis();
54: for (int i = 0; i < iterations; i++) {
55: local.getState();
56: }
57: long end = System.currentTimeMillis() - start;
58: System.out.println(iterations + " simple iterations took: "
59: + end);
60: return end;
61: }
62:
63: public void longRunning() throws Exception {
64: Thread.sleep(11000);
65: }
66:
67: public boolean getPostActivate() {
68: return postActivateCalled;
69: }
70:
71: public boolean getPrePassivate() {
72: return prePassivateCalled;
73: }
74:
75: public void setState(String state) {
76: this .state = state;
77: }
78:
79: public String getState() {
80: return this .state;
81: }
82:
83: public void reset() {
84: state = null;
85: postActivateCalled = false;
86: prePassivateCalled = false;
87: }
88:
89: @PostActivate
90: public void postActivate() {
91: postActivateCalled = true;
92: }
93:
94: @PrePassivate
95: public void prePassivate() {
96: prePassivateCalled = true;
97: }
98:
99: }
|