KickJava   Java API By Example, From Geeks To Geeks.

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


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.simple.CacheConfig;
11 import org.jboss.logging.Logger;
12
13 import javax.ejb.*;
14 import javax.annotation.PostConstruct;
15 import javax.ejb.EJB JavaDoc;
16
17 /**
18  * Parent SFSB that contains nested SFSB
19  *
20  * @author Ben Wang
21  * @version $Revision: 45473 $
22  */

23 @Stateful(name="testParentStateful")
24 @CacheConfig(maxSize=1000, idleTimeoutSeconds=3) // this will get evicted the second time eviction thread wakes up
25
@Remote(ParentStatefulRemote.class)
26 public class ParentStatefulBean implements java.io.Serializable JavaDoc, ParentStatefulRemote
27 {
28    private Logger log = Logger.getLogger(ParentStatefulBean.class);
29    private int counter = 0;
30
31    @EJB JavaDoc
32    private NestedStateful nested;
33
34    public int increment()
35    {
36       counter = nested.increment();
37
38       log.debug("INCREMENT - counter: " + counter);
39       return counter;
40    }
41
42    public static int postActivateCalled = 0;
43    public static int prePassivateCalled = 0;
44
45    /**
46     * Sleep to test
47     * @throws Exception
48     */

49    public void longRunning() throws Exception JavaDoc
50    {
51       log.debug("+++ longRunning() enter ");
52       Thread.sleep(10000);
53       log.debug("+++ longRunning() leave ");
54    }
55
56    public int getPostActivate()
57    {
58       return ParentStatefulBean.postActivateCalled;
59    }
60
61    public int getPrePassivate()
62    {
63       return ParentStatefulBean.prePassivateCalled;
64    }
65
66    public void reset()
67    {
68       counter = 0;
69       ParentStatefulBean.postActivateCalled = 0;
70       ParentStatefulBean.prePassivateCalled = 0;
71    }
72
73    @PostActivate
74    public void postActivate()
75    {
76       ++ParentStatefulBean.postActivateCalled;
77       log.debug("Activate with counter: " + counter);
78    }
79
80    @PrePassivate
81    public void prePassivate()
82    {
83       ++ParentStatefulBean.prePassivateCalled;
84       log.debug("Passivate with counter: " + counter);
85    }
86
87    @Remove
88    public void remove()
89    {
90    }
91
92    @PostConstruct
93    public void ejbCreate()
94    {
95    }
96
97    // Remote Interface implementation ----------------------------------------------
98

99 }
100
Popular Tags