KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > test > stateful > nested > NestedStatefulBean


1 /*
2  * JBoss, Home of Professional Open Source
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.ejb3.test.stateful.nested;
9
10 import org.jboss.annotation.ejb.cache.tree.CacheConfig;
11 import org.jboss.logging.Logger;
12
13 import javax.ejb.*;
14
15 /**
16  * Nested SFSB
17  *
18  * @author Ben Wang
19  * @version $Revision: 45372 $
20  */

21 @Stateful(name="testNestedStateful")
22 @CacheConfig(maxSize=1000, idleTimeoutSeconds=3) // this will get evicted the second time eviction thread wakes up
23
public class NestedStatefulBean implements java.io.Serializable JavaDoc, NestedStateful
24 {
25    private Logger log = Logger.getLogger(NestedStatefulBean.class);
26    private int counter = 0;
27
28    public int increment()
29    {
30       log.debug("INCREMENT - counter: " + (counter++));
31       return counter;
32    }
33
34    public static int postActivateCalled = 0;
35    public static int prePassivateCalled = 0;
36
37    public int getPostActivate()
38    {
39       return postActivateCalled;
40    }
41
42    public int getPrePassivate()
43    {
44       return prePassivateCalled;
45    }
46
47    public void reset()
48    {
49       counter = 0;
50       NestedStatefulBean.postActivateCalled = 0;
51       NestedStatefulBean.prePassivateCalled = 0;
52    }
53
54    @PostActivate
55    public void postActivate()
56    {
57       ++NestedStatefulBean.postActivateCalled;
58       log.debug("Activate with counter: " + counter);
59    }
60
61    @PrePassivate
62    public void prePassivate()
63    {
64       ++NestedStatefulBean.prePassivateCalled;
65       log.debug("Passivate with counter: " + counter);
66    }
67
68 }
69
Popular Tags